Skip to content

Commit 0ea93bb

Browse files
committed
chore: pre-generate bindgen output, remove libclang build requirement
1 parent efb3cbe commit 0ea93bb

5 files changed

Lines changed: 900 additions & 8 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

litehtml-sys/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "litehtml-sys"
3-
version = "0.2.3"
3+
version = "0.2.4"
44
edition = "2021"
55
license = "MIT AND BSD-3-Clause AND Apache-2.0"
66
authors = ["Franz Geffke <mail@gofranz.com>"]
@@ -14,9 +14,10 @@ exclude = ["tests/"]
1414
[features]
1515
default = ["vendored"]
1616
vendored = []
17+
buildtime-bindgen = ["bindgen"]
1718

1819
[build-dependencies]
1920
cc = "1"
20-
bindgen = "0.71"
21+
bindgen = { version = "0.71", optional = true }
2122

2223
[dependencies]

litehtml-sys/build.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
build_system(&out_dir, &csrc_dir);
1515
}
1616

17-
generate_bindings(&csrc_dir, &out_dir, vendored, &manifest_dir);
17+
write_bindings(&csrc_dir, &out_dir, vendored, &manifest_dir);
1818

1919
println!("cargo:rerun-if-changed={}", csrc_dir.display());
2020
}
@@ -248,7 +248,10 @@ fn find_library(name: &str) -> Option<PathBuf> {
248248
None
249249
}
250250

251-
fn generate_bindings(csrc_dir: &Path, out_dir: &Path, vendored: bool, manifest_dir: &Path) {
251+
#[cfg(feature = "buildtime-bindgen")]
252+
fn write_bindings(csrc_dir: &Path, out_dir: &Path, vendored: bool, manifest_dir: &Path) {
253+
let out_bindings = out_dir.join("bindings.rs");
254+
252255
let mut builder = bindgen::Builder::default()
253256
.header(csrc_dir.join("litehtml_c.h").to_str().unwrap())
254257
.allowlist_function("lh_.*")
@@ -268,6 +271,14 @@ fn generate_bindings(csrc_dir: &Path, out_dir: &Path, vendored: bool, manifest_d
268271
let bindings = builder.generate().expect("failed to generate bindings");
269272

270273
bindings
271-
.write_to_file(out_dir.join("bindings.rs"))
274+
.write_to_file(out_bindings)
272275
.expect("failed to write bindings");
273276
}
277+
278+
#[cfg(not(feature = "buildtime-bindgen"))]
279+
fn write_bindings(_csrc_dir: &Path, out_dir: &Path, _vendored: bool, manifest_dir: &Path) {
280+
let pregenerated = manifest_dir.join("src/bindings.rs");
281+
let out_bindings = out_dir.join("bindings.rs");
282+
std::fs::copy(&pregenerated, &out_bindings).expect("failed to copy pre-generated bindings");
283+
println!("cargo:rerun-if-changed={}", pregenerated.display());
284+
}

0 commit comments

Comments
 (0)