Skip to content

Commit

Permalink
Unify bits, macos_arch into arch, support non-x86 Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfranke committed Sep 8, 2022
1 parent 97c181a commit 4f2e4dd
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 37 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@ 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
artifact-path: bin/libgodot-cpp.linux.release.x86_64.a
godot_zip: Godot_v3.5-stable_linux_server.64.zip
executable: Godot_v3.5-stable_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
artifact-path: bin/libgodot-cpp.osx.release.universal.a
flags: macos_arch=universal
godot_zip: Godot_v3.5-stable_osx.universal.zip
executable: Godot.app/Contents/MacOS/Godot
Expand Down
81 changes: 53 additions & 28 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

import os
import platform
import sys
import subprocess

Expand Down Expand Up @@ -100,15 +101,6 @@ if hasattr(os, "cpu_count") and env.GetOption("num_jobs") == altered_num_jobs:
)
env.SetOption("num_jobs", safer_cpu_count)

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(
Expand All @@ -119,7 +111,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
Expand Down Expand Up @@ -152,7 +143,6 @@ opts.Add(
)
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(
Expand Down Expand Up @@ -180,6 +170,44 @@ opts.Add(

opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True))

# CPU architecture options.
architectures = ["universal", "x86_32", "x86_64", "arm32", "arm64", "rv64", "ppc32", "ppc64", "wasm32"]
architecture_aliases = {
"x86": "x86_32",
"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",
}


def detect_arch():
host_machine = platform.machine().lower()
if host_platform == "osx":
return "universal"
if host_machine in architectures:
return host_machine
elif host_machine in architecture_aliases.keys():
return architecture_aliases[host_machine]
elif "86" in host_machine:
# Catches x86, i386, i486, i586, i686, etc.
return "x86_32"
else:
print("Unsupported CPU architecture: " + host_machine)
print("Falling back to x86_64.")
return "x86_64"


opts.Add(EnumVariable("arch", "CPU architecture", detect_arch(), architectures, architecture_aliases))

opts.Update(env)
Help(opts.GenerateHelpText(env))

Expand All @@ -194,9 +222,9 @@ if unknown:
# 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)
Expand All @@ -220,26 +248,27 @@ if env["platform"] == "linux" or env["platform"] == "freebsd":
elif env["target"] == "release":
env.Append(CCFLAGS=["-O3"])

if env["bits"] == "64":
if env["arch"] == "x86_64":
env.Append(CCFLAGS=["-m64"])
env.Append(LINKFLAGS=["-m64"])
elif env["bits"] == "32":
elif env["arch"] == "x86_32":
env.Append(CCFLAGS=["-m32"])
env.Append(LINKFLAGS=["-m32"])

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"]])
Expand Down Expand Up @@ -306,12 +335,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"
Expand Down Expand Up @@ -440,6 +469,7 @@ elif env["platform"] == "android":
env.Append(CCFLAGS=["-O3"])

elif env["platform"] == "javascript":
env["arch"] = "wasm32"
env["ENV"] = os.environ
env["CC"] = "emcc"
env["CXX"] = "em++"
Expand Down Expand Up @@ -507,18 +537,13 @@ sources = []
add_sources(sources, "src/core", "cpp")
add_sources(sources, "src/gen", "cpp")

arch_suffix = env["bits"]
arch_suffix = env["arch"]
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"
# Expose it to projects that import this env.
env["arch_suffix"] = arch_suffix

Expand Down
8 changes: 4 additions & 4 deletions test/gdexample.gdnlib
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit 4f2e4dd

Please sign in to comment.