Files
codex/patches/llvm_windows_mingw_compat.patch
T

69 lines
2.0 KiB
Diff

# What: provide MinGW compile and link compatibility required by Windows gnullvm.
# Why: Bazel's Windows launcher needs the UCRT secure-random declaration, while
# clang and prebuilt MSVC archives request libraries the hermetic runtime does
# not publish by default.
diff --git a/toolchain/args/BUILD.bazel b/toolchain/args/BUILD.bazel
--- a/toolchain/args/BUILD.bazel
+++ b/toolchain/args/BUILD.bazel
@@ -765,5 +765,12 @@ cc_args(
# provided as part of the compiler toolchain repository.
"-nostdlibinc",
- ],
+ ] + select({
+ # MinGW exposes rand_s only when this UCRT feature macro is defined.
+ # Bazel's native Windows launcher uses rand_s unconditionally, so make
+ # the declaration available to every hermetic Windows compile.
+ "//platforms/config:windows_aarch64": ["-D_CRT_RAND_S="],
+ "//platforms/config:windows_x86_64": ["-D_CRT_RAND_S="],
+ "//conditions:default": [],
+ }),
)
diff --git a/runtimes/mingw/BUILD.bazel b/runtimes/mingw/BUILD.bazel
--- a/runtimes/mingw/BUILD.bazel
+++ b/runtimes/mingw/BUILD.bazel
@@ -386,14 +386,42 @@ stub_library(
name = "stdc++",
)
+# Clang may inject -lssp and -lssp_nonshared for windows-gnu links.
+# Provide compatibility archives in the MinGW runtime search directory.
+stub_library(
+ name = "ssp",
+)
+
+stub_library(
+ name = "ssp_nonshared",
+)
+
+# Prebuilt MSVC archives can carry /DEFAULTLIB:libcmt.lib and
+# /DEFAULTLIB:oldnames.lib directives. Provide MinGW-compatible stand-ins so
+# lld can satisfy the lookup under windows-gnullvm.
+stub_library(
+ name = "libcmt",
+)
+
+copy_file(
+ name = "oldnames",
+ src = ":moldname",
+ out = "liboldnames.a",
+ visibility = ["//visibility:public"],
+)
+
copy_to_directory(
name = "mingw_crt_library_search_directory",
srcs = [
+ ":libcmt",
":m",
":mingw32",
":mingwex",
":moldname",
+ ":oldnames",
":pthread",
+ ":ssp",
+ ":ssp_nonshared",
":stdc++",
":uuid",
":winpthread",