From 6d195137fe21d6169bc43a928141c006efc7c1f2 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Sun, 23 Jul 2023 22:41:55 +0200 Subject: [PATCH] [SCons] Merge OSXCross tools into platofrm ones --- tools/ios.py | 35 +++++++++++++++++++++++++++++------ tools/ios_osxcross.py | 26 -------------------------- tools/macos.py | 30 +++++++++++++++++++++++++----- tools/macos_osxcross.py | 28 ---------------------------- 4 files changed, 54 insertions(+), 65 deletions(-) delete mode 100644 tools/ios_osxcross.py delete mode 100644 tools/macos_osxcross.py diff --git a/tools/ios.py b/tools/ios.py index 11d606b9..4a644f94 100644 --- a/tools/ios.py +++ b/tools/ios.py @@ -1,7 +1,6 @@ import os import sys import subprocess -import ios_osxcross from SCons.Variables import * if sys.version_info < (3,): @@ -16,6 +15,10 @@ else: return codecs.utf_8_decode(x)[0] +def has_ios_osxcross(): + return "OSXCROSS_IOS" in os.environ + + def options(opts): opts.Add(BoolVariable("ios_simulator", "Target iOS Simulator", False)) opts.Add("ios_min_version", "Target minimum iphoneos/iphonesimulator version", "10.0") @@ -25,17 +28,18 @@ def options(opts): "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain", ) opts.Add("IOS_SDK_PATH", "Path to the iOS SDK", "") - ios_osxcross.options(opts) + + if has_ios_osxcross(): + opts.Add("ios_triple", "Triple for ios toolchain", "") def exists(env): - return sys.platform == "darwin" or ios_osxcross.exists(env) + return sys.platform == "darwin" or has_ios_osxcross() def generate(env): if env["arch"] not in ("universal", "arm64", "x86_64"): - print("Only universal, arm64, and x86_64 are supported on iOS. Exiting.") - Exit() + raise ValueError("Only universal, arm64, and x86_64 are supported on iOS. Exiting.") if env["ios_simulator"]: sdk_name = "iphonesimulator" @@ -64,7 +68,26 @@ def generate(env): env["ENV"]["PATH"] = env["IOS_TOOLCHAIN_PATH"] + "/Developer/usr/bin/:" + env["ENV"]["PATH"] else: - ios_osxcross.generate(env) + # OSXCross + compiler_path = "$IOS_TOOLCHAIN_PATH/usr/bin/${ios_triple}" + env["CC"] = compiler_path + "clang" + env["CXX"] = compiler_path + "clang++" + env["AR"] = compiler_path + "ar" + env["RANLIB"] = compiler_path + "ranlib" + env["SHLIBSUFFIX"] = ".dylib" + + env.Prepend( + CPPPATH=[ + "$IOS_SDK_PATH/usr/include", + "$IOS_SDK_PATH/System/Library/Frameworks/AudioUnit.framework/Headers", + ] + ) + + env.Append(CCFLAGS=["-stdlib=libc++"]) + + binpath = os.path.join(env["IOS_TOOLCHAIN_PATH"], "usr", "bin") + if binpath not in env["ENV"]["PATH"]: + env.PrependENVPath("PATH", binpath) if env["arch"] == "universal": if env["ios_simulator"]: diff --git a/tools/ios_osxcross.py b/tools/ios_osxcross.py deleted file mode 100644 index 21a3f5e4..00000000 --- a/tools/ios_osxcross.py +++ /dev/null @@ -1,26 +0,0 @@ -import os - - -def options(opts): - opts.Add("ios_triple", "Triple for ios toolchain", "") - - -def exists(env): - return "OSXCROSS_IOS" in os.environ - - -def generate(env): - compiler_path = "$IOS_TOOLCHAIN_PATH/usr/bin/${ios_triple}" - env["CC"] = compiler_path + "clang" - env["CXX"] = compiler_path + "clang++" - env["AR"] = compiler_path + "ar" - env["RANLIB"] = compiler_path + "ranlib" - env["SHLIBSUFFIX"] = ".dylib" - - env.Prepend( - CPPPATH=[ - "$IOS_SDK_PATH/usr/include", - "$IOS_SDK_PATH/System/Library/Frameworks/AudioUnit.framework/Headers", - ] - ) - env.Append(CCFLAGS=["-stdlib=libc++"]) diff --git a/tools/macos.py b/tools/macos.py index 2e4bfc68..71eae1b1 100644 --- a/tools/macos.py +++ b/tools/macos.py @@ -1,16 +1,20 @@ import os import sys -import macos_osxcross + + +def has_osxcross(): + return "OSXCROSS_ROOT" in os.environ def options(opts): opts.Add("macos_deployment_target", "macOS deployment target", "default") opts.Add("macos_sdk_path", "macOS SDK path", "") - macos_osxcross.options(opts) + if has_osxcross(): + opts.Add("osxcross_sdk", "OSXCross SDK version", "darwin16") def exists(env): - return sys.platform == "darwin" or macos_osxcross.exists(env) + return sys.platform == "darwin" or has_osxcross() def generate(env): @@ -23,9 +27,25 @@ def generate(env): env["CXX"] = "clang++" env["CC"] = "clang" else: - # Use osxcross - macos_osxcross.generate(env) + # OSXCross + root = os.environ.get("OSXCROSS_ROOT", "") + if env["arch"] == "arm64": + basecmd = root + "/target/bin/arm64-apple-" + env["osxcross_sdk"] + "-" + else: + basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-" + env["CC"] = basecmd + "clang" + env["CXX"] = basecmd + "clang++" + env["AR"] = basecmd + "ar" + env["RANLIB"] = basecmd + "ranlib" + env["AS"] = basecmd + "as" + + binpath = os.path.join(root, "target", "bin") + if binpath not in env["ENV"]["PATH"]: + # Add OSXCROSS bin folder to PATH (required for linking). + env.PrependENVPath("PATH", binpath) + + # Common flags if env["arch"] == "universal": env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"]) env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"]) diff --git a/tools/macos_osxcross.py b/tools/macos_osxcross.py deleted file mode 100644 index f11166d1..00000000 --- a/tools/macos_osxcross.py +++ /dev/null @@ -1,28 +0,0 @@ -import os - - -def options(opts): - opts.Add("osxcross_sdk", "OSXCross SDK version", "darwin16") - - -def exists(env): - return "OSXCROSS_ROOT" in os.environ - - -def generate(env): - root = os.environ.get("OSXCROSS_ROOT", "") - if env["arch"] == "arm64": - basecmd = root + "/target/bin/arm64-apple-" + env["osxcross_sdk"] + "-" - else: - basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-" - - env["CC"] = basecmd + "clang" - env["CXX"] = basecmd + "clang++" - env["AR"] = basecmd + "ar" - env["RANLIB"] = basecmd + "ranlib" - env["AS"] = basecmd + "as" - - binpath = os.path.join(root, "target", "bin") - if binpath not in env["ENV"]["PATH"]: - # Add OSXCROSS bin folder to PATH (required for linking). - env["ENV"]["PATH"] = "%s:%s" % (binpath, env["ENV"]["PATH"])