-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Link against shared zlib library when cross-compiling #201
Comments
Thanks for reporting! I'd hope that this information is available in the Git history somewhere. As insinuated, the intention behind a lot of things might not be clear from looking at the code and if unlucky isn't even discovered when checking the Git history. Further, due to the nature of this crate, it's hard to test on all platforms so a test is unlikely to fail if any change to And in a way, this makes changes like these hard to make as it alters semantics that many might rely upon, at least implicitly. I don't really know how to solve this except for trying to build actual tests for all the involved platforms, essentially rebuilding the build-script in a test-driven fashion and finally, releasing a new major version as one should probably fix a lot of things on the way. |
I tried to figure this out from git log, but I failed. To workaround this, we could add another ENV var, similar to LIBZ_SYS_STATIC, e.g. LIBZ_SYS_FORCE_PKG_CONFIG=1, or similar to override this behavior if someone wants it. This would solve my issue (on a probably not that nice way), but I would still think the default behavior would be to link with the installed shared library. |
It's a good idea to have a variable of sorts - instead of an environment variable, would a Cargo feature work? Regarding the default behaviour, I am afraid this can't change without a new breaking release, and it's something I'd consider doing if the build script would be re-built with full documentation and full testing. |
Yes, I think, that should work.
I agree. |
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. fixes rust-lang#201
I couldn't make it working with a Cargo feature for me. Unfortunately I'm using a workspace Cargo.toml, and libz-sys is pulled in by a dependency. So I couldn't really find a good way to set a feature for libz-sys. ENV var is a better fit. |
I understand. The way this could work, very explicitly, with cargo features is by adding the libz-sys-for-configuration = { version = "X", package = "libz-sys", features = ["whateveryouneed"] } |
So you mean, adding it to "[workspace.dependencies]". I already tried that, but it wasn't working. Note, that I'm using "[patch.create-io]" to be able to modify libz-sys, but I don't think that should change anything. Another use-case for ENV var: what if we are thinking in build systems, like buildroot? If there are multiple packages which are pulling in libz-sys as a dependency (multiple builds), I should have to patch each recipes to add this feature to their Cargo.toml. But using an ENV variable, I can just add it to the generic Cargo ENV vars, and if something is pulling in libz-sys, it will work automagically. |
No, it would have to be a
That's a valid point, and to make that possible, it should certainly be an environment variable. I think the issue to solve really is to make it less magic. At least I'd expect to be able to learn about this magic somewhere, and the |
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:
The text was updated successfully, but these errors were encountered: