Skip to content

Commit ce56973

Browse files
committed
Implement M1 build.
1 parent 777845f commit ce56973

File tree

5 files changed

+36
-24
lines changed

5 files changed

+36
-24
lines changed

Lib/__np__/common.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def run_with_output(*args, **kwargs):
215215
import subprocess
216216

217217
stdin = kwargs.pop("stdin", None)
218+
quiet = kwargs.pop("quiet", False)
218219
assert not kwargs
219220

220221
p = subprocess.Popen(
@@ -227,8 +228,9 @@ def run_with_output(*args, **kwargs):
227228

228229
output = ""
229230
for line in p.stdout:
230-
sys.stdout.write(line)
231-
sys.stdout.flush()
231+
if not quiet:
232+
sys.stdout.write(line)
233+
sys.stdout.flush()
232234
output += line
233235
p.wait()
234236
if p.returncode != 0:

Lib/rebuildpython.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def run_rebuild():
428428
sysconfig_libs = []
429429
sysconfig_lib_dirs = []
430430
for arg in (
431-
["-lm", "-pthread", "-lutil", "-ldl"]
431+
["-lm", "-pthread", "-lutil", "-ldl", "-lffi"]
432432
+ sysconfig.get_config_var("LDFLAGS").split()
433433
+ sysconfig.get_config_var("CFLAGS").split()
434434
):
@@ -456,10 +456,14 @@ def run_rebuild():
456456
extra_args_combined = [x for x in sysconfig.get_config_var("LDFLAGS").split() if not x.startswith("-L") and not x.startswith("-l")] \
457457
+ extra_link_args \
458458
+ [
459-
"-flto",
459+
"-flto=thin",
460460
"-framework", "SystemConfiguration",
461461
"-framework", "CoreFoundation",
462+
"-framework", "Carbon",
462463
]
464+
num_link_threads = os.environ.get("LINK_THREADS", None)
465+
if num_link_threads is not None:
466+
extra_args_combined += ["-Wl,-mllvm,-threads=" + num_link_threads]
463467
i = 0
464468
used_frameworks = []
465469
final_extra_link_args = ["-lstdc++"]
@@ -470,7 +474,7 @@ def run_rebuild():
470474
used_frameworks.append(extra_args_combined[i + 1])
471475
final_extra_link_args += ["-framework", extra_args_combined[i + 1]]
472476
i += 2
473-
if extra_args_combined[i].lower() in ("-g", "-xlinker"):
477+
elif extra_args_combined[i].lower() in ("-g", "-xlinker"):
474478
i += 1
475479
else:
476480
final_extra_link_args += [extra_args_combined[i]]
@@ -486,7 +490,7 @@ def run_rebuild():
486490
extra_midargs=final_extra_link_args,
487491
)
488492

489-
otool_output = __np__.run_with_output("otool", "-l", os.path.join(build_dir, "python"))
493+
otool_output = __np__.run_with_output("otool", "-l", os.path.join(build_dir, "python"), quiet=True)
490494
curr_load_lines = []
491495
for line in otool_output.split('\n'):
492496
if line.startswith("Load command") or line.startswith("Section"):

Modules/Setup.macos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ _sha3 _sha3/sha3module.c
263263
_blake2 _blake2/blake2module.c _blake2/blake2b_impl.c _blake2/blake2s_impl.c
264264

265265
# Nuitka: _ctypes module
266-
_ctypes -I$(srcdir)/Modules/_ctypes _ctypes/malloc_closure.c _ctypes/stgdict.c _ctypes/callbacks.c _ctypes/cfield.c _ctypes/_ctypes.c _ctypes/callproc.c
266+
_ctypes -I$(srcdir)/Modules/_ctypes -I$(srcdir)/Modules/_ctypes/darwin _ctypes/malloc_closure.c _ctypes/stgdict.c _ctypes/callbacks.c _ctypes/cfield.c _ctypes/_ctypes.c _ctypes/callproc.c -lffi -DUSING_MALLOC_CLOSURE_DOT_C=1 -DMACOSX -DUSING_APPLE_OS_LIBFFI=1 -DHAVE_FFI_PREP_CIF_VAR=1 -DHAVE_FFI_PREP_CLOSURE_LOC=1 -DHAVE_FFI_CLOSURE_ALLOC=1
267267
#_ctypes/darwin/dlfcn_simple.c
268268
#_ctypes/libffi_osx/types.c
269269
#_ctypes/libffi_osx/powerpc/ppc-ffi_darwin.c

build.mac.sh

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,22 @@
33
set -e
44
set -x
55

6+
if [ "$arch" = "" ]; then
7+
if [ "$(arch)" = "arm64" ]; then
8+
arch=arm64
9+
else
10+
arch=x86-64
11+
fi
12+
fi
13+
14+
echo Building for architecture $arch
15+
616
# The dependencies must be outside of the build folder because
717
# the python build process ends up running a find -delete that
818
# happens to also delete all the static libraries that we built.
919
export "PREFIX=$(pwd)/../Nuitka-Python-Deps"
10-
export "CFLAGS=-mmacosx-version-min=10.9 -I${PREFIX}/include"
11-
export "LDFLAGS=-L${PREFIX}/lib"
20+
export "CFLAGS=-arch $arch -mmacosx-version-min=10.9 -I${PREFIX}/include -I$(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/ffi -flto=thin"
21+
export "LDFLAGS=-arch $arch -L${PREFIX}/lib"
1222
export "MACOSX_DEPLOYMENT_TARGET=10.9"
1323

1424

@@ -49,7 +59,11 @@ if [ ! -d openssl-1.1.1q ]; then
4959
curl https://www.openssl.org/source/openssl-1.1.1q.tar.gz -o openssl.tar.gz
5060
tar -xf openssl.tar.gz
5161
cd openssl-1.1.1q
52-
./configure --prefix=${PREFIX} darwin64-x86_64-cc enable-ec_nistp_64_gcc_128 no-shared no-tests
62+
if [ "$arch" = "arm64" ]; then
63+
./Configure --prefix=${PREFIX} darwin64-arm64-cc enable-ec_nistp_64_gcc_128 no-shared no-tests
64+
else
65+
./Configure --prefix=${PREFIX} darwin64-x86_64-cc enable-ec_nistp_64_gcc_128 no-shared no-tests
66+
fi
5367
make depend all -j$(sysctl -n hw.ncpu)
5468
make install
5569
cd ..
@@ -93,16 +107,6 @@ make install
93107
cd ..
94108
fi
95109

96-
if [ ! -d libffi-3.4.2 ]; then
97-
curl -L https://github.com/libffi/libffi/releases/download/v3.4.2/libffi-3.4.2.tar.gz -o libffi.tar.gz
98-
tar -xf libffi.tar.gz
99-
cd libffi-3.4.2
100-
./configure --prefix=${PREFIX} --disable-shared
101-
make -j$(sysctl -n hw.ncpu)
102-
make install
103-
cd ..
104-
fi
105-
106110
if [ ! -d zlib-1.2.12 ]; then
107111
curl -L https://zlib.net/zlib-1.2.12.tar.gz -o zlib.tar.gz
108112
tar -xf zlib.tar.gz
@@ -169,17 +173,19 @@ fi
169173

170174
cp Modules/Setup.macos Modules/Setup
171175

176+
export "LDFLAGS=-L${PREFIX}/lib"
177+
172178
# The UCS4 has best compatibility with wheels on PyPI it seems.
173179
./configure "--prefix=$target" --disable-shared --enable-ipv6 --enable-unicode=ucs4 \
174180
--enable-optimizations --with-lto --with-computed-gotos --with-fpectl \
175181
CC="$CC" \
176182
CXX="$CXX" \
177183
CFLAGS="-g -mmacosx-version-min=10.9 $CFLAGS" \
178-
LDFLAGS="-g -Xlinker $LDFLAGS" \
179-
LIBS="-lffi -lbz2 -luuid -lsqlite3 -llzma"
184+
LDFLAGS="-arch $arch -g -Xlinker $LDFLAGS" \
185+
LIBS="-lffi -lbz2 -luuid -lsqlite3 -llzma" \
186+
ax_cv_c_float_words_bigendian=no
180187

181188
make -j 32 \
182-
EXTRA_CFLAGS="-flto" \
183189
PROFILE_TASK='./Lib/test/regrtest.py -j 8 -x test_bsddb3 test_compiler test_cpickle test_cprofile test_dbm_dumb test_dbm_ndbm test_distutils test_ensurepip test_gdb test_io test_linuxaudiodev test_multiprocessing test_ossaudiodev test_platform test_pydoc test_socketserver test_subprocess test_sundry test_thread test_threaded_import test_threadedtempfile test_threading test_threading_local test_threadsignals test_xmlrpc test_zipfile' \
184190
profile-opt
185191

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ cd ..
109109
fi
110110

111111
if [ ! -d libffi-3.4.2 ]; then
112-
curl -L https://github.com/libffi/libffi/releases/download/v3.4.2/libffi-3.4.2.tar.gz -o libffi.tar.gz
112+
curl -L https://github.com/libffi/libffi/releases/download/v3.4.3/libffi-3.4.3.tar.gz -o libffi.tar.gz
113113
tar -xf libffi.tar.gz
114114
cd libffi-3.4.2
115115
./configure --prefix=${PREFIX} --disable-shared

0 commit comments

Comments
 (0)