Skip to content

Commit 7bd01a2

Browse files
authored
Rebuild MacOS python with lzma module installed (#975)
Also update `scripts/update_python.py` such that it works on linux once again. Fixes: emscripten-core/emscripten#16073
1 parent 476a14d commit 7bd01a2

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

emsdk_manifest.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@
422422
},
423423
{
424424
"id": "python",
425-
"version": "3.9.2-1",
425+
"version": "3.9.2",
426426
"bitness": 64,
427427
"arch": "x86_64",
428428
"windows_url": "python-3.9.2-1-embed-amd64+pywin32.zip",
@@ -431,16 +431,16 @@
431431
},
432432
{
433433
"id": "python",
434-
"version": "3.9.2-1",
434+
"version": "3.9.2",
435435
"bitness": 64,
436436
"arch": "x86_64",
437-
"macos_url": "python-3.9.2-1-macos-x86_64.tar.gz",
437+
"macos_url": "python-3.9.2-2-macos-x86_64.tar.gz",
438438
"activated_cfg": "PYTHON='%installation_dir%/bin/python3'",
439439
"activated_env": "EMSDK_PYTHON=%installation_dir%/bin/python3;SSL_CERT_FILE=%installation_dir%/lib/python3.9/site-packages/certifi/cacert.pem"
440440
},
441441
{
442442
"id": "python",
443-
"version": "3.9.2-1",
443+
"version": "3.9.2",
444444
"bitness": 64,
445445
"arch": "aarch64",
446446
"macos_url": "python-3.9.2-1-macos-arm64.tar.gz",
@@ -644,13 +644,13 @@
644644
{
645645
"version": "upstream-main",
646646
"bitness": 64,
647-
"uses": ["python-3.9.2-1-64bit", "llvm-git-main-64bit", "node-14.18.2-64bit", "emscripten-main-64bit", "binaryen-main-64bit"],
647+
"uses": ["python-3.9.2-64bit", "llvm-git-main-64bit", "node-14.18.2-64bit", "emscripten-main-64bit", "binaryen-main-64bit"],
648648
"os": "win"
649649
},
650650
{
651651
"version": "upstream-main",
652652
"bitness": 64,
653-
"uses": ["python-3.9.2-1-64bit", "llvm-git-main-64bit", "node-14.18.2-64bit", "emscripten-main-64bit", "binaryen-main-64bit"],
653+
"uses": ["python-3.9.2-64bit", "llvm-git-main-64bit", "node-14.18.2-64bit", "emscripten-main-64bit", "binaryen-main-64bit"],
654654
"os": "macos"
655655
},
656656
{
@@ -711,23 +711,23 @@
711711
{
712712
"version": "releases-upstream-%releases-tag%",
713713
"bitness": 64,
714-
"uses": ["node-14.18.2-64bit", "python-3.9.2-1-64bit", "releases-upstream-%releases-tag%-64bit"],
714+
"uses": ["node-14.18.2-64bit", "python-3.9.2-64bit", "releases-upstream-%releases-tag%-64bit"],
715715
"os": "macos",
716716
"arch": "x86_64",
717717
"custom_install_script": "emscripten_npm_install"
718718
},
719719
{
720720
"version": "releases-upstream-%releases-tag%",
721721
"bitness": 64,
722-
"uses": ["node-14.18.2-64bit", "python-3.9.2-1-64bit", "releases-upstream-%releases-tag%-64bit"],
722+
"uses": ["node-14.18.2-64bit", "python-3.9.2-64bit", "releases-upstream-%releases-tag%-64bit"],
723723
"os": "macos",
724724
"arch": "aarch64",
725725
"custom_install_script": "emscripten_npm_install"
726726
},
727727
{
728728
"version": "releases-upstream-%releases-tag%",
729729
"bitness": 64,
730-
"uses": ["node-14.18.2-64bit", "python-3.9.2-1-64bit", "java-8.152-64bit", "releases-upstream-%releases-tag%-64bit"],
730+
"uses": ["node-14.18.2-64bit", "python-3.9.2-64bit", "java-8.152-64bit", "releases-upstream-%releases-tag%-64bit"],
731731
"os": "win",
732732
"custom_install_script": "emscripten_npm_install"
733733
},
@@ -749,7 +749,7 @@
749749
{
750750
"version": "releases-fastcomp-%releases-tag%",
751751
"bitness": 64,
752-
"uses": ["node-14.18.2-64bit", "python-3.9.2-1-64bit", "releases-fastcomp-%releases-tag%-64bit"],
752+
"uses": ["node-14.18.2-64bit", "python-3.9.2-64bit", "releases-fastcomp-%releases-tag%-64bit"],
753753
"os": "macos",
754754
"arch": "aarch64",
755755
"custom_install_script": "emscripten_npm_install"

scripts/update_python.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
version = '3.9.2'
3535
major_minor_version = '.'.join(version.split('.')[:2]) # e.g. '3.9.2' -> '3.9'
3636
base = 'https://www.python.org/ftp/python/%s/' % version
37-
revision = '1'
37+
revision = '2'
3838

3939
pywin32_version = '227'
4040
pywin32_base = 'https://github.com/mhammond/pywin32/releases/download/b%s/' % pywin32_version
@@ -105,19 +105,22 @@ def build_python():
105105
if sys.platform.startswith('darwin'):
106106
osname = 'macos'
107107
# Take some rather drastic steps to link openssl statically
108-
check_call(['brew', 'install', 'openssl', 'pkg-config'])
108+
check_call(['brew', 'install', 'openssl', 'xz', 'pkg-config'])
109109
if platform.machine() == 'x86_64':
110110
prefix = '/usr/local'
111111
min_macos_version = '10.11'
112112
elif platform.machine() == 'arm64':
113113
prefix = '/opt/homebrew'
114114
min_macos_version = '11.0'
115115

116-
osname += '-' + platform.machine() # Append '-x86_64' or '-arm64' depending on current arch. (TODO: Do this for Linux too, move this below?)
116+
# Append '-x86_64' or '-arm64' depending on current arch. (TODO: Do
117+
# this for Linux too, move this below?)
118+
osname += '-' + platform.machine()
117119

118120
try:
119121
os.remove(os.path.join(prefix, 'opt', 'openssl', 'lib', 'libssl.dylib'))
120122
os.remove(os.path.join(prefix, 'opt', 'openssl', 'lib', 'libcrypto.dylib'))
123+
os.remove(os.path.join(prefix, 'opt', 'xz', 'lib', 'liblzma.dylib'))
121124
except Exception:
122125
pass
123126
os.environ['PKG_CONFIG_PATH'] = os.path.join(prefix, 'opt', 'openssl', 'lib', 'pkgconfig')
@@ -129,11 +132,18 @@ def build_python():
129132
check_call(['git', 'clone', 'https://github.com/python/cpython'])
130133
check_call(['git', 'checkout', 'v' + version], cwd=src_dir)
131134

132-
min_macos_version_line = '-mmacosx-version-min=' + min_macos_version # Specify the min OS version we want the build to work on
133-
build_flags = min_macos_version_line + ' -Werror=partial-availability' # Build against latest SDK, but issue an error if using any API that would not work on the min OS version
134-
env = os.environ.copy()
135-
env['MACOSX_DEPLOYMENT_TARGET'] = min_macos_version
136-
check_call(['./configure', 'CFLAGS=' + build_flags, 'CXXFLAGS=' + build_flags, 'LDFLAGS=' + min_macos_version_line], cwd=src_dir, env=env)
135+
env = os.environ
136+
if sys.platform.startswith('darwin'):
137+
# Specify the min OS version we want the build to work on
138+
min_macos_version_line = '-mmacosx-version-min=' + min_macos_version
139+
build_flags = min_macos_version_line + ' -Werror=partial-availability'
140+
# Build against latest SDK, but issue an error if using any API that would not work on the min OS version
141+
env = env.copy()
142+
env['MACOSX_DEPLOYMENT_TARGET'] = min_macos_version
143+
configure_args = ['CFLAGS=' + build_flags, 'CXXFLAGS=' + build_flags, 'LDFLAGS=' + min_macos_version_line]
144+
else:
145+
configure_args = []
146+
check_call(['./configure'] + configure_args, cwd=src_dir, env=env)
137147
check_call(['make', '-j', str(multiprocessing.cpu_count())], cwd=src_dir, env=env)
138148
check_call(['make', 'install', 'DESTDIR=install'], cwd=src_dir, env=env)
139149

@@ -143,6 +153,7 @@ def build_python():
143153
# SSL certificates are available (certifi in installed and used by requests).
144154
pybin = os.path.join(src_dir, 'install', 'usr', 'local', 'bin', 'python3')
145155
pip = os.path.join(src_dir, 'install', 'usr', 'local', 'bin', 'pip3')
156+
check_call([pybin, '-m', 'ensurepip', '--upgrade'])
146157
check_call([pybin, pip, 'install', 'requests'])
147158

148159
dirname = 'python-%s-%s' % (version, revision)
@@ -154,7 +165,7 @@ def build_python():
154165
shutil.rmtree(os.path.join(dirname, 'lib', 'python' + major_minor_version, 'test'))
155166
shutil.rmtree(os.path.join(dirname, 'include'))
156167
for lib in glob.glob(os.path.join(dirname, 'lib', 'lib*.a')):
157-
os.remove(lib)
168+
os.remove(lib)
158169
check_call(['tar', 'zcvf', tarball, dirname])
159170
print('Uploading: ' + upload_base + tarball)
160171
check_call(['gsutil', 'cp', '-n', tarball, upload_base + tarball])

0 commit comments

Comments
 (0)