11#!/usr/bin/env python
22
33import os
4+ import platform
45import sys
56import subprocess
67
@@ -9,6 +10,7 @@ if sys.version_info < (3,):
910 def decode_utf8 (x ):
1011 return x
1112
13+
1214else :
1315 import codecs
1416
8183
8284env = Environment (ENV = os .environ )
8385
84- is64 = sys .maxsize > 2 ** 32
85- if (
86- env ["TARGET_ARCH" ] == "amd64"
87- or env ["TARGET_ARCH" ] == "emt64"
88- or env ["TARGET_ARCH" ] == "x86_64"
89- or env ["TARGET_ARCH" ] == "arm64-v8a"
90- ):
91- is64 = True
92-
9386opts = Variables ([], ARGUMENTS )
9487opts .Add (
9588 EnumVariable (
@@ -100,7 +93,6 @@ opts.Add(
10093 ignorecase = 2 ,
10194 )
10295)
103- opts .Add (EnumVariable ("bits" , "Target platform bits" , "64" if is64 else "32" , ("32" , "64" )))
10496opts .Add (BoolVariable ("use_llvm" , "Use the LLVM compiler - only effective when targeting Linux or FreeBSD" , False ))
10597opts .Add (BoolVariable ("use_mingw" , "Use the MinGW compiler instead of MSVC - only effective on Windows" , False ))
10698# Must be the same setting as used for cpp_bindings
@@ -123,18 +115,8 @@ opts.Add(
123115 ignorecase = 2 ,
124116 )
125117)
126- opts .Add (
127- EnumVariable (
128- "android_arch" ,
129- "Target Android architecture" ,
130- "armv7" ,
131- ["armv7" , "arm64v8" , "x86" , "x86_64" ],
132- )
133- )
134118opts .Add ("macos_deployment_target" , "macOS deployment target" , "default" )
135119opts .Add ("macos_sdk_path" , "macOS SDK path" , "" )
136- opts .Add (EnumVariable ("macos_arch" , "Target macOS architecture" , "universal" , ["universal" , "x86_64" , "arm64" ]))
137- opts .Add (EnumVariable ("ios_arch" , "Target iOS architecture" , "arm64" , ["armv7" , "arm64" , "x86_64" ]))
138120opts .Add (BoolVariable ("ios_simulator" , "Target iOS Simulator" , False ))
139121opts .Add (
140122 "IPHONEPATH" ,
@@ -144,7 +126,7 @@ opts.Add(
144126opts .Add (
145127 "android_api_level" ,
146128 "Target Android API level" ,
147- "18" if ARGUMENTS . get ( "android_arch" , "armv7" ) in [ "armv7 " , "x86" ] else "21" ,
129+ "18" if "32" in ARGUMENTS . get ( "arch " , "arm32" ) else "21" ,
148130)
149131opts .Add (
150132 "ANDROID_NDK_ROOT" ,
@@ -159,19 +141,64 @@ opts.Add(
159141 )
160142)
161143
144+ # CPU architecture options.
145+ architecture_array = ["" , "universal" , "x86_32" , "x86_64" , "arm32" , "arm64" , "rv64" , "ppc32" , "ppc64" , "wasm32" ]
146+ architecture_aliases = {
147+ "x64" : "x86_64" ,
148+ "amd64" : "x86_64" ,
149+ "armv7" : "arm32" ,
150+ "armv8" : "arm64" ,
151+ "arm64v8" : "arm64" ,
152+ "aarch64" : "arm64" ,
153+ "rv" : "rv64" ,
154+ "riscv" : "rv64" ,
155+ "riscv64" : "rv64" ,
156+ "ppcle" : "ppc32" ,
157+ "ppc" : "ppc32" ,
158+ "ppc64le" : "ppc64" ,
159+ }
160+ opts .Add (EnumVariable ("arch" , "CPU architecture" , "" , architecture_array , architecture_aliases ))
161+
162162opts .Update (env )
163163Help (opts .GenerateHelpText (env ))
164164
165+ # Process CPU architecture argument.
166+ if env ["arch" ] == "" :
167+ # No architecture specified. Default to universal if building for macOS,
168+ # arm64 if building for mobile, wasm32 if building for web,
169+ # otherwise default to the host architecture.
170+ if env ["platform" ] == "osx" :
171+ env ["arch" ] = "universal"
172+ elif env ["platform" ] in ["android" , "ios" ]:
173+ env ["arch" ] = "arm64"
174+ elif env ["platform" ] == "javascript" :
175+ env ["arch" ] = "wasm32"
176+ else :
177+ host_machine = platform .machine ().lower ()
178+ if host_machine in architecture_array :
179+ env ["arch" ] = host_machine
180+ elif host_machine in architecture_aliases .keys ():
181+ env ["arch" ] = architecture_aliases [host_machine ]
182+ elif "86" in host_machine :
183+ # Catches x86, i386, i486, i586, i686, etc.
184+ env ["arch" ] = "x86_32"
185+ else :
186+ print ("Unsupported CPU architecture: " + host_machine )
187+ Exit ()
188+
189+ env_arch = env ["arch" ]
190+
165191# This makes sure to keep the session environment variables on Windows.
166192# This way, you can run SCons in a Visual Studio 2017 prompt and it will find
167193# all the required tools
168194if host_platform == "windows" and env ["platform" ] != "android" :
169- if env ["bits " ] == "64 " :
195+ if env ["arch " ] == "x86_64 " :
170196 env = Environment (TARGET_ARCH = "amd64" )
171- elif env ["bits " ] == "32 " :
197+ elif env ["arch " ] == "x86_32 " :
172198 env = Environment (TARGET_ARCH = "x86" )
173199
174200 opts .Update (env )
201+ env ["arch" ] = env_arch
175202
176203if env ["platform" ] == "linux" or env ["platform" ] == "freebsd" :
177204 if env ["use_llvm" ]:
@@ -185,26 +212,33 @@ if env["platform"] == "linux" or env["platform"] == "freebsd":
185212 elif env ["target" ] == "release" :
186213 env .Append (CCFLAGS = ["-O3" ])
187214
188- if env ["bits" ] == "64" :
189- env .Append (CCFLAGS = ["-m64" ])
190- env .Append (LINKFLAGS = ["-m64" ])
191- elif env ["bits" ] == "32" :
192- env .Append (CCFLAGS = ["-m32" ])
193- env .Append (LINKFLAGS = ["-m32" ])
215+ if env_arch == "x86_64" :
216+ env .Append (CCFLAGS = ["-m64" , "-march=x86-64" ])
217+ env .Append (LINKFLAGS = ["-m64" , "-march=x86-64" ])
218+ elif env_arch == "x86_32" :
219+ env .Append (CCFLAGS = ["-m32" , "-march=i686" ])
220+ env .Append (LINKFLAGS = ["-m32" , "-march=i686" ])
221+ elif env_arch == "arm64" :
222+ env .Append (CCFLAGS = ["-march=armv8-a" ])
223+ env .Append (LINKFLAGS = ["-march=armv8-a" ])
224+ elif env_arch == "rv64" :
225+ env .Append (CCFLAGS = ["-march=rv64gc" ])
226+ env .Append (LINKFLAGS = ["-march=rv64gc" ])
194227
195228elif env ["platform" ] == "osx" :
196229 # Use Clang on macOS by default
197230 env ["CXX" ] = "clang++"
198231
199- if env ["bits" ] == "32" :
200- raise ValueError ("Only 64-bit builds are supported for the macOS target." )
232+ if env ["arch" ] not in ("universal" , "x86_64" , "arm64" ):
233+ print ("Only universal, x86_64, and arm64 are supported on macOS. Exiting." )
234+ Exit ()
201235
202- if env ["macos_arch " ] == "universal" :
236+ if env ["arch " ] == "universal" :
203237 env .Append (LINKFLAGS = ["-arch" , "x86_64" , "-arch" , "arm64" ])
204238 env .Append (CCFLAGS = ["-arch" , "x86_64" , "-arch" , "arm64" ])
205239 else :
206- env .Append (LINKFLAGS = ["-arch" , env ["macos_arch " ]])
207- env .Append (CCFLAGS = ["-arch" , env ["macos_arch " ]])
240+ env .Append (LINKFLAGS = ["-arch" , env ["arch " ]])
241+ env .Append (CCFLAGS = ["-arch" , env ["arch " ]])
208242
209243 env .Append (CCFLAGS = ["-std=c++14" ])
210244
@@ -251,11 +285,15 @@ elif env["platform"] == "ios":
251285 env ["AR" ] = compiler_path + "ar"
252286 env ["RANLIB" ] = compiler_path + "ranlib"
253287
254- env .Append (CCFLAGS = ["-std=c++14" , "-arch" , env ["ios_arch" ], "-isysroot" , sdk_path ])
288+ if env ["arch" ] == "arm32" :
289+ env .Append (CCFLAGS = ["-arch" , "armv7" ])
290+ env .Append (LINKFLAGS = ["-arch" , "armv7" ])
291+ else :
292+ env .Append (CCFLAGS = ["-arch" , env ["arch" ]])
293+ env .Append (LINKFLAGS = ["-arch" , env ["arch" ]])
294+ env .Append (CCFLAGS = ["-std=c++14" , "-isysroot" , sdk_path ])
255295 env .Append (
256296 LINKFLAGS = [
257- "-arch" ,
258- env ["ios_arch" ],
259297 "-framework" ,
260298 "Cocoa" ,
261299 "-Wl,-undefined,dynamic_lookup" ,
@@ -281,12 +319,12 @@ elif env["platform"] == "windows":
281319
282320 elif host_platform == "linux" or host_platform == "freebsd" or host_platform == "osx" :
283321 # Cross-compilation using MinGW
284- if env ["bits " ] == "64 " :
322+ if env ["arch " ] == "x86_64 " :
285323 env ["CXX" ] = "x86_64-w64-mingw32-g++"
286324 env ["AR" ] = "x86_64-w64-mingw32-ar"
287325 env ["RANLIB" ] = "x86_64-w64-mingw32-ranlib"
288326 env ["LINK" ] = "x86_64-w64-mingw32-g++"
289- elif env ["bits " ] == "32 " :
327+ elif env ["arch " ] == "x86_32 " :
290328 env ["CXX" ] = "i686-w64-mingw32-g++"
291329 env ["AR" ] = "i686-w64-mingw32-ar"
292330 env ["RANLIB" ] = "i686-w64-mingw32-ranlib"
@@ -296,6 +334,7 @@ elif env["platform"] == "windows":
296334 # Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
297335 env = Environment (ENV = os .environ , tools = ["mingw" ])
298336 opts .Update (env )
337+ env ["arch" ] = env_arch
299338 # env = env.Clone(tools=['mingw'])
300339
301340 env ["SPAWN" ] = mySpawn
@@ -318,6 +357,7 @@ elif env["platform"] == "android":
318357 # Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
319358 env = Environment (ENV = os .environ , tools = ["mingw" ])
320359 opts .Update (env )
360+ env ["arch" ] = env_arch
321361 # env = env.Clone(tools=['mingw'])
322362
323363 env ["SPAWN" ] = mySpawn
@@ -330,7 +370,7 @@ elif env["platform"] == "android":
330370
331371 # Validate API level
332372 api_level = int (env ["android_api_level" ])
333- if env [ "android_arch" ] in [ "x86_64" , "arm64v8 " ] and api_level < 21 :
373+ if "64" in env [ "arch " ] and api_level < 21 :
334374 print ("WARN: 64-bit Android architectures require an API level of at least 21; setting android_api_level=21" )
335375 env ["android_api_level" ] = "21"
336376 api_level = 21
@@ -339,9 +379,7 @@ elif env["platform"] == "android":
339379 toolchain = env ["ANDROID_NDK_ROOT" ] + "/toolchains/llvm/prebuilt/"
340380 if host_platform == "windows" :
341381 toolchain += "windows"
342- import platform as pltfm
343-
344- if pltfm .machine ().endswith ("64" ):
382+ if platform .machine ().endswith ("64" ):
345383 toolchain += "-x86_64"
346384 elif host_platform == "linux" :
347385 toolchain += "linux-x86_64"
@@ -351,21 +389,21 @@ elif env["platform"] == "android":
351389
352390 # Get architecture info
353391 arch_info_table = {
354- "armv7 " : {
392+ "arm32 " : {
355393 "march" : "armv7-a" ,
356394 "target" : "armv7a-linux-androideabi" ,
357395 "tool_path" : "arm-linux-androideabi" ,
358396 "compiler_path" : "armv7a-linux-androideabi" ,
359397 "ccflags" : ["-mfpu=neon" ],
360398 },
361- "arm64v8 " : {
399+ "arm64 " : {
362400 "march" : "armv8-a" ,
363401 "target" : "aarch64-linux-android" ,
364402 "tool_path" : "aarch64-linux-android" ,
365403 "compiler_path" : "aarch64-linux-android" ,
366404 "ccflags" : [],
367405 },
368- "x86 " : {
406+ "x86_32 " : {
369407 "march" : "i686" ,
370408 "target" : "i686-linux-android" ,
371409 "tool_path" : "i686-linux-android" ,
@@ -380,7 +418,7 @@ elif env["platform"] == "android":
380418 "ccflags" : [],
381419 },
382420 }
383- arch_info = arch_info_table [env ["android_arch " ]]
421+ arch_info = arch_info_table [env ["arch " ]]
384422
385423 # Setup tools
386424 env ["CC" ] = toolchain + "/bin/clang"
@@ -406,6 +444,7 @@ elif env["platform"] == "android":
406444 env .Append (CCFLAGS = ["-O3" ])
407445
408446elif env ["platform" ] == "javascript" :
447+ env ["arch" ] = "wasm32"
409448 env ["ENV" ] = os .environ
410449 env ["CC" ] = "emcc"
411450 env ["CXX" ] = "em++"
@@ -414,7 +453,7 @@ elif env["platform"] == "javascript":
414453 env .Append (CPPFLAGS = ["-s" , "SIDE_MODULE=1" ])
415454 env .Append (LINKFLAGS = ["-s" , "SIDE_MODULE=1" ])
416455 env ["SHOBJSUFFIX" ] = ".bc"
417- env ["SHLIBSUFFIX" ] = ".wasm "
456+ env ["SHLIBSUFFIX" ] = ".wasm32 "
418457 # Use TempFileMunge since some AR invocations are too long for cmd.exe.
419458 # Use POSIX-style paths, required with TempFileMunge.
420459 env ["ARCOM_POSIX" ] = env ["ARCOM" ].replace ("$TARGET" , "$TARGET.posix" ).replace ("$SOURCES" , "$SOURCES.posix" )
@@ -473,16 +512,7 @@ sources = []
473512add_sources (sources , "src/core" , "cpp" )
474513add_sources (sources , "src/gen" , "cpp" )
475514
476- arch_suffix = env ["bits" ]
477- if env ["platform" ] == "android" :
478- arch_suffix = env ["android_arch" ]
479- elif env ["platform" ] == "ios" :
480- arch_suffix = env ["ios_arch" ]
481- elif env ["platform" ] == "osx" :
482- if env ["macos_arch" ] != "universal" :
483- arch_suffix = env ["macos_arch" ]
484- elif env ["platform" ] == "javascript" :
485- arch_suffix = "wasm"
515+ arch_suffix = env ["arch" ]
486516
487517library = env .StaticLibrary (
488518 target = "bin/" + "libgodot-cpp.{}.{}.{}{}" .format (env ["platform" ], env ["target" ], arch_suffix , env ["LIBSUFFIX" ]),
0 commit comments