mcgoo / vcpkg-rs

Build library for finding native libraries in vcpkg for Rust - Windows (msvc), Linux and macOS
https://docs.rs/vcpkg
Apache License 2.0
108 stars 22 forks source link

Links to static libraries not working on Linux (?) #21

Closed pkgw closed 4 years ago

pkgw commented 4 years ago

I'm testing out some new Linux builds of tectonic using vcpkg-rs. My cargo build commands works OK, but cargo test doesn't because of missing symbols. As far as I can tell, the root cause is that the link information being emitted by vcpkg-rs doesn't tell Rust that it should be linking with static libraries. That is, the output from build.rs is like this:

cargo:rustc-link-search=native=/home/peter/sw/tex/tectonic/target/vcpkg/installed/x64-linux/lib
cargo:rustc-link-lib=harfbuzz-icu
cargo:rustc-link-lib=harfbuzz

instead of rustc-link-lib=static=harfbuzz, etc.

I notice that there used to be a test for vcpkg_target.is_static that would emit the static= variant, but it was removed in 34292487ce112e69d99e561c38f49d1a9ba8e0eb . It is not obvious to me what the motivation for that was, but my best understanding is that there should be a codepath that at least makes sure that static= comes back on Linux static builds.

mcgoo commented 4 years ago

I think https://github.com/tectonic-typesetting/tectonic/pull/664 should fix what you are seeing.

The static= was dropped when vcpkg-rs only supported Windows. As I understand it, static= is definitely at least unnecessary on Windows, and possibly broken. There is a nightly static-nobundle feature that (I think) is supposed to fix whatever was not working.

I tried making the Linux build mark everything as static= but this resulted in duplicate symbols instead of missing symbols. (I wonder if this is because both the tectonic rlib and the test binaries have the same build.rs run for them since they are in the same crate?)

As an aside, I just had to fix the Linux tests for vcpkg-rs by manually printing cargo:rustc-link-lib=brotlicommon-static from build.rs because the libraries were in the wrong order. The particular test links to harfbuzz since it's one of the more complex things I could find. For some reason, tectonic does not seem to have the same problem. I still do not have a solution for guaranteeing the correct link order from vcpkg. (vcpkg itself works fine when it is used as intended.)

pkgw commented 4 years ago

OK, thanks for investigating! I'll close this since it sounds like there isn't anything to be changed in this crate.

waych commented 3 years ago

See #27 for potential solution to library ordering problem described above.