@@ -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 ,
@@ -735,6 +736,7 @@ def build_cpython(
735736 python_archive ,
736737 python_version = python_version ,
737738 target_triple = target_triple ,
739+ build_options = parsed_build_options ,
738740 extension_modules = ems ,
739741 )
740742
@@ -825,6 +827,8 @@ def build_cpython(
825827 env ["CPYTHON_OPTIMIZED" ] = "1"
826828 if "lto" in parsed_build_options :
827829 env ["CPYTHON_LTO" ] = "1"
830+ if "static" in parsed_build_options :
831+ env ["CPYTHON_STATIC" ] = "1"
828832
829833 add_target_env (env , host_platform , target_triple , build_env )
830834
@@ -834,19 +838,26 @@ def build_cpython(
834838 crt_features = []
835839
836840 if host_platform == "linux64" :
837- if "musl " in target_triple :
841+ if "static " in parsed_build_options :
838842 crt_features .append ("static" )
839843 else :
840844 extension_module_loading .append ("shared-library" )
841- crt_features .append ("glibc-dynamic" )
842845
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" )
846+ if "musl" in target_triple :
847+ crt_features . append ( "musl-dynamic" )
848+ # TODO: Determine the dynamic musl libc version
846849
847- crt_features .append (
848- "glibc-max-symbol-version:%s" % glibc_max_version .decode ("ascii" )
849- )
850+ else :
851+ crt_features .append ("glibc-dynamic" )
852+
853+ glibc_max_version = build_env .get_file ("glibc_version.txt" ).strip ()
854+ if not glibc_max_version :
855+ raise Exception ("failed to retrieve glibc max symbol version" )
856+
857+ crt_features .append (
858+ "glibc-max-symbol-version:%s"
859+ % glibc_max_version .decode ("ascii" )
860+ )
850861
851862 python_symbol_visibility = "global-default"
852863
@@ -874,7 +885,9 @@ def build_cpython(
874885 "python_stdlib_test_packages" : sorted (STDLIB_TEST_PACKAGES ),
875886 "python_symbol_visibility" : python_symbol_visibility ,
876887 "python_extension_module_loading" : extension_module_loading ,
877- "libpython_link_mode" : "static" if "musl" in target_triple else "shared" ,
888+ "libpython_link_mode" : (
889+ "static" if "static" in parsed_build_options else "shared"
890+ ),
878891 "crt_features" : crt_features ,
879892 "run_tests" : "build/run_tests.py" ,
880893 "build_info" : python_build_info (
@@ -884,6 +897,7 @@ def build_cpython(
884897 target_triple ,
885898 "musl" in target_triple ,
886899 "lto" in parsed_build_options ,
900+ "static" in parsed_build_options ,
887901 enabled_extensions ,
888902 extra_metadata ,
889903 ),
@@ -946,6 +960,7 @@ def main():
946960 print ("unable to connect to Docker: %s" % e , file = sys .stderr )
947961 return 1
948962
963+ # Note these arguments must be synced with `build-main.py`
949964 parser = argparse .ArgumentParser ()
950965 parser .add_argument (
951966 "--host-platform" , required = True , help = "Platform we are building from"
@@ -955,13 +970,25 @@ def main():
955970 required = True ,
956971 help = "Host triple that we are building Python for" ,
957972 )
958- optimizations = {"debug" , "noopt" , "pgo" , "lto" , "pgo+lto" }
973+
974+ # Construct possible options
975+ options = set ()
976+ options .update ({"debug" , "noopt" , "pgo" , "lto" , "pgo+lto" })
977+ options .update ({f"freethreaded+{ option } " for option in options })
978+ options .update (
979+ {
980+ f"{ option } +{ link_mode } "
981+ for link_mode in {"static" , "shared" }
982+ for option in options
983+ }
984+ )
959985 parser .add_argument (
960986 "--options" ,
961- choices = optimizations . union ({ f"freethreaded+ { o } " for o in optimizations }) ,
987+ choices = options ,
962988 default = "noopt" ,
963989 help = "Build options to apply when compiling Python" ,
964990 )
991+
965992 parser .add_argument (
966993 "--toolchain" ,
967994 action = "store_true" ,
0 commit comments