-
Notifications
You must be signed in to change notification settings - Fork 159
Description
When building for windows, most cc packages assume targeting @platforms//os:windows implies compiler is msvc-style (msvc-cl or clang-cl).
As part toolchains_llvm_bootstrapped, we use clang to build for windows using mingw and hit a number of build errors because of this assumption. We upstreamed a number of fixes already but sometimes, selecting on the compiler alone is enough.
For example, in the code below, the correct select statement would need to be:
@platforms//os:windowsAND@rules_cc//cc/compiler=msvc-cl=>bcrypt.lib@platforms//os:windowsAND@rules_cc//cc/compiler=clang-cl=>bcrypt.lib@platforms//os:windowsAND@rules_cc//cc/compiler=clang=>-lbcrypt- default => None
linkopts = select({
"@platforms//os:windows": [
"bcrypt.lib",
],
"//conditions:default": [
"-lm",
"-pthread",
"-ldl",
],
}),
LLVM uses an extra config_setting to handle this properly too:
linkopts = select({
"//llvm:is_windows_clang_mingw": ["-lversion"],
"//llvm:is_windows_clang_cl": ["version.lib"],
"//llvm:is_windows_msvc": ["version.lib"],
"//conditions:default": [],
}),
As we progress fixing packages to support building for windows using clang, we will encounter more and more of those issues.
Would it be reasonable to have those config_settings inside rules_cc instead of redefining them in every project where it's needed ?
cc @keith since you added those config_setting first in llvm.