Skip to content

Commit 9699969

Browse files
Use bundled feature to use our own copy of harfbuzz. (#223)
This looks for one installed on the system by default. It can be forced to look on the system even if `bundled` is set by defining `HARFBUZZ_SYS_USE_PKG_CONFIG` in the environment to `"1"`. If `bundled` is set, then it will use the sources that we vendor. In general, `bundled` should be set as needed by applications rather than by libraries using `harfbuzz` or `harfbuzz-sys`. This allows for control by the application's build since once the feature is enabled by a crate, it can't readily be disabled. The name for the `bundled` feature comes from the rusqlite bindings for `libsqlite-sys`.
1 parent 0fe2766 commit 9699969

File tree

8 files changed

+32
-30
lines changed

8 files changed

+32
-30
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ jobs:
4848
linux-ci-static:
4949
name: stable, Linux, static linking, no pkg-config
5050
runs-on: ubuntu-latest
51-
env:
52-
HARFBUZZ_SYS_NO_PKG_CONFIG: 1
5351
steps:
5452
- uses: actions/checkout@v3
5553

@@ -60,13 +58,13 @@ jobs:
6058
# do this where the embedded harfbuzz is statically linked, but we don't
6159
# need to do it for every environment.
6260
- name: Cargo package
63-
run: cargo package --manifest-path=harfbuzz-sys/Cargo.toml
61+
run: cargo package --manifest-path=harfbuzz-sys/Cargo.toml --features bundled
6462

6563
- name: Cargo build
66-
run: cargo build --workspace
64+
run: cargo build --workspace --features bundled
6765

6866
- name: Cargo test
69-
run: cargo test --workspace
67+
run: cargo test --workspace --features bundled
7068
env:
7169
RUST_BACKTRACE: 1
7270

@@ -100,8 +98,6 @@ jobs:
10098
mac-ci-static:
10199
name: stable, macOS, static library
102100
runs-on: macos-latest
103-
env:
104-
HARFBUZZ_SYS_NO_PKG_CONFIG: 1
105101

106102
steps:
107103
- uses: actions/checkout@v3
@@ -115,10 +111,10 @@ jobs:
115111
run: cargo fmt --all -- --check
116112

117113
- name: Cargo build
118-
run: cargo build --workspace
114+
run: cargo build --workspace --features bundled
119115

120116
- name: Cargo test
121-
run: cargo test --workspace
117+
run: cargo test --workspace --features bundled
122118
env:
123119
RUST_BACKTRACE: 1
124120

@@ -133,10 +129,10 @@ jobs:
133129
uses: dtolnay/rust-toolchain@stable
134130

135131
- name: Cargo build
136-
run: cargo build --workspace
132+
run: cargo build --workspace --features bundled
137133

138134
- name: Cargo test
139-
run: cargo test --workspace
135+
run: cargo test --workspace --features bundled
140136
env:
141137
RUST_BACKTRACE: 1
142138

@@ -157,7 +153,7 @@ jobs:
157153
target: wasm32-unknown-emscripten
158154

159155
- name: Cargo build
160-
run: cargo build --target wasm32-unknown-emscripten --workspace --no-default-features --features build-native-harfbuzz
156+
run: cargo build --target wasm32-unknown-emscripten --workspace --no-default-features --features bundled
161157

162158
ios-ci-static:
163159
name: stable, iOS, static library
@@ -172,7 +168,7 @@ jobs:
172168
target: aarch64-apple-ios
173169

174170
- name: Cargo build
175-
run: cargo build --target aarch64-apple-ios --workspace --no-default-features --features "build-native-harfbuzz, coretext"
171+
run: cargo build --target aarch64-apple-ios --workspace --no-default-features --features "bundled, coretext"
176172

177173
build_result:
178174
name: Result

harfbuzz-sys/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ links = "harfbuzz"
2424
build = "build.rs"
2525

2626
[build-dependencies]
27-
pkg-config = { version = "0.3", optional = true }
28-
cc = { version = "1", optional = true }
27+
pkg-config = { version = "0.3" }
28+
cc = { version = "1" }
2929

3030
[target.'cfg(target_vendor = "apple")'.dependencies]
3131
core-graphics = { version = "0.22", optional = true }
@@ -42,7 +42,7 @@ version = "0.7"
4242
optional = true
4343

4444
[features]
45-
default = ["build-native-harfbuzz", "coretext", "directwrite", "freetype"]
45+
default = ["coretext", "directwrite", "freetype"]
46+
bundled = []
4647
coretext = ["core-graphics", "core-text", "foreign-types"]
4748
directwrite = ["winapi"]
48-
build-native-harfbuzz = ["cc", "pkg-config"]

harfbuzz-sys/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ This crate provides low-level bindings to the C API.
2020
- `coretext` - Enables bindings to the CoreText font engine. (Apple platforms only) (Enabled by default.)
2121
- `directwrite` - Enables bindings to the DirectWrite font engine. (Windows only) (Enabled by default.)
2222

23+
- `bundled` - Use the bundled copy of the harfbuzz library rather than one installed on the system.
24+
2325
## License
2426

2527
Licensed under the MIT license ([LICENSE](LICENSE) or <https://opensource.org/licenses/MIT>).

harfbuzz-sys/build.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
#[cfg(feature = "build-native-harfbuzz")]
2-
fn main() {
1+
fn build_harfbuzz() {
32
use std::env;
43
use std::path::PathBuf;
54

65
let target = env::var("TARGET").unwrap();
76

8-
println!("cargo:rerun-if-env-changed=HARFBUZZ_SYS_NO_PKG_CONFIG");
9-
if (target.contains("wasm32") || env::var_os("HARFBUZZ_SYS_NO_PKG_CONFIG").is_none())
10-
&& pkg_config::probe_library("harfbuzz").is_ok()
11-
{
12-
return;
13-
}
14-
157
let mut cfg = cc::Build::new();
168
cfg.cpp(true)
179
.flag_if_supported("-std=c++11") // for unix
@@ -44,5 +36,11 @@ fn main() {
4436
);
4537
}
4638

47-
#[cfg(not(feature = "build-native-harfbuzz"))]
48-
fn main() {}
39+
fn main() {
40+
if cfg!(feature = "bundled") {
41+
build_harfbuzz();
42+
} else {
43+
// Use the pre-installed harfbuzz.
44+
pkg_config::probe_library("harfbuzz").unwrap();
45+
}
46+
}

harfbuzz-sys/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
//! - `freetype` - Enables bindings to the FreeType font engine. (Enabled by default.)
99
//! - `coretext` - Enables bindings to the CoreText font engine. (Apple platforms only) (Enabled by default.)
1010
//! - `directwrite` - Enables bindings to the DirectWrite font engine. (Windows only) (Enabled by default.)
11+
//!
12+
//! - `bundled` - Use the bundled copy of the harfbuzz library rather than one installed on the system.
1113
1214
#[cfg(all(target_vendor = "apple", feature = "coretext"))]
1315
pub mod coretext;

harfbuzz/Cargo.toml

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

2121
[features]
22-
default = ["build-native-harfbuzz", "coretext", "directwrite", "freetype"]
23-
build-native-harfbuzz = ["harfbuzz-sys/build-native-harfbuzz"]
22+
default = ["coretext", "directwrite", "freetype"]
23+
bundled = ["harfbuzz-sys/bundled"]
2424
coretext = ["harfbuzz-sys/coretext"]
2525
directwrite = ["harfbuzz-sys/directwrite"]
2626
freetype = ["harfbuzz-sys/freetype"]

harfbuzz/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ This crate provides a higher level API (than the
2121
- `coretext` - Enables bindings to the CoreText font engine. (Apple platforms only) (Enabled by default.)
2222
- `directwrite` - Enables bindings to the DirectWrite font engine. (Windows only) (Enabled by default.)
2323

24+
- `bundled` - Use the bundled copy of the harfbuzz library rather than one installed on the system.
25+
2426
## License
2527

2628
Licensed under either of

harfbuzz/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
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+
//!
19+
//! - `bundled` - Use the bundled copy of the harfbuzz library rather than one installed on the system.
1820
1921
#![warn(missing_docs)]
2022
#![deny(

0 commit comments

Comments
 (0)