diff --git a/scripts/mk_unix_dist.py b/scripts/mk_unix_dist.py index d967e9109..7aebb6750 100644 --- a/scripts/mk_unix_dist.py +++ b/scripts/mk_unix_dist.py @@ -29,6 +29,7 @@ GIT_HASH=False PYTHON_ENABLED=True MAKEJOBS=getenv("MAKEJOBS", '8') OS_NAME=None +LINUX_X64=mk_util.LINUX_X64 def set_verbose(flag): global VERBOSE @@ -57,7 +58,7 @@ def display_help(): print(" -f, --force force script to regenerate Makefiles.") print(" --nodotnet do not include .NET bindings in the binary distribution files.") print(" --dotnet-key= sign the .NET assembly with the private key in .") - print(" --arch= set architecture (to arm64) to force arm64 build") + print(" --arch= set architecture (arm64 or x64) to force cross-compilation") print(" --nojava do not include Java bindings in the binary distribution files.") print(" --os= set OS version.") print(" --nopython do not include Python bindings in the binary distribution files.") @@ -66,7 +67,7 @@ def display_help(): # Parse configuration option for mk_make script def parse_options(): - global FORCE_MK, JAVA_ENABLED, GIT_HASH, DOTNET_CORE_ENABLED, DOTNET_KEY_FILE, PYTHON_ENABLED, OS_NAME + global FORCE_MK, JAVA_ENABLED, GIT_HASH, DOTNET_CORE_ENABLED, DOTNET_KEY_FILE, PYTHON_ENABLED, OS_NAME, LINUX_X64 path = BUILD_DIR options, remainder = getopt.gnu_getopt(sys.argv[1:], 'b:hsf', ['build=', 'help', @@ -104,8 +105,11 @@ def parse_options(): elif opt == '--arch': if arg == "arm64": mk_util.IS_ARCH_ARM64 = True + elif arg == "x64": + mk_util.IS_ARCH_ARM64 = False + LINUX_X64 = True else: - raise MKException("Invalid architecture directive '%s'. Legal directives: arm64" % arg) + raise MKException("Invalid architecture directive '%s'. Legal directives: arm64, x64" % arg) elif opt == '--os': OS_NAME = arg else: @@ -136,15 +140,26 @@ def mk_build_dir(path): if mk_util.IS_ARCH_ARM64: opts.append('--arm64=true') if mk_util.IS_ARCH_ARM64 and LINUX_X64: - # we are machine x64 but build against arm64 - # so we have to do cross compiling - # the cross compiler is download from ARM GNU - # toolchain + # we are on x64 machine but build for arm64 + # so we have to do cross compiling on Linux + # the cross compiler is downloaded from ARM GNU toolchain myvar = { "CC": "aarch64-none-linux-gnu-gcc", "CXX": "aarch64-none-linux-gnu-g++" } env.update(myvar) + elif not mk_util.IS_ARCH_ARM64 and not LINUX_X64: + # we are on arm64 machine but build for x64 + # handle cross compilation on macOS (or other Unix systems) + import platform + if platform.system() == 'Darwin': + # On macOS, we can cross-compile using -arch flag + myvar = { + "CXXFLAGS": os.environ.get("CXXFLAGS", "") + " -arch x86_64", + "CFLAGS": os.environ.get("CFLAGS", "") + " -arch x86_64", + "LDFLAGS": os.environ.get("LDFLAGS", "") + " -arch x86_64" + } + env.update(myvar) if subprocess.call(opts, env=env) != 0: raise MKException("Failed to generate build directory at '%s'" % path)