Skip to content

Commit 9eeed70

Browse files
committed
Compile zlib for cross compiles
Also don't run `make install` as it apparently tries to compile a little too much that doesn't always work, instead just emulate it and build the bare-bones lib.
1 parent 523f409 commit 9eeed70

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

build.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ fn main() {
2222
// Practically all platforms come with libz installed already, but MSVC is
2323
// one of those sole platforms that doesn't!
2424
let target = env::var("TARGET").unwrap();
25+
let host = env::var("HOST").unwrap();
2526
if target.contains("msvc") {
2627
build_msvc_zlib(&target);
27-
} else if target.contains("musl") {
28+
} else if target.contains("musl") || target != host {
2829
build_zlib();
2930
} else {
3031
println!("cargo:rustc-link-lib=z");
@@ -45,12 +46,17 @@ fn build_zlib() {
4546
}
4647
run(Command::new("./configure")
4748
.current_dir(&build)
48-
.arg(format!("--prefix={}", dst.display()))
4949
.env("CC", compiler.path())
5050
.env("CFLAGS", cflags));
5151
run(Command::new("make")
5252
.current_dir(&build)
53-
.arg("install"));
53+
.arg("libz.a"));
54+
55+
t!(fs::create_dir_all(dst.join("lib")));
56+
t!(fs::create_dir_all(dst.join("include")));
57+
t!(fs::copy(build.join("libz.a"), dst.join("lib/libz.a")));
58+
t!(fs::copy(build.join("zlib.h"), dst.join("include/zlib.h")));
59+
t!(fs::copy(build.join("zconf.h"), dst.join("include/zconf.h")));
5460

5561
println!("cargo:rustc-link-lib=static=z");
5662
println!("cargo:rustc-link-search={}/lib", dst.to_string_lossy());

0 commit comments

Comments
 (0)