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

linker search path of proc_macro deps are not propagated #2904

Open
erenon opened this issue Sep 30, 2024 · 1 comment
Open

linker search path of proc_macro deps are not propagated #2904

erenon opened this issue Sep 30, 2024 · 1 comment

Comments

@erenon
Copy link
Contributor

erenon commented Sep 30, 2024

Reproduction Requirements

I could trigger this on macOS only. Install:

$ brew install bazelisk postgresql@14 pkg-config

Then clone:

$ git clone https://github.com/erenon/proc-macro-link-flags.git

What happens there

rust_decimal is a regular library crate for decimal numbers. With the 'db-diesel2-postgres' feature,
it pulls in the pq-sys dependency, that in its build.rs potentially finds libpq using pkg-config:

cargo:rustc-link-search=native=/opt/homebrew/lib/postgresql@14
cargo:rustc-link-lib=pq

(To make pkg-config work with the homebrew setup, we are modifying some envvars, see .bazelrc)

In the demo repository, the target //:good depends on rust_decimal, and bazel can compile and link it.

The rust_decimal_macros is a proc-macro crate, that provides (surprise!) macros for the above crate.
It depends on rust_decimal, therefore it also pulls in pq-sys transitively.

In the demo repository, the target //:bad depends on rust_decimal_macros, and bazel cannot compile it:

$ bazel build bad
[...]
ld: library 'pq' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Suspicion

aquery shows that //:good inherits a linker search path from pq-sys:

$ bazel aquery good | grep pq
[...]
bazel-out/darwin_arm64-fastbuild/bin/external/rules_rust~~crate~crates__pq-sys-0.6.3/_bs.linksearchpaths \

but //bad: does not. Therefore the suspicion, that proc macro crates do not pass forward their link search path files?

Interestingly, even if bad also depends on rust_decimal or even pq-sys, it doesn't link.

@erenon
Copy link
Contributor Author

erenon commented Oct 1, 2024

Refined suspicion: The link search path given by the build.rs file is not propagated to the linking of proc-macro itself, that is linked in host configuration. Ugly workaround:

build:macos --host_linkopt "-L/opt/homebrew/lib/postgresql@14"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant