@@ -488,6 +488,7 @@ def python_build_info(
488
488
target_triple ,
489
489
musl ,
490
490
lto ,
491
+ static ,
491
492
extensions ,
492
493
extra_metadata ,
493
494
):
@@ -506,7 +507,7 @@ def python_build_info(
506
507
)
507
508
)
508
509
509
- if not musl :
510
+ if not static :
510
511
bi ["core" ]["shared_lib" ] = "install/lib/libpython%s%s.so.1.0" % (
511
512
version ,
512
513
binary_suffix ,
@@ -825,6 +826,8 @@ def build_cpython(
825
826
env ["CPYTHON_OPTIMIZED" ] = "1"
826
827
if "lto" in parsed_build_options :
827
828
env ["CPYTHON_LTO" ] = "1"
829
+ if "static" in parsed_build_options :
830
+ env ["CPYTHON_STATIC" ] = "1"
828
831
829
832
add_target_env (env , host_platform , target_triple , build_env )
830
833
@@ -834,19 +837,26 @@ def build_cpython(
834
837
crt_features = []
835
838
836
839
if host_platform == "linux64" :
837
- if "musl " in target_triple :
840
+ if "static " in parsed_build_options :
838
841
crt_features .append ("static" )
839
842
else :
840
843
extension_module_loading .append ("shared-library" )
841
- crt_features .append ("glibc-dynamic" )
842
844
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
846
848
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
+ )
850
860
851
861
python_symbol_visibility = "global-default"
852
862
@@ -874,7 +884,9 @@ def build_cpython(
874
884
"python_stdlib_test_packages" : sorted (STDLIB_TEST_PACKAGES ),
875
885
"python_symbol_visibility" : python_symbol_visibility ,
876
886
"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" ,
878
890
"crt_features" : crt_features ,
879
891
"run_tests" : "build/run_tests.py" ,
880
892
"build_info" : python_build_info (
@@ -884,6 +896,7 @@ def build_cpython(
884
896
target_triple ,
885
897
"musl" in target_triple ,
886
898
"lto" in parsed_build_options ,
899
+ "static" in parsed_build_options ,
887
900
enabled_extensions ,
888
901
extra_metadata ,
889
902
),
@@ -946,6 +959,7 @@ def main():
946
959
print ("unable to connect to Docker: %s" % e , file = sys .stderr )
947
960
return 1
948
961
962
+ # Note these arguments must be synced with `build-main.py`
949
963
parser = argparse .ArgumentParser ()
950
964
parser .add_argument (
951
965
"--host-platform" , required = True , help = "Platform we are building from"
@@ -955,13 +969,25 @@ def main():
955
969
required = True ,
956
970
help = "Host triple that we are building Python for" ,
957
971
)
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
+ )
959
984
parser .add_argument (
960
985
"--options" ,
961
- choices = optimizations . union ({ f"freethreaded+ { o } " for o in optimizations }) ,
986
+ choices = options ,
962
987
default = "noopt" ,
963
988
help = "Build options to apply when compiling Python" ,
964
989
)
990
+
965
991
parser .add_argument (
966
992
"--toolchain" ,
967
993
action = "store_true" ,
0 commit comments