Skip to content
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

rustc-link-search parameters are not propagated to dependent crates #859

Closed
djmarcin opened this issue Jul 29, 2021 · 4 comments · Fixed by #1123
Closed

rustc-link-search parameters are not propagated to dependent crates #859

djmarcin opened this issue Jul 29, 2021 · 4 comments · Fixed by #1123
Labels

Comments

@djmarcin
Copy link
Contributor

I'm trying to use the https://crates.io/crates/sentry-contrib-native crate which in turn depends on https://crates.io/crates/sentry-contrib-native-sys which has a build.rs that adds a rustc-link-search param. This parameter is correctly present in bazel-out/k8-fastbuild/bin/external/raze__sentry_contrib_native_sys__0_3_1/sentry_contrib_native_sys_build_script.linkflags but compilation eventually fails because the rust_binary that transitively depends on sentry-contrib-native-sys does not pick up the flag -L=${pwd}/bazel-out/k8-fastbuild/bin/external/raze__sentry_contrib_native_sys__0_3_1/sentry_contrib_native_sys_build_script.out_dir/lib, but it does seem to pick up the -lsentry, -lcrashpad_client, etc which can't be founds with out the -L flag.

It seems like this flag needs to be propagated up through transitive dependencies to the target that gets linked.

@UebelAndre UebelAndre added the bug label Jul 29, 2021
@illicitonion
Copy link
Collaborator

We used to propagate these transitively, and #448 changed that...

@djmarcin - could you put together a minimal repro case of this not working?
@dae - any thoughts?

@dae
Copy link
Contributor

dae commented Aug 11, 2021

This is not an area I know well, so I can only guess here - but maybe rustc-link-search should be propagated transitively, but not rustc-link-lib? If that is the case, it will be a little tricky, as currently cargo_build_script_runner lumps them all in together into link_flags.

https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname

@djmarcin
Copy link
Contributor Author

djmarcin commented Sep 3, 2021

Here's an example with the sentry crate https://github.com/djmarcin/sentry-repro. It could probably be reduced more, but I'm not certain why other sys crates don't seem to be showing the same issue.

The example also builds with cargo, and when building with -vv you can see that cargo does seem to pass the rustc-link-search up to the bin crate (although interestingly, it does not pass the -lsentry -lcrashpad_client etc that rules_rust is passing to the top level rust_binary crate -- these are only passed to the sys crate).

I suspect there may be something amiss with how the sentry-contrib-native crate is being compiled / linked against the sentry-contrib-native-sys crate, since the missing symbols seem to come from sentry-contrib-native code.

@djmarcin
Copy link
Contributor Author

djmarcin commented Sep 4, 2021

I was able to get this to succeed by patching the sentry-contrib-native-sys crate to emit link instructions like cargo:rustc-link-lib=static=sentry instead of cargo:rustc-link-lib=sentry, although it seems like it should work either way since it works in cargo.

My uninformed guess is that the rlib has some embedded info that it needs the "sentry" library to be linked and cargo passes along the link path so when rustc attempts to link "sentry" it finds it on the propagated link path, whereas because bazel is not propagating the link path, it's not found. Does this sound right?

illicitonion pushed a commit that referenced this issue Feb 10, 2022
Adds a new `link_search_paths: File` field to `BuildInfo` provider.

Resolves #859

I use native Windows bindings through [windows-rs](https://github.com/microsoft/windows-rs) crate and it fails to link without propagating the link search path to a platform-dependent native library. The bindings call for a native library via `#[link(name = "windows")]` and propagate search path by a buildscript from a dependency (i.e. a transitive dependency for a root crate).

Propagating link search paths seems to be what is cargo doing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants