Skip to content

Commit 88b335b

Browse files
committed
Split the musl versions for static and shared buildsl
1 parent fd04e37 commit 88b335b

File tree

4 files changed

+61
-8
lines changed

4 files changed

+61
-8
lines changed

cpython-unix/build-musl.sh

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ pushd musl-${MUSL_VERSION}
1818
# added reallocarray(), which gets used by at least OpenSSL.
1919
# Here, we disable this single function so as to not introduce
2020
# symbol dependencies on clients using an older musl version.
21-
patch -p1 <<EOF
21+
if [ "${MUSL_VERSION}" = "1.2.2"]; then
22+
patch -p1 <<EOF
2223
diff --git a/include/stdlib.h b/include/stdlib.h
2324
index b54a051f..194c2033 100644
2425
--- a/include/stdlib.h
@@ -51,6 +52,42 @@ index 4a6ebe46..00000000
5152
- return realloc(ptr, m * n);
5253
-}
5354
EOF
55+
else
56+
# There is a different patch for newer musl versions, used in static distributions
57+
patch -p1 <<EOF
58+
diff --git a/include/stdlib.h b/include/stdlib.h
59+
index b507ca3..8259e27 100644
60+
--- a/include/stdlib.h
61+
+++ b/include/stdlib.h
62+
@@ -147,7 +147,6 @@ int getloadavg(double *, int);
63+
int clearenv(void);
64+
#define WCOREDUMP(s) ((s) & 0x80)
65+
#define WIFCONTINUED(s) ((s) == 0xffff)
66+
-void *reallocarray (void *, size_t, size_t);
67+
void qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *);
68+
#endif
69+
70+
diff --git a/src/malloc/reallocarray.c b/src/malloc/reallocarray.c
71+
deleted file mode 100644
72+
index 4a6ebe4..0000000
73+
--- a/src/malloc/reallocarray.c
74+
+++ /dev/null
75+
@@ -1,13 +0,0 @@
76+
-#define _BSD_SOURCE
77+
-#include <errno.h>
78+
-#include <stdlib.h>
79+
-
80+
-void *reallocarray(void *ptr, size_t m, size_t n)
81+
-{
82+
- if (n && m > -1 / n) {
83+
- errno = ENOMEM;
84+
- return 0;
85+
- }
86+
-
87+
- return realloc(ptr, m * n);
88+
-}
89+
EOF
90+
fi
5491

5592

5693
CFLAGS="${CFLAGS} -fPIC" CPPFLAGS="${CPPFLAGS} -fPIC" ./configure \

cpython-unix/build.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ def simple_build(
255255
binutils=install_binutils(host_platform),
256256
clang=True,
257257
musl="musl" in target_triple,
258+
static="static" in build_options,
258259
)
259260

260261
for a in extra_archives or []:
@@ -320,25 +321,26 @@ def materialize_clang(host_platform: str, target_triple: str):
320321
dctx.copy_stream(ifh, ofh)
321322

322323

323-
def build_musl(client, image, host_platform: str, target_triple: str):
324-
musl_archive = download_entry("musl", DOWNLOADS_PATH)
324+
def build_musl(client, image, host_platform: str, target_triple: str, build_options):
325+
musl = "musl-static" if "static" in build_options else "msul"
326+
musl_archive = download_entry(musl, DOWNLOADS_PATH)
325327

326328
with build_environment(client, image) as build_env:
327329
build_env.install_toolchain(
328-
BUILD, host_platform, target_triple, binutils=True, clang=True
330+
BUILD, host_platform, target_triple, binutils=True, clang=True, static=False,
329331
)
330332
build_env.copy_file(musl_archive)
331333
build_env.copy_file(SUPPORT / "build-musl.sh")
332334

333335
env = {
334-
"MUSL_VERSION": DOWNLOADS["musl"]["version"],
336+
"MUSL_VERSION": DOWNLOADS[musl]["version"],
335337
"TOOLCHAIN": "llvm",
336338
}
337339

338340
build_env.run("build-musl.sh", environment=env)
339341

340342
build_env.get_tools_archive(
341-
toolchain_archive_path("musl", host_platform), "host"
343+
toolchain_archive_path(musl, host_platform), "host"
342344
)
343345

344346

@@ -356,6 +358,7 @@ def build_libedit(
356358
binutils=install_binutils(host_platform),
357359
clang=True,
358360
musl="musl" in target_triple,
361+
static="static" in build_options,
359362
)
360363

361364
build_env.install_artifact_archive(
@@ -390,6 +393,7 @@ def build_tix(
390393
binutils=install_binutils(host_platform),
391394
clang=True,
392395
musl="musl" in target_triple,
396+
static="static" in build_options,
393397
)
394398

395399
depends = {"tcl", "tk"}
@@ -436,6 +440,7 @@ def build_cpython_host(
436440
target_triple,
437441
binutils=install_binutils(host_platform),
438442
clang=True,
443+
static="static" in build_options,
439444
)
440445

441446
build_env.copy_file(archive)
@@ -751,6 +756,7 @@ def build_cpython(
751756
binutils=install_binutils(host_platform),
752757
clang=True,
753758
musl="musl" in target_triple,
759+
static="static" in build_options,
754760
)
755761

756762
packages = target_needs(TARGETS_CONFIG, target_triple, python_version)
@@ -1071,6 +1077,7 @@ def main():
10711077
get_image(client, ROOT, BUILD, "gcc"),
10721078
host_platform,
10731079
target_triple,
1080+
build_options,
10741081
)
10751082

10761083
elif action == "autoconf":

pythonbuild/buildenv.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def install_toolchain(
7676
binutils=False,
7777
musl=False,
7878
clang=False,
79+
static=False,
7980
):
8081
if binutils:
8182
self.install_toolchain_archive(build_dir, "binutils", host_platform)
@@ -86,7 +87,7 @@ def install_toolchain(
8687
)
8788

8889
if musl:
89-
self.install_toolchain_archive(build_dir, "musl", host_platform)
90+
self.install_toolchain_archive(build_dir, "musl-static" if static else "musl", host_platform)
9091

9192
def run(self, program, user="build", environment=None):
9293
if isinstance(program, str) and not program.startswith("/"):
@@ -207,7 +208,7 @@ def install_toolchain(
207208
)
208209

209210
if musl:
210-
self.install_toolchain_archive(build_dir, "musl", platform)
211+
self.install_toolchain_archive(build_dir, "musl-static" if static else "musl", platform)
211212

212213
def run(self, program, user="build", environment=None):
213214
if user != "build":

pythonbuild/downloads.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,20 @@
219219
"licenses": ["BSD-2-Clause"],
220220
"license_file": "LICENSE.mpdecimal.txt",
221221
},
222+
# The musl toolchain for shared / dynamically linked builds
222223
"musl": {
223224
"url": "https://musl.libc.org/releases/musl-1.2.2.tar.gz",
224225
"size": 1055220,
225226
"sha256": "9b969322012d796dc23dda27a35866034fa67d8fb67e0e2c45c913c3d43219dd",
226227
"version": "1.2.2",
227228
},
229+
# The musl toolchain for static builds
230+
"musl-static": {
231+
"url": "https://musl.libc.org/releases/musl-1.2.5.tar.gz",
232+
"size": 1080786,
233+
"sha256": "a9a118bbe84d8764da0ea0d28b3ab3fae8477fc7e4085d90102b8596fc7c75e4",
234+
"version": "1.2.5",
235+
},
228236
"ncurses": {
229237
"url": "https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.5.tar.gz",
230238
"size": 3688489,

0 commit comments

Comments
 (0)