mirror of
https://github.com/openai/codex.git
synced 2026-05-04 19:36:45 +00:00
Enable Windows Bazel Rust test coverage
This commit is contained in:
@@ -1,62 +1,39 @@
|
||||
diff --git a/cargo/private/cargo_build_script.bzl b/cargo/private/cargo_build_script.bzl
|
||||
--- a/cargo/private/cargo_build_script.bzl
|
||||
+++ b/cargo/private/cargo_build_script.bzl
|
||||
@@ -142,40 +142,82 @@ def _strip_stack_protector_for_windows_llvm_mingw(toolchain, args):
|
||||
def _rewrite_windows_exec_msvc_cc_args(toolchain, args):
|
||||
"""Translate GNU-flavored cc args when exec-side build scripts target Windows MSVC."""
|
||||
@@ -144,9 +144,14 @@ def _rewrite_windows_exec_msvc_cc_args(toolchain, args):
|
||||
if toolchain.target_flag_value != toolchain.exec_triple.str or not toolchain.exec_triple.str.endswith("-pc-windows-msvc"):
|
||||
return args
|
||||
|
||||
- rewritten = []
|
||||
- skip_next = False
|
||||
- for arg in args:
|
||||
- if skip_next:
|
||||
- skip_next = False
|
||||
- continue
|
||||
+ rewritten = [
|
||||
+ "-target",
|
||||
+ toolchain.target_flag_value,
|
||||
+ ]
|
||||
+ skip_next = False
|
||||
skip_next = False
|
||||
- for arg in args:
|
||||
+ for index in range(len(args)):
|
||||
+ arg = args[index]
|
||||
+
|
||||
+ if skip_next:
|
||||
+ skip_next = False
|
||||
+ continue
|
||||
|
||||
if arg == "-target":
|
||||
- skip_next = True
|
||||
+ skip_next = True
|
||||
if skip_next:
|
||||
skip_next = False
|
||||
continue
|
||||
|
||||
if arg.startswith("-target=") or arg.startswith("--target="):
|
||||
continue
|
||||
|
||||
@@ -161,21 +166,58 @@ def _rewrite_windows_exec_msvc_cc_args(toolchain, args):
|
||||
if arg == "-nostdlibinc" or arg.startswith("--sysroot"):
|
||||
continue
|
||||
|
||||
- if "mingw-w64-" in arg or "mingw_import_libraries_directory" in arg or "mingw_crt_library_search_directory" in arg:
|
||||
+ if arg.startswith("-fstack-protector") or arg.startswith("-D_FORTIFY_SOURCE="):
|
||||
continue
|
||||
|
||||
- if arg.startswith("-fstack-protector"):
|
||||
- continue
|
||||
-
|
||||
- if arg.startswith("-D_FORTIFY_SOURCE="):
|
||||
- continue
|
||||
+ continue
|
||||
+
|
||||
+ if arg == "-isystem" and index + 1 < len(args):
|
||||
+ path = args[index + 1]
|
||||
+ if "mingw-w64-" in path or "mingw_import_libraries_directory" in path or "mingw_crt_library_search_directory" in path:
|
||||
+ skip_next = True
|
||||
+ continue
|
||||
|
||||
rewritten.append(arg)
|
||||
|
||||
- return [
|
||||
- "-target",
|
||||
- toolchain.target_flag_value,
|
||||
- ] + rewritten
|
||||
+
|
||||
+ rewritten.append(arg)
|
||||
+
|
||||
+ return rewritten
|
||||
+
|
||||
+def _rewrite_windows_exec_msvc_link_args(toolchain, args):
|
||||
@@ -78,8 +55,9 @@ diff --git a/cargo/private/cargo_build_script.bzl b/cargo/private/cargo_build_sc
|
||||
+ continue
|
||||
+
|
||||
+ if arg.startswith("--sysroot="):
|
||||
+ continue
|
||||
+
|
||||
continue
|
||||
|
||||
- if arg.startswith("-fstack-protector"):
|
||||
+ if arg == "-L" and index + 1 < len(args):
|
||||
+ path = args[index + 1]
|
||||
+ if "mingw_import_libraries_directory" in path or "mingw_crt_library_search_directory" in path:
|
||||
@@ -87,25 +65,120 @@ diff --git a/cargo/private/cargo_build_script.bzl b/cargo/private/cargo_build_sc
|
||||
+ continue
|
||||
+ rewritten.extend([arg, path])
|
||||
+ skip_next = True
|
||||
+ continue
|
||||
+
|
||||
continue
|
||||
|
||||
- if arg.startswith("-D_FORTIFY_SOURCE="):
|
||||
+ if arg.startswith("-L") and (
|
||||
+ "mingw_import_libraries_directory" in arg or
|
||||
+ "mingw_crt_library_search_directory" in arg
|
||||
+ ):
|
||||
+ continue
|
||||
+
|
||||
+ rewritten.append(arg)
|
||||
+
|
||||
continue
|
||||
|
||||
rewritten.append(arg)
|
||||
|
||||
- return [
|
||||
- "-target",
|
||||
- toolchain.target_flag_value,
|
||||
- ] + rewritten
|
||||
+ return rewritten
|
||||
|
||||
def get_cc_compile_args_and_env(cc_toolchain, feature_configuration):
|
||||
"""Gather cc environment variables from the given `cc_toolchain`
|
||||
@@ -509,6 +550,7 @@ def _construct_build_script_env(
|
||||
@@ -508,15 +550,23 @@ 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
|
||||
+ link_args = _rewrite_windows_exec_msvc_link_args(toolchain, link_args)
|
||||
env["LDFLAGS"] = " ".join(_pwd_flags(link_args))
|
||||
- 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
|
||||
+ link_args = _rewrite_windows_exec_msvc_link_args(toolchain, link_args)
|
||||
+ env["LDFLAGS"] = " ".join(_pwd_flags(link_args))
|
||||
+
|
||||
+ # Defaults for cxx flags.
|
||||
+ env["CFLAGS"] = ""
|
||||
+ env["CXXFLAGS"] = ""
|
||||
|
||||
# Defaults for cxx flags.
|
||||
- # 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",
|
||||
@@ -542,36 +592,37 @@ 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)
|
||||
- cc_c_args = _rewrite_windows_exec_msvc_cc_args(toolchain, cc_c_args)
|
||||
- cc_cxx_args = _rewrite_windows_exec_msvc_cc_args(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)
|
||||
+ cc_c_args = _rewrite_windows_exec_msvc_cc_args(toolchain, cc_c_args)
|
||||
+ cc_cxx_args = _rewrite_windows_exec_msvc_cc_args(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
|
||||
|
||||
Reference in New Issue
Block a user