diff --git a/ci-targets.yaml b/ci-targets.yaml index ec08bd9a..a3b78565 100644 --- a/ci-targets.yaml +++ b/ci-targets.yaml @@ -247,7 +247,7 @@ linux: minimum-python-version: "3.13" run: true - x86_64-unknown-linux-musl: + x86_64-unknown-linux-musl-static: arch: x86_64 libc: musl python_versions: @@ -262,7 +262,7 @@ linux: - lto run: true - x86_64_v2-unknown-linux-musl: + x86_64_v2-unknown-linux-musl-static: arch: x86_64 arch_variant: v2 libc: musl @@ -278,7 +278,7 @@ linux: - lto run: true - x86_64_v3-unknown-linux-musl: + x86_64_v3-unknown-linux-musl-static: arch: x86_64 arch_variant: v3 libc: musl @@ -294,7 +294,7 @@ linux: - lto run: true - x86_64_v4-unknown-linux-musl: + x86_64_v4-unknown-linux-musl-static: arch: x86_64 arch_variant: v4 libc: musl diff --git a/cpython-unix/build-cpython.sh b/cpython-unix/build-cpython.sh index ea1b1c0a..d58cbdc5 100755 --- a/cpython-unix/build-cpython.sh +++ b/cpython-unix/build-cpython.sh @@ -381,7 +381,7 @@ CONFIGURE_FLAGS=" --without-ensurepip ${EXTRA_CONFIGURE_FLAGS}" -if [ "${CC}" = "musl-clang" ]; then +if [ -n "${CPYTHON_STATIC}" ]; then CFLAGS="${CFLAGS} -static" CPPFLAGS="${CPPFLAGS} -static" LDFLAGS="${LDFLAGS} -static" diff --git a/cpython-unix/build.py b/cpython-unix/build.py index da66ba4e..0ae17f94 100755 --- a/cpython-unix/build.py +++ b/cpython-unix/build.py @@ -486,7 +486,6 @@ def python_build_info( version, platform, target_triple, - musl, lto, extensions, extra_metadata, @@ -506,7 +505,7 @@ def python_build_info( ) ) - if not musl: + if not target_triple.endswith("-static"): bi["core"]["shared_lib"] = "install/lib/libpython%s%s.so.1.0" % ( version, binary_suffix, @@ -825,6 +824,8 @@ def build_cpython( env["CPYTHON_OPTIMIZED"] = "1" if "lto" in parsed_build_options: env["CPYTHON_LTO"] = "1" + if target_triple.endswith("-static"): + env["CPYTHON_STATIC"] = "1" add_target_env(env, host_platform, target_triple, build_env) @@ -834,19 +835,26 @@ def build_cpython( crt_features = [] if host_platform == "linux64": - if "musl" in target_triple: + if target_triple.endswith("-static"): crt_features.append("static") else: extension_module_loading.append("shared-library") - crt_features.append("glibc-dynamic") - glibc_max_version = build_env.get_file("glibc_version.txt").strip() - if not glibc_max_version: - raise Exception("failed to retrieve glibc max symbol version") + if "musl" in target_triple: + crt_features.append("musl-dynamic") + # TODO: Determine the dynamic musl libc version - crt_features.append( - "glibc-max-symbol-version:%s" % glibc_max_version.decode("ascii") - ) + else: + crt_features.append("glibc-dynamic") + + glibc_max_version = build_env.get_file("glibc_version.txt").strip() + if not glibc_max_version: + raise Exception("failed to retrieve glibc max symbol version") + + crt_features.append( + "glibc-max-symbol-version:%s" + % glibc_max_version.decode("ascii") + ) python_symbol_visibility = "global-default" @@ -874,7 +882,9 @@ def build_cpython( "python_stdlib_test_packages": sorted(STDLIB_TEST_PACKAGES), "python_symbol_visibility": python_symbol_visibility, "python_extension_module_loading": extension_module_loading, - "libpython_link_mode": "static" if "musl" in target_triple else "shared", + "libpython_link_mode": ( + "static" if target_triple.endswith("-static") else "shared" + ), "crt_features": crt_features, "run_tests": "build/run_tests.py", "build_info": python_build_info( @@ -946,6 +956,7 @@ def main(): print("unable to connect to Docker: %s" % e, file=sys.stderr) return 1 + # Note these arguments must be synced with `build-main.py` parser = argparse.ArgumentParser() parser.add_argument( "--host-platform", required=True, help="Platform we are building from" @@ -962,6 +973,7 @@ def main(): default="noopt", help="Build options to apply when compiling Python", ) + parser.add_argument( "--toolchain", action="store_true", diff --git a/cpython-unix/targets.yml b/cpython-unix/targets.yml index d3285891..5ba81bc3 100644 --- a/cpython-unix/targets.yml +++ b/cpython-unix/targets.yml @@ -947,7 +947,7 @@ x86_64_v4-unknown-linux-gnu: openssl_target: linux-x86_64 bolt_capable: true -x86_64-unknown-linux-musl: +x86_64-unknown-linux-musl-static: host_platforms: - linux64 pythons_supported: @@ -990,7 +990,7 @@ x86_64-unknown-linux-musl: - zlib openssl_target: linux-x86_64 -x86_64_v2-unknown-linux-musl: +x86_64_v2-unknown-linux-musl-static: host_platforms: - linux64 pythons_supported: @@ -1034,7 +1034,7 @@ x86_64_v2-unknown-linux-musl: - zlib openssl_target: linux-x86_64 -x86_64_v3-unknown-linux-musl: +x86_64_v3-unknown-linux-musl-static: host_platforms: - linux64 pythons_supported: @@ -1078,7 +1078,7 @@ x86_64_v3-unknown-linux-musl: - zlib openssl_target: linux-x86_64 -x86_64_v4-unknown-linux-musl: +x86_64_v4-unknown-linux-musl-static: host_platforms: - linux64 pythons_supported: diff --git a/pythonbuild/cpython.py b/pythonbuild/cpython.py index 50ad6f70..8f3ae82c 100644 --- a/pythonbuild/cpython.py +++ b/pythonbuild/cpython.py @@ -466,12 +466,13 @@ def derive_setup_local( enabled_extensions[name]["setup_line"] = name.encode("ascii") continue - # musl is static only. Ignore build-mode override. - if "musl" in target_triple: - section = "static" - else: - section = info.get("build-mode", "static") - + section = ( + # If performing a static build, always use static + "static" + if target_triple.endswith("-static") + # Otherwise, use the build mode (falling back to static) + else info.get("build-mode", "static") + ) enabled_extensions[name]["build-mode"] = section # Presumably this means the extension comes from the distribution's