3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-01-20 01:03:20 +00:00

Add support for ARM to X64 cross-compilation on macOS

- Initialize LINUX_X64 from mk_util.LINUX_X64
- Add support for --arch=x64 flag to force x64 builds
- Handle cross-compilation from ARM64 to x64 on macOS using -arch x86_64 flags
- Update help text to reflect both arm64 and x64 architecture options

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-01-17 14:14:14 +00:00
parent e7857159e4
commit b0a88056cf

View file

@ -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=<file> sign the .NET assembly with the private key in <file>.")
print(" --arch=<arch> set architecture (to arm64) to force arm64 build")
print(" --arch=<arch> set architecture (arm64 or x64) to force cross-compilation")
print(" --nojava do not include Java bindings in the binary distribution files.")
print(" --os=<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)