Skip to content

Commit a47ce07

Browse files
committed
[Meta] Ensure GMP can be found when building on an M1 host
1 parent b4c5cdb commit a47ce07

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

scripts/build_os_toolchain.py

+26-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/python3
22
import os
3+
import platform
34
import shutil
45
import argparse
6+
import sysconfig
57
import tempfile
68
from pathlib import Path
79
from typing import Tuple
@@ -23,6 +25,15 @@ def sleep():
2325
time.sleep(1)
2426

2527

28+
def is_arm64_process() -> bool:
29+
# Are we currently running in 'native' arm64 mode?
30+
return platform.machine() == 'arm64'
31+
32+
33+
def is_on_macos() -> bool:
34+
return 'macosx' in sysconfig.get_platform()
35+
36+
2637
def build() -> None:
2738
axle_dir = Path(__file__).parents[1]
2839
sysroot_dir = axle_dir / "axle-sysroot"
@@ -132,17 +143,22 @@ def build() -> None:
132143
libstdcpp_dir = gcc_dir / 'libstdc++-v3'
133144
run_and_check(['autoconf'], cwd=libstdcpp_dir, env_additions=env)
134145

146+
gcc_configure_args = [
147+
configure_script_path.as_posix(),
148+
f"--target=x86_64-elf-axle",
149+
f"--prefix={build_products_dir.as_posix()}",
150+
f"--with-sysroot={sysroot_dir.as_posix()}",
151+
"--disable-nls",
152+
# Ref: https://stackoverflow.com/questions/46487529/crosscompiling-gcc-link-tests-are-not-allowed-after-gcc-no-executables-when-che
153+
"--disable-bootstrap",
154+
"--enable-languages=c,c++",
155+
]
156+
if is_on_macos() and is_arm64_process():
157+
# homebrew_root = "/opt/homebrew/"
158+
homebrew_root = "/usr/local/homebrew/"
159+
gcc_configure_args.append(f"--with-gmp={homebrew_root}")
135160
run_and_check(
136-
[
137-
configure_script_path.as_posix(),
138-
f"--target=x86_64-elf-axle",
139-
f"--prefix={build_products_dir.as_posix()}",
140-
f"--with-sysroot={sysroot_dir.as_posix()}",
141-
"--disable-nls",
142-
# Ref: https://stackoverflow.com/questions/46487529/crosscompiling-gcc-link-tests-are-not-allowed-after-gcc-no-executables-when-che
143-
"--disable-bootstrap",
144-
"--enable-languages=c,c++",
145-
],
161+
gcc_configure_args,
146162
cwd=gcc_build_dir,
147163
env_additions=env
148164
)

0 commit comments

Comments
 (0)