Make default_compile_flags configurable for the default Windows CC toolchain
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.
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
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
any update on this ? do we have a approach to remove the default_compile_flags?
@yun341 I made a PR (#14735) but no one has reviewed it yet
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.
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!
@jheaff1 I'm hitting this same issue. Have you ever found a solution?
My PR (#14735) has been merged, so I’m Bazel 6.0 onwards you can remove default flags from the cc toolchain
@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...
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?