Skip to content

Enable free-threaded builds of Python 3.14 on musl #571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 24 additions & 28 deletions ci-targets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,12 @@ linux:
- debug
- noopt
- lto
# freethreaded builds require mimalloc which is not available on musl yet
# build_options_conditional:
# - options:
# - freethreaded+debug
# - freethreaded+noopt
# - freethreaded+lto
# minimum-python-version: "3.13"
build_options_conditional:
- options:
- freethreaded+debug
- freethreaded+noopt
- freethreaded+lto
minimum-python-version: "3.13"
run: true

x86_64_v2-unknown-linux-musl:
Expand All @@ -291,13 +290,12 @@ linux:
- debug
- noopt
- lto
# freethreaded builds require mimalloc which is not available on musl yet
# build_options_conditional:
# - options:
# - freethreaded+debug
# - freethreaded+noopt
# - freethreaded+lto
# minimum-python-version: "3.13"
build_options_conditional:
- options:
- freethreaded+debug
- freethreaded+noopt
- freethreaded+lto
minimum-python-version: "3.13"
run: true

x86_64_v3-unknown-linux-musl:
Expand All @@ -318,13 +316,12 @@ linux:
- debug
- noopt
- lto
# freethreaded builds require mimalloc which is not available on musl yet
# build_options_conditional:
# - options:
# - freethreaded+debug
# - freethreaded+noopt
# - freethreaded+lto
# minimum-python-version: "3.13"
build_options_conditional:
- options:
- freethreaded+debug
- freethreaded+noopt
- freethreaded+lto
minimum-python-version: "3.13"
run: true

x86_64_v4-unknown-linux-musl:
Expand All @@ -345,13 +342,12 @@ linux:
- debug
- noopt
- lto
# freethreaded builds require mimalloc which is not available on musl yet
# build_options_conditional:
# - options:
# - freethreaded+debug
# - freethreaded+noopt
# - freethreaded+lto
# minimum-python-version: "3.13"
build_options_conditional:
- options:
- freethreaded+debug
- freethreaded+noopt
- freethreaded+lto
minimum-python-version: "3.13"
run: true

windows:
Expand Down
20 changes: 18 additions & 2 deletions cpython-unix/build-cpython.sh
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,22 @@ if [ "${CC}" = "musl-clang" ]; then
done
fi

# To enable mimalloc (which is hard requirement for free-threaded versions, but preferred in
# general), we need `stdatomic.h` which is not provided by musl. It's a part of the include files
# that are part of clang. But musl-clang eliminates them from the default include path. So copy it
# into place.
if [[ "${CC}" = "musl-clang" && -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" ]]; then
for h in /tools/${TOOLCHAIN}/lib/clang/*/include/stdatomic.h; do
filename=$(basename "$h")
if [ -e "/tools/host/include/${filename}" ]; then
echo "${filename} already exists; don't need to copy!"
exit 1
fi
Comment on lines +410 to +414
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this my bash scripting knowledge failing me or are you bailing on the entire build here if the include file exists?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhh I guess so, I copied this from above though. It seems fine to bail because it's a wrong assumption in the build script.

cp "$h" /tools/host/include/
done
fi


if [ -n "${CPYTHON_STATIC}" ]; then
CFLAGS="${CFLAGS} -static"
CPPFLAGS="${CPPFLAGS} -static"
Expand All @@ -416,8 +432,8 @@ if [ -n "${CPYTHON_DEBUG}" ]; then
fi

# Explicitly enable mimalloc on 3.13+, it's already included by default but with this it'll fail
# if it's missing from the system. The musl builds do not supprt mimalloc yet.
if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" && "${CC}" != "musl-clang" ]]; then
# if it's missing from the system.
if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" ]]; then
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-mimalloc"
fi

Expand Down