Files
codex/patches/rules_rust_windows_exec_msvc_build_script_env.patch
T

98 lines
4.7 KiB
Diff

diff --git a/cargo/private/cargo_build_script.bzl b/cargo/private/cargo_build_script.bzl
index 996541eeb..052c1eb9d 100644
--- a/cargo/private/cargo_build_script.bzl
+++ b/cargo/private/cargo_build_script.bzl
@@ -441,15 +441,22 @@ def _cargo_build_script_impl(ctx):
cc_toolchain, feature_configuration = find_cc_toolchain(ctx)
linker, _, link_args, linker_env = get_linker_and_args(ctx, "bin", toolchain, cc_toolchain, feature_configuration, None)
env.update(**linker_env)
- env["LD"] = linker
- env["LDFLAGS"] = " ".join(_pwd_flags(link_args))
+ use_windows_exec_msvc_path_tools = (
+ toolchain.target_flag_value == toolchain.exec_triple.str and
+ toolchain.exec_triple.str.endswith("-pc-windows-msvc")
+ )
+
+ if not use_windows_exec_msvc_path_tools:
+ env["LD"] = linker
+ env["LDFLAGS"] = " ".join(_pwd_flags(link_args))
+
+ # Defaults for cxx flags.
+ env["CFLAGS"] = ""
+ env["CXXFLAGS"] = ""
- # Defaults for cxx flags.
env["ARFLAGS"] = ""
- env["CFLAGS"] = ""
- env["CXXFLAGS"] = ""
fallback_tools = []
- if not cc_toolchain:
+ if not cc_toolchain and not use_windows_exec_msvc_path_tools:
fallbacks = {
"AR": "_fallback_ar",
"CC": "_fallback_cc",
@@ -475,34 +482,35 @@ def _cargo_build_script_impl(ctx):
toolchain_tools.append(cc_toolchain.all_files)
- env["CC"] = cc_common.get_tool_for_action(
- feature_configuration = feature_configuration,
- action_name = ACTION_NAMES.c_compile,
- )
- env["CXX"] = cc_common.get_tool_for_action(
- feature_configuration = feature_configuration,
- action_name = ACTION_NAMES.cpp_compile,
- )
- env["AR"] = cc_common.get_tool_for_action(
- feature_configuration = feature_configuration,
- action_name = ACTION_NAMES.cpp_link_static_library,
- )
-
- # Many C/C++ toolchains are missing an action_config for AR because
- # one was never included in the unix_cc_toolchain_config.
- if not env["AR"]:
- env["AR"] = cc_toolchain.ar_executable
-
- cc_c_args = _strip_stack_protector_for_windows_llvm_mingw(toolchain, cc_c_args)
- cc_cxx_args = _strip_stack_protector_for_windows_llvm_mingw(toolchain, cc_cxx_args)
- # Populate CFLAGS and CXXFLAGS that cc-rs relies on when building from source, in particular
- # to determine the deployment target when building for apple platforms (`macosx-version-min`
- # for example, itself derived from the `macos_minimum_os` Bazel argument).
- env["CFLAGS"] = " ".join(_pwd_flags(cc_c_args))
- env["CXXFLAGS"] = " ".join(_pwd_flags(cc_cxx_args))
- # It may be tempting to forward ARFLAGS, but cc-rs is opinionated enough
- # that doing so is more likely to hurt than help. If you need to change
- # ARFLAGS, make changes to cc-rs.
+ if not use_windows_exec_msvc_path_tools:
+ env["CC"] = cc_common.get_tool_for_action(
+ feature_configuration = feature_configuration,
+ action_name = ACTION_NAMES.c_compile,
+ )
+ env["CXX"] = cc_common.get_tool_for_action(
+ feature_configuration = feature_configuration,
+ action_name = ACTION_NAMES.cpp_compile,
+ )
+ env["AR"] = cc_common.get_tool_for_action(
+ feature_configuration = feature_configuration,
+ action_name = ACTION_NAMES.cpp_link_static_library,
+ )
+
+ # Many C/C++ toolchains are missing an action_config for AR because
+ # one was never included in the unix_cc_toolchain_config.
+ if not env["AR"]:
+ env["AR"] = cc_toolchain.ar_executable
+
+ cc_c_args = _strip_stack_protector_for_windows_llvm_mingw(toolchain, cc_c_args)
+ cc_cxx_args = _strip_stack_protector_for_windows_llvm_mingw(toolchain, cc_cxx_args)
+ # Populate CFLAGS and CXXFLAGS that cc-rs relies on when building from source, in particular
+ # to determine the deployment target when building for apple platforms (`macosx-version-min`
+ # for example, itself derived from the `macos_minimum_os` Bazel argument).
+ env["CFLAGS"] = " ".join(_pwd_flags(cc_c_args))
+ env["CXXFLAGS"] = " ".join(_pwd_flags(cc_cxx_args))
+ # It may be tempting to forward ARFLAGS, but cc-rs is opinionated enough
+ # that doing so is more likely to hurt than help. If you need to change
+ # ARFLAGS, make changes to cc-rs.
# Inform build scripts of rustc flags
# https://github.com/rust-lang/cargo/issues/9600