rust-lang / rust-lang/libz-sys
Link against shared zlib library when cross-compiling
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 138
- Forks
- 88
- PR merge metrics
- No merged PRs in 30d
Description
Currently libz-sys is always building a static zlib library when cross-compiling, except on Apple platforms. Can I ask the reason of this? I have a shared zlib library in my rootfs, and pkg-config is working fine. With this config, I have a build failure because of library collision, 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
If I remove forcing this static library build, it is building fine:
index cab160ae6e6f..87e3e8664fd6 100644
--- a/build.rs
+++ b/build.rs
@@ -81,11 +81,11 @@ fn main() {
//
// Apple platforms have libz.1.dylib, and it's usually available even when
// cross compiling (via fat binary or in the target's Xcode SDK)
- let cross_compiling = target != host;
+ // let cross_compiling = target != host;
if target.contains("msvc")
|| target.contains("pc-windows-gnu")
|| want_static
- || (cross_compiling && !target.contains("-apple-"))
+ // || (cross_compiling && !target.contains("-apple-"))
{
return build_zlib(&mut cfg, &target);
}```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in build.rs, especially the cross_compiling check and build_zlib call, and review how the cross-compiling branch interacts with pkg-config and a shared zlib in the target rootfs. Reproduce the reported AArch64 linking failure with the stated configuration. Done means the intended shared-versus-static behavior is resolved for cross-compilation without the reported library collision.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100