Skip to content

Commit 278c865

Browse files
authored
Make harfbuzz and harfbuzz-sys no_std (#232)
* Add std feature to harfbuzz * Mark harfbuzz-sys as no_std.
1 parent 1b25f08 commit 278c865

File tree

7 files changed

+38
-18
lines changed

7 files changed

+38
-18
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ jobs:
3434
env:
3535
RUST_BACKTRACE: 1
3636

37+
- name: Cargo check no-default-features
38+
run: cargo check --no-default-features
39+
env:
40+
RUST_BACKTRACE: 1
41+
3742
linux-ci-static:
3843
name: stable, Linux, static linking, no pkg-config
3944
runs-on: ubuntu-latest

harfbuzz-sys/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
//!
2121
//! - `bundled` - Use the bundled copy of the harfbuzz library rather than one installed on the system.
2222
23+
#![no_std]
24+
2325
#[cfg(all(target_vendor = "apple", feature = "coretext"))]
2426
pub mod coretext;
2527

harfbuzz/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ version = "0.5.0"
1919
default-features = false
2020

2121
[features]
22-
default = ["coretext", "directwrite", "freetype"]
22+
default = ["coretext", "directwrite", "freetype", "std"]
2323
bundled = ["harfbuzz-sys/bundled"]
2424
coretext = ["harfbuzz-sys/coretext"]
2525
directwrite = ["harfbuzz-sys/directwrite"]
2626
freetype = ["harfbuzz-sys/freetype"]
27+
std = []

harfbuzz/src/blob.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
// except according to those terms.
99

1010
use crate::sys;
11-
use std::marker::PhantomData;
12-
use std::os::raw::{c_char, c_uint, c_void};
13-
use std::sync::Arc;
14-
use std::{mem, ops, ptr, slice};
11+
use core::ffi::{c_char, c_uint};
12+
use core::marker::PhantomData;
13+
use core::{mem, ops, ptr, slice};
14+
15+
#[cfg(feature = "std")]
16+
use std::{ffi::c_void, sync::Arc, vec::Vec};
1517

1618
/// Blobs wrap a chunk of binary data to handle lifecycle management of data
1719
/// while it is passed between client and HarfBuzz.
@@ -55,6 +57,8 @@ impl<'a> Blob<'a> {
5557
/// data may be shared by Rust code and the blob. The `Vec` is freed
5658
/// when all references are dropped.
5759
///
60+
/// ✨ *Enabled with the `std` Cargo feature.*
61+
///
5862
/// ```
5963
/// # use std::sync::Arc;
6064
/// # use harfbuzz::Blob;
@@ -63,6 +67,7 @@ impl<'a> Blob<'a> {
6367
/// assert_eq!(blob.len(), 256);
6468
/// assert!(!blob.is_empty());
6569
/// ```
70+
#[cfg(feature = "std")]
6671
pub fn new_from_arc_vec(data: Arc<Vec<u8>>) -> Blob<'static> {
6772
let len = data.len();
6873
assert!(len <= c_uint::max_value() as usize);

harfbuzz/src/buffer.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl Buffer {
9999
/// Gives up ownership and returns a raw pointer to the buffer.
100100
pub fn into_raw(self) -> *mut sys::hb_buffer_t {
101101
let raw = self.raw;
102-
std::mem::forget(self);
102+
core::mem::forget(self);
103103
raw
104104
}
105105

@@ -122,10 +122,10 @@ impl Buffer {
122122
unsafe {
123123
sys::hb_buffer_add_utf8(
124124
self.raw,
125-
text.as_ptr() as *const std::os::raw::c_char,
126-
text.len() as std::os::raw::c_int,
125+
text.as_ptr() as *const core::ffi::c_char,
126+
text.len() as core::ffi::c_int,
127127
0,
128-
text.len() as std::os::raw::c_int,
128+
text.len() as core::ffi::c_int,
129129
)
130130
};
131131
}
@@ -144,8 +144,8 @@ impl Buffer {
144144
sys::hb_buffer_append(
145145
self.raw,
146146
other.raw,
147-
start as std::os::raw::c_uint,
148-
end as std::os::raw::c_uint,
147+
start as core::ffi::c_uint,
148+
end as core::ffi::c_uint,
149149
)
150150
};
151151
}
@@ -297,8 +297,8 @@ impl Buffer {
297297
}
298298
}
299299

300-
impl std::fmt::Debug for Buffer {
301-
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
300+
impl core::fmt::Debug for Buffer {
301+
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
302302
fmt.debug_struct("Buffer")
303303
.field("direction", &self.get_direction())
304304
.field("script", &self.get_script())

harfbuzz/src/language.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ impl Language {
5353
Language {
5454
raw: unsafe {
5555
sys::hb_language_from_string(
56-
lang.as_ptr() as *const std::os::raw::c_char,
57-
lang.len() as std::os::raw::c_int,
56+
lang.as_ptr() as *const core::ffi::c_char,
57+
lang.len() as core::ffi::c_int,
5858
)
5959
},
6060
}
@@ -68,7 +68,7 @@ impl Language {
6868
/// assert_eq!(lang.to_string(), "en-us");
6969
/// ```
7070
pub fn to_string(&self) -> &str {
71-
unsafe { std::ffi::CStr::from_ptr(sys::hb_language_to_string(self.raw)) }
71+
unsafe { core::ffi::CStr::from_ptr(sys::hb_language_to_string(self.raw)) }
7272
.to_str()
7373
.unwrap()
7474
}
@@ -117,8 +117,8 @@ impl Language {
117117
}
118118
}
119119

120-
impl std::fmt::Debug for Language {
121-
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
120+
impl core::fmt::Debug for Language {
121+
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
122122
fmt.write_str(self.to_string())
123123
}
124124
}

harfbuzz/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
//! - `freetype` - Enables bindings to the FreeType font engine. (Enabled by default.)
1616
//! - `coretext` - Enables bindings to the CoreText font engine. (Apple platforms only) (Enabled by default.)
1717
//! - `directwrite` - Enables bindings to the DirectWrite font engine. (Windows only) (Enabled by default.)
18+
//! - `std` - Enable certain functions that require the standard library. (Enabled by default.)
1819
//!
1920
//! - `bundled` - Use the bundled copy of the harfbuzz library rather than one installed on the system.
2021
22+
#![no_std]
2123
#![warn(missing_docs)]
2224
#![deny(
2325
trivial_numeric_casts,
@@ -26,6 +28,11 @@
2628
unused_qualifications
2729
)]
2830

31+
extern crate alloc;
32+
33+
#[cfg(feature = "std")]
34+
extern crate std;
35+
2936
pub use harfbuzz_sys as sys;
3037

3138
mod buffer;

0 commit comments

Comments
 (0)