-
Notifications
You must be signed in to change notification settings - Fork 249
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
feat: configurable ldflags #1226
feat: configurable ldflags #1226
Conversation
9d5e961
to
16eee5d
Compare
The ci failures on this PR don't seem related to this change. The same error occurs on other recent PRs (e.g. #1223). I also did test run on main and the errors on macos still occurs. See #1228 and https://buildkite.com/bazel/rules-foreign-cc/builds/5761#0190be8c-a6b9-4df3-b99a-54831c1e37ef. I tried looking into the error but I cannot replicate it locally. Running
locally passes. However, I noticed my local resolves to |
@jsharpe - would you mind reviewing? TIA! |
16eee5d
to
698b47d
Compare
@jsharpe any chance of getting some feedback on this? |
698b47d
to
c1e2c2b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay in getting round to reviewing this - I've not had much time to devote to maintaining these rules and the priority was getting CI back to green first.
In an ideal world this wouldn't be needed but the reality is since third party build systems can do literally anything then it does make sense to be able to override the ldflags.
I think it'd be good if you could also plumb this through for meson and ninja rules too? Specifically if this was present for the meson rules we could actually fix the macOS CI issues that had popped up I think because the issue there is due to ldflags from the toolchain propagating through to meson's setup where its not expecting to have them set if I've understood the issue there correctly.
foreign_cc/configure.bzl
Outdated
"A string list of variable names use as LDFLAGS for shared libraries. These variables " + | ||
"will be passed to the make command as make vars and overwrite what is defined in " + | ||
"the Makefile." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this is true for autotools generated makefiles but in general a makefile doesn't have to accept the environment variable based overrides for any given flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I understand. The 2 flags I've added for the different linker flags are injected to the build_script.sh as make vars (not env vars), which can be used for autotools or non-autotools makefiles. Is there anything specific you would like me to update in the description?
I think the issue raised in this PR is also present in the Meson rule. Linking shared libraries is also complete ignored. If we are to consider a solution to this problem, I think it should also take cmake and meson into account. Also, does this PR consider the situation where we are building shared library with |
Thanks for reviewing @jsharpe. I had another look at the macOS CI issue with glib and meson. The issue is not a foreign_cc one but a meson one. I've raised a fix for it at #1260. Also, I agree configurable LDFLAGS should be extended to meson, ninja and even cmake. However, I don't have the expertise in those build tools to make the update. I also don't know how to test any updates I would make. I'm testing @allsey87 - given we are still using linker flags produced by the resolved cc_toolchain it should still support building shared libraries with |
65e8770
to
89af605
Compare
Looks like this is already supported in cmake in some form --> https://github.com/bazelbuild/rules_foreign_cc/blob/main/foreign_cc/private/cmake_script.bzl#L355 |
89af605
to
692d530
Compare
Looks like github had an outage when I last pushed. Is there anyway to retry or trigger another buildkite run without having to do a dummy commit? |
692d530
to
478f9fd
Compare
@jsharpe - any chance for another review on this? |
478f9fd
to
5b96748
Compare
2753ea9
to
41e5e1a
Compare
47078b0
to
ea688e4
Compare
configure_make()
andmake()
both resolvesLDFLAGS
toCxxToolsInfo.cxx_linker_executable
. This hard codes the linker executable flags and does not provide a way to use thecxx_linker_shared
flags. While this works for most use cases, it does not work for all. An example is when we enable--force-pic
which appends-pie
to our executable linker flags.-pie
is only applicable when linking executables and will fail on shared libraries since it cannot find amain()
function.This MR solves this problem by introducing 2 new attributes to
configure_make()
andmake()
.executable_ldflags_vars
shared_ldflags_vars
Each is a string_list of variable names that the target project uses for executable ldflags and shared ldflags. For example, in openssl3 BIN_LDFLAGS is used for executable ldflags and LIB_LDFLAGS is used for shared ldflags.
by overwriting the respective *_LDFLAGS using make vars mapped to
cxx_linker_executable
andcxx_shared_executable
we can enforce the mapping of appropriate linker flags.