Skip to content

Commit 250ea7d

Browse files
committed
fix: ci
1 parent 3cb50a4 commit 250ea7d

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

libxml-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ zlib = []
1919
[build-dependencies]
2020
cmake = "0.1.57"
2121
bindgen = "0.72.1"
22-
22+
regex = "1.12.3"
2323

2424
[package.metadata.cross.target.x86_64-pc-windows-gnu]
2525
pre-build = [

libxml-sys/build.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,30 @@ fn main() {
1414

1515
println!("cargo::rerun-if-changed=libxml2");
1616

17-
let libs = std::process::Command::new(format!("{}/bin/xml2-config", path.display(),))
17+
let host = env::var("HOST").unwrap();
18+
let reg = regex::Regex::new("-(.)/(.)/").expect("reg");
19+
20+
let mut libs = std::process::Command::new("sh")
21+
.arg(path.join("bin/xml2-config"))
1822
.arg("--libs")
1923
.output()
20-
.expect("");
21-
let libs = String::from_utf8_lossy(&libs.stdout);
22-
println!("cargo::rustc-flags={}", libs);
23-
24-
let cflags = std::process::Command::new(format!("{}/bin/xml2-config", path.display(),))
24+
.map(|output| String::from_utf8_lossy(&output.stdout).to_string());
25+
let mut cflags = std::process::Command::new("sh")
26+
.arg(path.join("bin/xml2-config"))
2527
.arg("--cflags")
2628
.output()
27-
.expect("");
28-
let cflags = String::from_utf8_lossy(&cflags.stdout);
29+
.map(|output| String::from_utf8_lossy(&output.stdout).to_string());
30+
31+
if host.contains("windows") {
32+
libs = libs.map(|v| reg.replace_all(&v, "-$1$2:/").to_string());
33+
cflags = cflags.map(|v| reg.replace_all(&v, "-$1$2:/").to_string());
34+
}
35+
// NOTE: Manually specify
36+
let libs = libs.unwrap_or_else(|_| format!("-L{} -lxml2", path.join("lib").display()));
37+
println!("cargo::rustc-flags={}", libs);
2938

39+
// Note: Manually specify
40+
let cflags = cflags.unwrap_or_else(|_| format!("-I{}", path.join("include/libxml2").display()));
3041
let bindings_path = PathBuf::from(out_dir).join("bindings.rs");
3142
bindgen::builder()
3243
.opaque_type("max_align_t")

0 commit comments

Comments
 (0)