Skip to content

Commit

Permalink
Fix #2406: use codegen option link-args to forward `user_link_flags…
Browse files Browse the repository at this point in the history
…` in bindgen. (#2407)

This commit fixes issue #2406 by using the [`link-args`] codegen option
of `rustc`:

```
-C
link-args=<user_link_flags>
```

where `<user_link_flags>` are the flags from the [`user_link_flags`]
field of [`LinkerInput`].

[`user_link_flags`]:
https://bazel.build/rules/lib/builtins/LinkerInput#user_link_flags
[`LinkerInput`]: https://bazel.build/rules/lib/builtins/LinkerInput
[`link-args`]:
https://doc.rust-lang.org/rustc/codegen-options/index.html#link-args
  • Loading branch information
thomas authored Jan 9, 2024
1 parent 012af3b commit 90e4505
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bindgen/private/bindgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ def _generate_cc_link_build_info(ctx, cc_lib):
linker_search_paths.append(lib.pic_static_library.dirname)
compile_data.append(lib.pic_static_library)

linker_flags.extend(linker_input.user_link_flags)
if linker_input.user_link_flags:
linker_flags.append("-C")
linker_flags.append("link-args={}".format(" ".join(linker_input.user_link_flags)))

if not compile_data:
fail("No static libraries found in {}".format(
Expand Down

0 comments on commit 90e4505

Please sign in to comment.