Skip to content

Commit 5904f4f

Browse files
committed
SCons: Fix support for compiling .S files on Windows/MinGW
1 parent 445a518 commit 5904f4f

File tree

2 files changed

+122
-1
lines changed

2 files changed

+122
-1
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
From 76e9d2f867467a567cec330e19f25c763e9129a0 Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= <[email protected]>
3+
Date: Thu, 5 Jun 2025 14:10:03 +0200
4+
Subject: [PATCH] zstd: Enable x86_64 assembly for Windows/MinGW
5+
6+
Fix SCons setup to compile .S files with preprocessor support with MinGW.
7+
---
8+
core/SCsub | 10 ++++++----
9+
platform/windows/detect.py | 4 +++-
10+
thirdparty/README.md | 4 ----
11+
thirdparty/zstd/common/portability_macros.h | 2 +-
12+
.../zstd/patches/0001-windows-turn-off-asm.patch | 13 -------------
13+
5 files changed, 10 insertions(+), 23 deletions(-)
14+
delete mode 100644 thirdparty/zstd/patches/0001-windows-turn-off-asm.patch
15+
16+
diff --git a/core/SCsub b/core/SCsub
17+
index 5820b78b12..b4c4a691a2 100644
18+
--- a/core/SCsub
19+
+++ b/core/SCsub
20+
@@ -111,9 +111,7 @@ thirdparty_minizip_sources = ["ioapi.c", "unzip.c", "zip.c"]
21+
thirdparty_minizip_sources = [thirdparty_minizip_dir + file for file in thirdparty_minizip_sources]
22+
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_minizip_sources)
23+
24+
-# Zstd library, can be unbundled in theory
25+
-# though we currently use some private symbols
26+
-# https://github.com/godotengine/godot/issues/17374
27+
+# Zstd library, can be unbundled
28+
if env["builtin_zstd"]:
29+
thirdparty_zstd_dir = "#thirdparty/zstd/"
30+
thirdparty_zstd_sources = [
31+
@@ -144,7 +142,11 @@ if env["builtin_zstd"]:
32+
"decompress/zstd_decompress_block.c",
33+
"decompress/zstd_decompress.c",
34+
]
35+
- if env["platform"] in ["android", "ios", "linuxbsd", "macos"] and env["arch"] == "x86_64":
36+
+ if (
37+
+ env["platform"] in ["android", "ios", "linuxbsd", "macos", "windows"]
38+
+ and env["arch"] == "x86_64"
39+
+ and not env.msvc
40+
+ ):
41+
# Match platforms with ZSTD_ASM_SUPPORTED in common/portability_macros.h
42+
thirdparty_zstd_sources.append("decompress/huf_decompress_amd64.S")
43+
thirdparty_zstd_sources = [thirdparty_zstd_dir + file for file in thirdparty_zstd_sources]
44+
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
45+
index 3e808ac8a9..9a5ee8e467 100644
46+
--- a/platform/windows/detect.py
47+
+++ b/platform/windows/detect.py
48+
@@ -707,6 +707,7 @@ def configure_mingw(env: "SConsEnvironment"):
49+
env["CXX"] = get_detected(env, "clang++")
50+
env["AR"] = get_detected(env, "ar")
51+
env["RANLIB"] = get_detected(env, "ranlib")
52+
+ env["AS"] = get_detected(env, "clang")
53+
env.Append(ASFLAGS=["-c"])
54+
env.extra_suffix = ".llvm" + env.extra_suffix
55+
else:
56+
@@ -714,6 +715,8 @@ def configure_mingw(env: "SConsEnvironment"):
57+
env["CXX"] = get_detected(env, "g++")
58+
env["AR"] = get_detected(env, "gcc-ar" if os.name != "nt" else "ar")
59+
env["RANLIB"] = get_detected(env, "gcc-ranlib")
60+
+ env["AS"] = get_detected(env, "gcc")
61+
+ env.Append(ASFLAGS=["-c"])
62+
63+
env["RC"] = get_detected(env, "windres")
64+
ARCH_TARGETS = {
65+
@@ -724,7 +727,6 @@ def configure_mingw(env: "SConsEnvironment"):
66+
}
67+
env.AppendUnique(RCFLAGS=f"--target={ARCH_TARGETS[env['arch']]}")
68+
69+
- env["AS"] = get_detected(env, "as")
70+
env["OBJCOPY"] = get_detected(env, "objcopy")
71+
env["STRIP"] = get_detected(env, "strip")
72+
73+
diff --git a/thirdparty/README.md b/thirdparty/README.md
74+
index 988349b137..f5730f30bd 100644
75+
--- a/thirdparty/README.md
76+
+++ b/thirdparty/README.md
77+
@@ -1182,7 +1182,3 @@ Files extracted from upstream source:
78+
79+
- `lib/{common/,compress/,decompress/,zstd.h,zstd_errors.h}`
80+
- `LICENSE`
81+
-
82+
-Patches:
83+
-
84+
-- `0001-windows-turn-off-asm.patch` (GH-103596)
85+
diff --git a/thirdparty/zstd/common/portability_macros.h b/thirdparty/zstd/common/portability_macros.h
86+
index b2c028ccf1..860734141d 100644
87+
--- a/thirdparty/zstd/common/portability_macros.h
88+
+++ b/thirdparty/zstd/common/portability_macros.h
89+
@@ -114,7 +114,7 @@
90+
* 100% of code to be instrumented to work.
91+
*/
92+
#if defined(__GNUC__)
93+
-# if defined(__linux__) || defined(__linux) || defined(__APPLE__)
94+
+# if defined(__linux__) || defined(__linux) || defined(__APPLE__) || defined(_WIN32)
95+
# if ZSTD_MEMORY_SANITIZER
96+
# define ZSTD_ASM_SUPPORTED 0
97+
# elif ZSTD_DATAFLOW_SANITIZER
98+
diff --git a/thirdparty/zstd/patches/0001-windows-turn-off-asm.patch b/thirdparty/zstd/patches/0001-windows-turn-off-asm.patch
99+
deleted file mode 100644
100+
index 4765a17690..0000000000
101+
--- a/thirdparty/zstd/patches/0001-windows-turn-off-asm.patch
102+
+++ /dev/null
103+
@@ -1,13 +0,0 @@
104+
-diff --git a/thirdparty/zstd/common/portability_macros.h b/thirdparty/zstd/common/portability_macros.h
105+
-index 860734141d..b2c028ccf1 100644
106+
---- a/thirdparty/zstd/common/portability_macros.h
107+
-+++ b/thirdparty/zstd/common/portability_macros.h
108+
-@@ -114,7 +114,7 @@
109+
- * 100% of code to be instrumented to work.
110+
- */
111+
- #if defined(__GNUC__)
112+
--# if defined(__linux__) || defined(__linux) || defined(__APPLE__) || defined(_WIN32)
113+
-+# if defined(__linux__) || defined(__linux) || defined(__APPLE__)
114+
- # if ZSTD_MEMORY_SANITIZER
115+
- # define ZSTD_ASM_SUPPORTED 0
116+
- # elif ZSTD_DATAFLOW_SANITIZER
117+
--
118+
2.49.0
119+

platform/windows/detect.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,13 +707,16 @@ def configure_mingw(env: "SConsEnvironment"):
707707
env["CXX"] = get_detected(env, "clang++")
708708
env["AR"] = get_detected(env, "ar")
709709
env["RANLIB"] = get_detected(env, "ranlib")
710+
env["AS"] = get_detected(env, "clang")
710711
env.Append(ASFLAGS=["-c"])
711712
env.extra_suffix = ".llvm" + env.extra_suffix
712713
else:
713714
env["CC"] = get_detected(env, "gcc")
714715
env["CXX"] = get_detected(env, "g++")
715716
env["AR"] = get_detected(env, "gcc-ar" if os.name != "nt" else "ar")
716717
env["RANLIB"] = get_detected(env, "gcc-ranlib")
718+
env["AS"] = get_detected(env, "gcc")
719+
env.Append(ASFLAGS=["-c"])
717720

718721
env["RC"] = get_detected(env, "windres")
719722
ARCH_TARGETS = {
@@ -724,7 +727,6 @@ def configure_mingw(env: "SConsEnvironment"):
724727
}
725728
env.AppendUnique(RCFLAGS=f"--target={ARCH_TARGETS[env['arch']]}")
726729

727-
env["AS"] = get_detected(env, "as")
728730
env["OBJCOPY"] = get_detected(env, "objcopy")
729731
env["STRIP"] = get_detected(env, "strip")
730732

0 commit comments

Comments
 (0)