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

Allow unsetting compiler env vars #1113

Open
attilaolah opened this issue Nov 4, 2023 · 3 comments
Open

Allow unsetting compiler env vars #1113

attilaolah opened this issue Nov 4, 2023 · 3 comments

Comments

@attilaolah
Copy link
Contributor

When I pass certain environment variables via env = {…}, instead of being set directly, they will be appended to the existing variables provided by the C toolchain. These are variables like CFLAGS, ASFLAGS, etc.

I hit the problem where some projects, like x264, need a specific assembler. So I pass in my custom-built nasm as a dependency, but now they will still use the compiler toolchain's ASFLAGS with nasm, which doesn't understand all the llvm-as flags so it fails to assemble anything.

When I pass in any other ASFLAGS via env, they simply get appended. I'd like to have a way to overwrite these flags when necessary. Not sure what would be the most elegant way to do this; it could be a separate boolean flag, something like override_env, which, when set to True, would replace these env vars instead of merging them? This would preserve existing behaviour which is probably appropriate for most other use cases.

I'm open to other suggestions too.

@attilaolah
Copy link
Contributor Author

attilaolah commented Nov 4, 2023

Interestingly, looks like there is an example file here that does exactly the same: https://github.com/bazelbuild/rules_foreign_cc/blob/main/examples/third_party/openssl/BUILD.openssl.bazel#L59-L61

Not sure what I'm doing wrong here but it doesn't seem to work for me.

Actually, that config uses configure_options, which is not possible in the case of x264.

@voxeljorge
Copy link

I ran into the same thing with libx264 (although in my case I was just allowing a system installed nasm to run) and I solved it by setting configure_prefix like this:

configure_make(
    name = "libx264",
    configure_prefix = "ASFLAGS=\"\" CFLAGS=\"\" CXXFLAGS=\"\"",
    lib_source = "@experimental_libx264",
)

I had to also clear CFLAGS as the default toolchain that was getting pulled in was setting some flags that were incompatible with the libx264 build.

@attilaolah
Copy link
Contributor Author

Nice, definitely simpler than the env_override parameter I concocted. Clearing CFLAGS is a bit unfortunate, you may be able to work around that by fiddling with copts or maybe customising your toolchain, but this should work too. (That said, this will probably invalidate things like -c opt for you.)

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

2 participants