Skip to content

Commit 612984b

Browse files
committed
Add LIB_SYS_TRY_SHARED ENV var to try to link with shared library
On cross-compilation libz-sys is always building static zlib library, except for Apple platforms. If target has an installed zlib shared library, this is problem, because: 1. the binary is increased, because we are including a static zlib as well 2. it may cause build issues if the pkg-config sets the linker arguments, like this: /tmp/rustc0ZqD0F/liblibz_sys-84983a050a121d20.rlib(inflate.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol '__stack_chk_guard' which may bind externally can not be used when making a shared object; recompile with -fPIC To workaround the issue, add a LIB_SYS_TRY_SHARED=1 ENV var (similarly to LIBZ_SYS_STATIC=1) to force the use of the shared library, recognized by the pkg-config.
1 parent 788f050 commit 612984b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ fn main() {
8282
// Apple platforms have libz.1.dylib, and it's usually available even when
8383
// cross compiling (via fat binary or in the target's Xcode SDK)
8484
let cross_compiling = target != host;
85+
let try_link_with_shared =
86+
env::var("LIB_SYS_TRY_SHARED").unwrap_or(String::new()) == "1";
8587
if target.contains("msvc")
8688
|| target.contains("pc-windows-gnu")
8789
|| want_static
88-
|| (cross_compiling && !target.contains("-apple-"))
90+
|| !try_link_with_shared && (cross_compiling && !target.contains("-apple-"))
8991
{
9092
return build_zlib(&mut cfg, &target);
9193
}

0 commit comments

Comments
 (0)