diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7ff1fb9ff..1d7f4294c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,48 +9,49 @@ jobs: fail-fast: false matrix: include: - - name: 🐧 Linux (GCC) + - name: 🐧 Linux (x86_64, GCC) os: ubuntu-18.04 platform: linux artifact-name: godot-cpp-linux-glibc2.27-x86_64-release - artifact-path: bin/libgodot-cpp.linux.release.64.a - godot_zip: Godot_v3.4-stable_linux_server.64.zip - executable: Godot_v3.4-stable_linux_server.64 + artifact-path: bin/libgodot-cpp.linux.release.x86_64.a + godot_zip: Godot_v3.5-rc4_linux_server.64.zip + executable: Godot_v3.5-rc4_linux_server.64 - name: 🏁 Windows (x86_64, MSVC) os: windows-2019 platform: windows artifact-name: godot-cpp-windows-msvc2019-x86_64-release - artifact-path: bin/libgodot-cpp.windows.release.64.lib + artifact-path: bin/libgodot-cpp.windows.release.x86_64.lib - name: 🏁 Windows (x86_64, MinGW) os: windows-2019 platform: windows artifact-name: godot-cpp-linux-mingw-x86_64-release - artifact-path: bin/libgodot-cpp.windows.release.64.a + artifact-path: bin/libgodot-cpp.windows.release.x86_64.a flags: use_mingw=yes - name: 🍎 macOS (universal) os: macos-11 platform: osx artifact-name: godot-cpp-macos-universal-release - artifact-path: bin/libgodot-cpp.osx.release.64.a - flags: macos_arch=universal - godot_zip: Godot_v3.4-stable_osx.universal.zip + artifact-path: bin/libgodot-cpp.osx.release.universal.a + flags: arch=universal + godot_zip: Godot_v3.5-rc4_osx.universal.zip executable: Godot.app/Contents/MacOS/Godot - name: 🤖 Android (arm64) os: ubuntu-18.04 platform: android artifact-name: godot-cpp-android-arm64-release - artifact-path: bin/libgodot-cpp.android.release.arm64v8.a - flags: android_arch=arm64v8 + artifact-path: bin/libgodot-cpp.android.release.arm64.a + flags: arch=arm64 - name: 🍏 iOS (arm64) os: macos-11 platform: ios artifact-name: godot-cpp-ios-arm64-release artifact-path: bin/libgodot-cpp.ios.release.arm64.a + flags: arch=arm64 steps: - name: Checkout @@ -94,7 +95,7 @@ jobs: - name: Run test GDNative library if: ${{ matrix.platform == 'linux' || matrix.platform == 'osx' }} run: | - curl -LO https://downloads.tuxfamily.org/godotengine/3.4/${{ matrix.godot_zip }} + curl -LO https://downloads.tuxfamily.org/godotengine/3.5/rc4/${{ matrix.godot_zip }} unzip ${{ matrix.godot_zip }} ./${{ matrix.executable }} --path test -s script.gd diff --git a/SConstruct b/SConstruct index 8343fa0fd8..5866bf423a 100644 --- a/SConstruct +++ b/SConstruct @@ -1,6 +1,7 @@ #!/usr/bin/env python import os +import platform import sys import subprocess @@ -9,6 +10,7 @@ if sys.version_info < (3,): def decode_utf8(x): return x + else: import codecs @@ -81,15 +83,6 @@ else: env = Environment(ENV=os.environ) -is64 = sys.maxsize > 2 ** 32 -if ( - env["TARGET_ARCH"] == "amd64" - or env["TARGET_ARCH"] == "emt64" - or env["TARGET_ARCH"] == "x86_64" - or env["TARGET_ARCH"] == "arm64-v8a" -): - is64 = True - opts = Variables([], ARGUMENTS) opts.Add( EnumVariable( @@ -100,7 +93,6 @@ opts.Add( ignorecase=2, ) ) -opts.Add(EnumVariable("bits", "Target platform bits", "64" if is64 else "32", ("32", "64"))) opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler - only effective when targeting Linux or FreeBSD", False)) opts.Add(BoolVariable("use_mingw", "Use the MinGW compiler instead of MSVC - only effective on Windows", False)) # Must be the same setting as used for cpp_bindings @@ -123,18 +115,8 @@ opts.Add( ignorecase=2, ) ) -opts.Add( - EnumVariable( - "android_arch", - "Target Android architecture", - "armv7", - ["armv7", "arm64v8", "x86", "x86_64"], - ) -) opts.Add("macos_deployment_target", "macOS deployment target", "default") opts.Add("macos_sdk_path", "macOS SDK path", "") -opts.Add(EnumVariable("macos_arch", "Target macOS architecture", "universal", ["universal", "x86_64", "arm64"])) -opts.Add(EnumVariable("ios_arch", "Target iOS architecture", "arm64", ["armv7", "arm64", "x86_64"])) opts.Add(BoolVariable("ios_simulator", "Target iOS Simulator", False)) opts.Add( "IPHONEPATH", @@ -144,7 +126,7 @@ opts.Add( opts.Add( "android_api_level", "Target Android API level", - "18" if ARGUMENTS.get("android_arch", "armv7") in ["armv7", "x86"] else "21", + "18" if "32" in ARGUMENTS.get("arch", "arm32") else "21", ) opts.Add( "ANDROID_NDK_ROOT", @@ -161,19 +143,64 @@ opts.Add( opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True)) +# CPU architecture options. +architecture_array = ["", "universal", "x86_32", "x86_64", "arm32", "arm64", "rv64", "ppc32", "ppc64", "wasm32"] +architecture_aliases = { + "x64": "x86_64", + "amd64": "x86_64", + "armv7": "arm32", + "armv8": "arm64", + "arm64v8": "arm64", + "aarch64": "arm64", + "rv": "rv64", + "riscv": "rv64", + "riscv64": "rv64", + "ppcle": "ppc32", + "ppc": "ppc32", + "ppc64le": "ppc64", +} +opts.Add(EnumVariable("arch", "CPU architecture", "", architecture_array, architecture_aliases)) + opts.Update(env) Help(opts.GenerateHelpText(env)) +# Process CPU architecture argument. +if env["arch"] == "": + # No architecture specified. Default to arm64 if building for Android, + # universal if building for macOS or iOS, wasm32 if building for web, + # otherwise default to the host architecture. + if env["platform"] in ["osx", "ios"]: + env["arch"] = "universal" + elif env["platform"] == "android": + env["arch"] = "arm64" + elif env["platform"] == "javascript": + env["arch"] = "wasm32" + else: + host_machine = platform.machine().lower() + if host_machine in architecture_array: + env["arch"] = host_machine + elif host_machine in architecture_aliases.keys(): + env["arch"] = architecture_aliases[host_machine] + elif "86" in host_machine: + # Catches x86, i386, i486, i586, i686, etc. + env["arch"] = "x86_32" + else: + print("Unsupported CPU architecture: " + host_machine) + Exit() + +env_arch = env["arch"] + # This makes sure to keep the session environment variables on Windows. # This way, you can run SCons in a Visual Studio 2017 prompt and it will find # all the required tools if host_platform == "windows" and env["platform"] != "android": - if env["bits"] == "64": + if env["arch"] == "x86_64": env = Environment(TARGET_ARCH="amd64") - elif env["bits"] == "32": + elif env["arch"] == "x86_32": env = Environment(TARGET_ARCH="x86") opts.Update(env) + env["arch"] = env_arch # Require C++14 if host_platform == "windows" and env["platform"] == "windows" and not env["use_mingw"]: @@ -194,26 +221,33 @@ if env["platform"] == "linux" or env["platform"] == "freebsd": elif env["target"] == "release": env.Append(CCFLAGS=["-O3"]) - if env["bits"] == "64": - env.Append(CCFLAGS=["-m64"]) - env.Append(LINKFLAGS=["-m64"]) - elif env["bits"] == "32": - env.Append(CCFLAGS=["-m32"]) - env.Append(LINKFLAGS=["-m32"]) + if env_arch == "x86_64": + env.Append(CCFLAGS=["-m64", "-march=x86-64"]) + env.Append(LINKFLAGS=["-m64", "-march=x86-64"]) + elif env_arch == "x86_32": + env.Append(CCFLAGS=["-m32", "-march=i686"]) + env.Append(LINKFLAGS=["-m32", "-march=i686"]) + elif env_arch == "arm64": + env.Append(CCFLAGS=["-march=armv8-a"]) + env.Append(LINKFLAGS=["-march=armv8-a"]) + elif env_arch == "rv64": + env.Append(CCFLAGS=["-march=rv64gc"]) + env.Append(LINKFLAGS=["-march=rv64gc"]) elif env["platform"] == "osx": # Use Clang on macOS by default env["CXX"] = "clang++" - if env["bits"] == "32": - raise ValueError("Only 64-bit builds are supported for the macOS target.") + if env["arch"] not in ("universal", "x86_64", "arm64"): + print("Only universal, x86_64, and arm64 are supported on macOS. Exiting.") + Exit() - if env["macos_arch"] == "universal": + if env["arch"] == "universal": env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"]) env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"]) else: - env.Append(LINKFLAGS=["-arch", env["macos_arch"]]) - env.Append(CCFLAGS=["-arch", env["macos_arch"]]) + env.Append(LINKFLAGS=["-arch", env["arch"]]) + env.Append(CCFLAGS=["-arch", env["arch"]]) if env["macos_deployment_target"] != "default": env.Append(CCFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]]) @@ -252,11 +286,22 @@ elif env["platform"] == "ios": env["RANLIB"] = compiler_path + "ranlib" env["SHLIBSUFFIX"] = ".dylib" - env.Append(CCFLAGS=["-arch", env["ios_arch"], "-isysroot", sdk_path]) + if env["arch"] == "universal": + if env["ios_simulator"]: + env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"]) + env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"]) + else: + env.Append(CCFLAGS=["-arch", "armv7", "-arch", "arm64"]) + env.Append(LINKFLAGS=["-arch", "armv7", "-arch", "arm64"]) + elif env["arch"] == "arm32": + env.Append(CCFLAGS=["-arch", "armv7"]) + env.Append(LINKFLAGS=["-arch", "armv7"]) + else: + env.Append(CCFLAGS=["-arch", env["arch"]]) + env.Append(LINKFLAGS=["-arch", env["arch"]]) + env.Append(CCFLAGS=["-isysroot", sdk_path]) env.Append( LINKFLAGS=[ - "-arch", - env["ios_arch"], "-Wl,-undefined,dynamic_lookup", "-isysroot", sdk_path, @@ -280,12 +325,12 @@ elif env["platform"] == "windows": elif host_platform == "linux" or host_platform == "freebsd" or host_platform == "osx": # Cross-compilation using MinGW - if env["bits"] == "64": + if env["arch"] == "x86_64": env["CXX"] = "x86_64-w64-mingw32-g++" env["AR"] = "x86_64-w64-mingw32-ar" env["RANLIB"] = "x86_64-w64-mingw32-ranlib" env["LINK"] = "x86_64-w64-mingw32-g++" - elif env["bits"] == "32": + elif env["arch"] == "x86_32": env["CXX"] = "i686-w64-mingw32-g++" env["AR"] = "i686-w64-mingw32-ar" env["RANLIB"] = "i686-w64-mingw32-ranlib" @@ -295,6 +340,7 @@ elif env["platform"] == "windows": # Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff. env = Environment(ENV=os.environ, tools=["mingw"]) opts.Update(env) + env["arch"] = env_arch # Still need to use C++14. env.Append(CCFLAGS=["-std=c++14"]) @@ -323,6 +369,7 @@ elif env["platform"] == "android": # Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff. env = Environment(ENV=os.environ, tools=["mingw"]) opts.Update(env) + env["arch"] = env_arch # Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other). env["SPAWN"] = mySpawn @@ -336,7 +383,7 @@ elif env["platform"] == "android": # Validate API level api_level = int(env["android_api_level"]) - if env["android_arch"] in ["x86_64", "arm64v8"] and api_level < 21: + if "64" in env["arch"] and api_level < 21: print("WARN: 64-bit Android architectures require an API level of at least 21; setting android_api_level=21") env["android_api_level"] = "21" api_level = 21 @@ -345,9 +392,7 @@ elif env["platform"] == "android": toolchain = env["ANDROID_NDK_ROOT"] + "/toolchains/llvm/prebuilt/" if host_platform == "windows": toolchain += "windows" - import platform as pltfm - - if pltfm.machine().endswith("64"): + if platform.machine().endswith("64"): toolchain += "-x86_64" elif host_platform == "linux": toolchain += "linux-x86_64" @@ -357,21 +402,21 @@ elif env["platform"] == "android": # Get architecture info arch_info_table = { - "armv7": { + "arm32": { "march": "armv7-a", "target": "armv7a-linux-androideabi", "tool_path": "arm-linux-androideabi", "compiler_path": "armv7a-linux-androideabi", "ccflags": ["-mfpu=neon"], }, - "arm64v8": { + "arm64": { "march": "armv8-a", "target": "aarch64-linux-android", "tool_path": "aarch64-linux-android", "compiler_path": "aarch64-linux-android", "ccflags": [], }, - "x86": { + "x86_32": { "march": "i686", "target": "i686-linux-android", "tool_path": "i686-linux-android", @@ -386,7 +431,7 @@ elif env["platform"] == "android": "ccflags": [], }, } - arch_info = arch_info_table[env["android_arch"]] + arch_info = arch_info_table[env["arch"]] # Setup tools env["CC"] = toolchain + "/bin/clang" @@ -414,6 +459,10 @@ elif env["platform"] == "android": env.Append(CCFLAGS=["-O3"]) elif env["platform"] == "javascript": + if env["arch"] != "wasm32": + print("Only the WebAssembly architecture is supported on the web. Exiting.") + Exit() + env["ENV"] = os.environ env["CC"] = "emcc" env["CXX"] = "em++" @@ -481,18 +530,9 @@ sources = [] add_sources(sources, "src/core", "cpp") add_sources(sources, "src/gen", "cpp") -arch_suffix = env["bits"] -if env["platform"] == "android": - arch_suffix = env["android_arch"] -elif env["platform"] == "ios": - arch_suffix = env["ios_arch"] - if env["ios_simulator"]: - arch_suffix += ".simulator" -elif env["platform"] == "osx": - if env["macos_arch"] != "universal": - arch_suffix = env["macos_arch"] -elif env["platform"] == "javascript": - arch_suffix = "wasm" +arch_suffix = env["arch"] +if env["ios_simulator"]: + arch_suffix += ".simulator" # Expose it to projects that import this env. env["arch_suffix"] = arch_suffix diff --git a/test/gdexample.gdnlib b/test/gdexample.gdnlib index 9744b98e0a..52e580be1d 100644 --- a/test/gdexample.gdnlib +++ b/test/gdexample.gdnlib @@ -7,10 +7,10 @@ reloadable=false [entry] -X11.64="res://bin/libgdexample.linux.release.64.so" -Server.64="res://bin/libgdexample.linux.release.64.so" -Windows.64="res://bin/libgdexample.windows.release.64.dll" -OSX.64="res://bin/libgdexample.osx.release.64.dylib" +X11.64="res://bin/libgdexample.linux.release.x86_64.so" +Server.64="res://bin/libgdexample.linux.release.x86_64.so" +Windows.64="res://bin/libgdexample.windows.release.x86_64.dll" +OSX.64="res://bin/libgdexample.osx.release.universal.dylib" [dependencies]