22
33import codecs
44import os
5+ import platform
56import sys
67import subprocess
78from binding_generator import scons_generate_bindings , scons_emit_files
@@ -91,15 +92,6 @@ if hasattr(os, "cpu_count") and env.GetOption("num_jobs") == altered_num_jobs:
9192 )
9293 env .SetOption ("num_jobs" , safer_cpu_count )
9394
94- is64 = sys .maxsize > 2 ** 32
95- if (
96- env ["TARGET_ARCH" ] == "amd64"
97- or env ["TARGET_ARCH" ] == "emt64"
98- or env ["TARGET_ARCH" ] == "x86_64"
99- or env ["TARGET_ARCH" ] == "arm64-v8a"
100- ):
101- is64 = True
102-
10395opts = Variables ([], ARGUMENTS )
10496opts .Add (
10597 EnumVariable (
@@ -110,7 +102,7 @@ opts.Add(
110102 ignorecase = 2 ,
111103 )
112104)
113- opts .Add (EnumVariable ("bits" , "Target platform bits" , "64" if is64 else "32 " , ( "32" , "64" )))
105+ opts .Add (EnumVariable ("bits" , "Target platform bits" , "auto" , ( "auto " , "32" , "64" )))
114106opts .Add (BoolVariable ("use_llvm" , "Use the LLVM compiler - only effective when targeting Linux or FreeBSD" , False ))
115107opts .Add (BoolVariable ("use_mingw" , "Use the MinGW compiler instead of MSVC - only effective on Windows" , False ))
116108# Must be the same setting as used for cpp_bindings
@@ -163,6 +155,25 @@ opts.Add(
163155
164156opts .Add (BoolVariable ("build_library" , "Build the godot-cpp library." , True ))
165157
158+ # CPU architecture options.
159+ architectures = ["auto" , "universal" , "x86_32" , "x86_64" , "arm32" , "arm64" , "rv64" , "ppc32" , "ppc64" , "wasm32" ]
160+ architecture_aliases = {
161+ "x86" : "x86_32" ,
162+ "x64" : "x86_64" ,
163+ "amd64" : "x86_64" ,
164+ "armv7" : "arm32" ,
165+ "armv8" : "arm64" ,
166+ "arm64v8" : "arm64" ,
167+ "aarch64" : "arm64" ,
168+ "rv" : "rv64" ,
169+ "riscv" : "rv64" ,
170+ "riscv64" : "rv64" ,
171+ "ppcle" : "ppc32" ,
172+ "ppc" : "ppc32" ,
173+ "ppc64le" : "ppc64" ,
174+ }
175+ opts .Add (EnumVariable ("arch" , "CPU architecture" , "auto" , architectures , architecture_aliases ))
176+
166177opts .Update (env )
167178Help (opts .GenerateHelpText (env ))
168179
@@ -173,16 +184,50 @@ if unknown:
173184 for item in unknown .items ():
174185 print (" " + item [0 ] + "=" + item [1 ])
175186
187+ # Compatibility with old bits argument on Windows/Linux.
188+ # Not needed on macOS or web. Android and iOS don't use env["arch"].
189+ if env ["platform" ] in ["windows" , "linux" ]:
190+ if env ["bits" ] == "64" :
191+ env ["arch" ] = "x86_64"
192+ elif env ["bits" ] == "32" :
193+ env ["arch" ] = "x86_32"
194+
195+ # Process CPU architecture argument.
196+ if env ["arch" ] == "auto" :
197+ # Use env["arch"] on all platforms except Android and iOS.
198+ # For macOS, default arch to macos_arch, which defaults to universal (compat with old argument).
199+ # For the web (javascript), default arch to wasm32.
200+ # For Windows and Linux, default arch to the host architecture.
201+ if env ["platform" ] == "osx" :
202+ env ["arch" ] = env ["macos_arch" ]
203+ elif env ["platform" ] == "javascript" :
204+ env ["arch" ] = "wasm32"
205+ else :
206+ host_machine = platform .machine ().lower ()
207+ if host_machine in architectures :
208+ env ["arch" ] = host_machine
209+ elif host_machine in architecture_aliases .keys ():
210+ env ["arch" ] = architecture_aliases [host_machine ]
211+ elif "86" in host_machine :
212+ # Catches x86, i386, i486, i586, i686, etc.
213+ env ["arch" ] = "x86_32"
214+ else :
215+ print ("Unsupported CPU architecture: " + host_machine )
216+ Exit ()
217+
218+ env_arch = env ["arch" ]
219+
176220# This makes sure to keep the session environment variables on Windows.
177221# This way, you can run SCons in a Visual Studio 2017 prompt and it will find
178222# all the required tools
179223if host_platform == "windows" and env ["platform" ] != "android" :
180- if env ["bits " ] == "64 " :
224+ if env ["arch " ] == "x86_64 " :
181225 env = Environment (TARGET_ARCH = "amd64" )
182- elif env ["bits " ] == "32 " :
226+ elif env ["arch " ] == "x86_32 " :
183227 env = Environment (TARGET_ARCH = "x86" )
184228
185229 opts .Update (env )
230+ env ["arch" ] = env_arch
186231
187232# Require C++14
188233if host_platform == "windows" and env ["platform" ] == "windows" and not env ["use_mingw" ]:
@@ -203,26 +248,27 @@ if env["platform"] == "linux" or env["platform"] == "freebsd":
203248 elif env ["target" ] == "release" :
204249 env .Append (CCFLAGS = ["-O3" ])
205250
206- if env ["bits " ] == "64 " :
251+ if env ["arch " ] == "x86_64 " :
207252 env .Append (CCFLAGS = ["-m64" ])
208253 env .Append (LINKFLAGS = ["-m64" ])
209- elif env ["bits " ] == "32 " :
254+ elif env ["arch " ] == "x86_32 " :
210255 env .Append (CCFLAGS = ["-m32" ])
211256 env .Append (LINKFLAGS = ["-m32" ])
212257
213258elif env ["platform" ] == "osx" :
214259 # Use Clang on macOS by default
215260 env ["CXX" ] = "clang++"
216261
217- if env ["bits" ] == "32" :
218- raise ValueError ("Only 64-bit builds are supported for the macOS target." )
262+ if env ["arch" ] not in ("universal" , "x86_64" , "arm64" ):
263+ print ("Only universal, x86_64, and arm64 are supported on macOS. Exiting." )
264+ Exit ()
219265
220- if env ["macos_arch " ] == "universal" :
266+ if env ["arch " ] == "universal" :
221267 env .Append (LINKFLAGS = ["-arch" , "x86_64" , "-arch" , "arm64" ])
222268 env .Append (CCFLAGS = ["-arch" , "x86_64" , "-arch" , "arm64" ])
223269 else :
224- env .Append (LINKFLAGS = ["-arch" , env ["macos_arch " ]])
225- env .Append (CCFLAGS = ["-arch" , env ["macos_arch " ]])
270+ env .Append (LINKFLAGS = ["-arch" , env ["arch " ]])
271+ env .Append (CCFLAGS = ["-arch" , env ["arch " ]])
226272
227273 if env ["macos_deployment_target" ] != "default" :
228274 env .Append (CCFLAGS = ["-mmacosx-version-min=" + env ["macos_deployment_target" ]])
@@ -289,12 +335,12 @@ elif env["platform"] == "windows":
289335
290336 elif host_platform == "linux" or host_platform == "freebsd" or host_platform == "osx" :
291337 # Cross-compilation using MinGW
292- if env ["bits " ] == "64 " :
338+ if env ["arch " ] == "x86_64 " :
293339 env ["CXX" ] = "x86_64-w64-mingw32-g++"
294340 env ["AR" ] = "x86_64-w64-mingw32-ar"
295341 env ["RANLIB" ] = "x86_64-w64-mingw32-ranlib"
296342 env ["LINK" ] = "x86_64-w64-mingw32-g++"
297- elif env ["bits " ] == "32 " :
343+ elif env ["arch " ] == "x86_32 " :
298344 env ["CXX" ] = "i686-w64-mingw32-g++"
299345 env ["AR" ] = "i686-w64-mingw32-ar"
300346 env ["RANLIB" ] = "i686-w64-mingw32-ranlib"
@@ -304,6 +350,7 @@ elif env["platform"] == "windows":
304350 # Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
305351 env = Environment (ENV = os .environ , tools = ["mingw" ])
306352 opts .Update (env )
353+ env ["arch" ] = env_arch
307354
308355 # Still need to use C++14.
309356 env .Append (CCFLAGS = ["-std=c++14" ])
@@ -332,6 +379,7 @@ elif env["platform"] == "android":
332379 # Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
333380 env = Environment (ENV = os .environ , tools = ["mingw" ])
334381 opts .Update (env )
382+ env ["arch" ] = env_arch
335383
336384 # Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
337385 env ["SPAWN" ] = mySpawn
@@ -423,6 +471,10 @@ elif env["platform"] == "android":
423471 env .Append (CCFLAGS = ["-O3" ])
424472
425473elif env ["platform" ] == "javascript" :
474+ if env ["arch" ] != "wasm32" :
475+ print ("Only the WebAssembly architecture (wasm32) is supported on the web. Exiting." )
476+ Exit ()
477+
426478 env ["ENV" ] = os .environ
427479 env ["CC" ] = "emcc"
428480 env ["CXX" ] = "em++"
@@ -487,18 +539,13 @@ sources = []
487539add_sources (sources , "src/core" , "cpp" )
488540sources .extend (f for f in bindings if str (f ).endswith (".cpp" ))
489541
490- arch_suffix = env ["bits " ]
542+ arch_suffix = env ["arch " ]
491543if env ["platform" ] == "android" :
492544 arch_suffix = env ["android_arch" ]
493545elif env ["platform" ] == "ios" :
494546 arch_suffix = env ["ios_arch" ]
495547 if env ["ios_simulator" ]:
496548 arch_suffix += ".simulator"
497- elif env ["platform" ] == "osx" :
498- if env ["macos_arch" ] != "universal" :
499- arch_suffix = env ["macos_arch" ]
500- elif env ["platform" ] == "javascript" :
501- arch_suffix = "wasm"
502549# Expose it to projects that import this env.
503550env ["arch_suffix" ] = arch_suffix
504551
0 commit comments