bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Make default_compile_flags configurable for the default Windows CC toolchain

Open davetclark opened this issue 5 years ago • 10 comments

Description of the problem / feature request:

For the default windows cc toolchain, make the default_compile_flags given by the default_compile_flags feature be configurable, as an attribute to the cc_toolchain_config

Feature requests: what underlying problem are you trying to solve with this feature?

Allow users of the default window toolchain to configure the default flags without defining a whole new toolchain. For example, here's the list of flags for MSVC which are not able to be changed. These make some very big assumptions about how users want to compile code. flags = [ "/DCOMPILER_MSVC", "/DNOMINMAX", "/D_WIN32_WINNT=0x0601", "/D_CRT_SECURE_NO_DEPRECATE", "/D_CRT_SECURE_NO_WARNINGS", "/bigobj", "/Zm500", "/EHsc", "/wd4351", "/wd4291", "/wd4250", "/wd4996", ],

What operating system are you running Bazel on?

Win10

What's the output of bazel info release?

release 3.7.2

Have you found anything relevant by searching the web?

I've searched google and StackOverflows and github issues. The only solution I can find is to create a whole new toolchain definition. The existing one in github is 1300+ lines long. From reading tools/cpp/windows_cc_toolchain_config.bzl, I believe the solution to be adding a default_compile_flags (or default_compile_flags_msvc, default_compile_flags_msys etc) attribute, just like default_link_flags is doing, and other platforms are doing for their compile flags.

davetclark avatar Dec 21 '20 05:12 davetclark

Any update on this? I would simply like to disable the default compile flags but by adding features = ["-default_compile_flags"] to my rule I am greeted with the following error:

Error in configure_features: The C++ toolchain #@local_config_cc//:toolchain' unconditionally implies feature 'default_compile_flags', which is unsupported by this rule.

The fact that bazel enforces compile flags without an option to disable this feature is rather annoying

jheaff1 avatar Jul 15 '21 16:07 jheaff1

Any update on this? I currently cannot build Qt within Bazel due to the flags set by Bazel that cannot be switched off, eg /DEFAULTLIB:msvcrt.

Bazel should really allow users to customise the cc flags of the auto detected toolchains

jheaff1 avatar Feb 05 '22 16:02 jheaff1

any update on this ? do we have a approach to remove the default_compile_flags?

yun341 avatar Mar 07 '22 11:03 yun341

@yun341 I made a PR (#14735) but no one has reviewed it yet

jheaff1 avatar Mar 07 '22 18:03 jheaff1

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

github-actions[bot] avatar Jun 13 '23 01:06 github-actions[bot]

This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team (@bazelbuild/triage). Thanks!

github-actions[bot] avatar Jun 27 '23 01:06 github-actions[bot]

@jheaff1 I'm hitting this same issue. Have you ever found a solution?

jdebache avatar Nov 27 '23 18:11 jdebache

My PR (#14735) has been merged, so I’m Bazel 6.0 onwards you can remove default flags from the cc toolchain

jheaff1 avatar Nov 27 '23 20:11 jheaff1

@jheaff1 Thanks, that seems to work, except somehow for unfiltered_compile_flags. Maybe what I'm trying to do is just too 'out there'. For context, I'm trying to use the Circle compiler, which does not support -Wno-builtin-macro-redefined. This flag seems to be defined in the unfiltered_compile_flags, from looking at the Bazel sources.

I have the following .bazelrc

build --action_env=CC="/home/jd/bin/circle"
build --action_env=CXX="/home/jd/bin/circle"
build --features=-default_compile_flags
build --features=-random_seed
build --features=-unfiltered_compile_flags

And I'm still getting:

Error in configure_features: The C++ toolchain '@local_config_cc//:toolchain' unconditionally implies feature 'unfiltered_compile_flags', which is unsupported by this rule. This is most likely a misconfiguration in the C++ toolchain.

I'm not sure what 'unconditionally' means here to be honest...

jdebache avatar Dec 08 '23 17:12 jdebache

I'm having the same issue. Something must have changed after that PR merge, at least when I try to use -default_compile_flags it still gives me the[...] unconditionally implies feature 'default_compile_flags' error. Any way around this?

dpvdberg avatar Apr 14 '24 14:04 dpvdberg