@@ -488,6 +488,7 @@ def python_build_info(
488488 target_triple ,
489489 musl ,
490490 lto ,
491+ static ,
491492 extensions ,
492493 extra_metadata ,
493494):
@@ -506,7 +507,7 @@ def python_build_info(
506507 )
507508 )
508509
509- if not musl :
510+ if not static :
510511 bi ["core" ]["shared_lib" ] = "install/lib/libpython%s%s.so.1.0" % (
511512 version ,
512513 binary_suffix ,
@@ -825,6 +826,8 @@ def build_cpython(
825826 env ["CPYTHON_OPTIMIZED" ] = "1"
826827 if "lto" in parsed_build_options :
827828 env ["CPYTHON_LTO" ] = "1"
829+ if "static" in parsed_build_options :
830+ env ["CPYTHON_STATIC" ] = "1"
828831
829832 add_target_env (env , host_platform , target_triple , build_env )
830833
@@ -834,19 +837,26 @@ def build_cpython(
834837 crt_features = []
835838
836839 if host_platform == "linux64" :
837- if "musl " in target_triple :
840+ if "static " in parsed_build_options :
838841 crt_features .append ("static" )
839842 else :
840843 extension_module_loading .append ("shared-library" )
841- crt_features .append ("glibc-dynamic" )
842844
843- glibc_max_version = build_env . get_file ( "glibc_version.txt" ). strip ()
844- if not glibc_max_version :
845- raise Exception ( "failed to retrieve glibc max symbol version" )
845+ if "musl" in target_triple :
846+ crt_features . append ( "musl-dynamic" )
847+ # TODO: Determine the dynamic musl libc version
846848
847- crt_features .append (
848- "glibc-max-symbol-version:%s" % glibc_max_version .decode ("ascii" )
849- )
849+ else :
850+ crt_features .append ("glibc-dynamic" )
851+
852+ glibc_max_version = build_env .get_file ("glibc_version.txt" ).strip ()
853+ if not glibc_max_version :
854+ raise Exception ("failed to retrieve glibc max symbol version" )
855+
856+ crt_features .append (
857+ "glibc-max-symbol-version:%s"
858+ % glibc_max_version .decode ("ascii" )
859+ )
850860
851861 python_symbol_visibility = "global-default"
852862
@@ -874,7 +884,9 @@ def build_cpython(
874884 "python_stdlib_test_packages" : sorted (STDLIB_TEST_PACKAGES ),
875885 "python_symbol_visibility" : python_symbol_visibility ,
876886 "python_extension_module_loading" : extension_module_loading ,
877- "libpython_link_mode" : "static" if "musl" in target_triple else "shared" ,
887+ "libpython_link_mode" : "static"
888+ if "static" in parsed_build_options
889+ else "shared" ,
878890 "crt_features" : crt_features ,
879891 "run_tests" : "build/run_tests.py" ,
880892 "build_info" : python_build_info (
@@ -884,6 +896,7 @@ def build_cpython(
884896 target_triple ,
885897 "musl" in target_triple ,
886898 "lto" in parsed_build_options ,
899+ "static" in parsed_build_options ,
887900 enabled_extensions ,
888901 extra_metadata ,
889902 ),
@@ -946,6 +959,7 @@ def main():
946959 print ("unable to connect to Docker: %s" % e , file = sys .stderr )
947960 return 1
948961
962+ # Note these arguments must be synced with `build-main.py`
949963 parser = argparse .ArgumentParser ()
950964 parser .add_argument (
951965 "--host-platform" , required = True , help = "Platform we are building from"
@@ -955,13 +969,25 @@ def main():
955969 required = True ,
956970 help = "Host triple that we are building Python for" ,
957971 )
958- optimizations = {"debug" , "noopt" , "pgo" , "lto" , "pgo+lto" }
972+
973+ # Construct possible options
974+ options = set ()
975+ options .update ({"debug" , "noopt" , "pgo" , "lto" , "pgo+lto" })
976+ options .update ({f"freethreaded+{ option } " for option in options })
977+ options .update (
978+ {
979+ f"{ option } +{ link_mode } "
980+ for link_mode in {"static" , "shared" }
981+ for option in options
982+ }
983+ )
959984 parser .add_argument (
960985 "--options" ,
961- choices = optimizations . union ({ f"freethreaded+ { o } " for o in optimizations }) ,
986+ choices = options ,
962987 default = "noopt" ,
963988 help = "Build options to apply when compiling Python" ,
964989 )
990+
965991 parser .add_argument (
966992 "--toolchain" ,
967993 action = "store_true" ,
0 commit comments