Skip to content

Commit 2cfed9e

Browse files
committed
linux: add MUSL
We don't do anything with it yet. I'd like to experiment with compiling against musl so we don't incur a glibc run-time dependency.
1 parent 2b0eef2 commit 2cfed9e

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

cpython-linux/Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ COMMON_DEPENDS := \
1111

1212
PLATFORM := linux64
1313

14-
TOOLCHAIN_DEPENDS := \
14+
BASE_TOOLCHAIN_DEPENDS := \
1515
$(OUTDIR)/binutils-linux64.tar \
1616
$(OUTDIR)/gcc-linux64.tar \
1717
$(OUTDIR)/clang-linux64.tar \
1818
$(NULL)
1919

20+
TOOLCHAIN_DEPENDS := \
21+
$(BASE_TOOLCHAIN_DEPENDS) \
22+
$(OUTDIR)/musl-linux64.tar \
23+
$(NULL)
24+
2025
default: $(OUTDIR)/cpython-linux64$(if $(PYBUILD_OPTIMIZED),-pgo,).tar
2126

2227
$(OUTDIR)/image-%.tar: $(HERE)/%.Dockerfile $(COMMON_DEPENDS)
@@ -31,6 +36,9 @@ $(OUTDIR)/gcc-linux64.tar: $(OUTDIR)/binutils-linux64.tar $(HERE)/build-gcc.sh
3136
$(OUTDIR)/clang-linux64.tar: $(OUTDIR)/binutils-linux64.tar $(OUTDIR)/gcc-linux64.tar $(OUTDIR)/image-clang.tar $(HERE)/build-clang.sh
3237
$(BUILD) clang
3338

39+
$(OUTDIR)/musl-linux64.tar: $(BASE_TOOLCHAIN_DEPENDS) $(HERE)/build-musl.sh
40+
$(BUILD) musl
41+
3442
$(OUTDIR)/bdb-%.tar: $(OUTDIR)/image-build.tar $(TOOLCHAIN_DEPENDS) $(HERE)/build-bdb.sh
3543
$(BUILD) --platform $* bdb
3644

cpython-linux/build-musl.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
6+
set -e
7+
8+
cd /build
9+
10+
tar -xf musl-${MUSL_VERSION}.tar.gz
11+
12+
pushd musl-${MUSL_VERSION}
13+
14+
./configure \
15+
--prefix=/tools/host \
16+
--disable-shared
17+
18+
make -j `nproc`
19+
make -j `nproc` install DESTDIR=/build/out
20+
21+
popd

cpython-linux/build.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,24 @@ def build_clang(client, image):
318318
tools_path)
319319

320320

321+
def build_musl(client, image):
322+
musl_archive = download_entry('musl', BUILD)
323+
324+
with run_container(client, image) as container:
325+
copy_file_to_container(musl_archive, container, '/build')
326+
copy_file_to_container(SUPPORT / 'build-musl.sh', container, '/build')
327+
328+
env = {
329+
'MUSL_VERSION': DOWNLOADS['musl']['version'],
330+
}
331+
332+
container_exec(container, '/build/build-musl.sh',
333+
environment=env)
334+
335+
download_tools_archive(container, BUILD / 'musl-linux64.tar',
336+
'host')
337+
338+
321339
def build_libedit(client, image, platform):
322340
libedit_archive = download_entry('libedit', BUILD)
323341

@@ -696,6 +714,9 @@ def main():
696714
elif action == 'gcc':
697715
build_gcc(client, get_image(client, 'gcc'))
698716

717+
elif action == 'musl':
718+
build_musl(client, get_image(client, 'gcc'))
719+
699720
elif action == 'libedit':
700721
build_libedit(client, get_image(client, 'build'), platform=args.platform)
701722

pythonbuild/downloads.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@
165165
'sha256': '7a62ac1a04408614fccdc506e4844b10cf0ad2c2b1677097f8f35d3a1344a950',
166166
'version': '3.1.6',
167167
},
168+
'musl': {
169+
'url': 'https://www.musl-libc.org/releases/musl-1.1.22.tar.gz',
170+
'size': 987296,
171+
'sha256': '8b0941a48d2f980fd7036cfbd24aa1d414f03d9a0652ecbd5ec5c7ff1bee29e3',
172+
'version': '1.1.22',
173+
},
168174
'ncurses': {
169175
'url': 'https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.1.tar.gz',
170176
'size': 3365395,

0 commit comments

Comments
 (0)