diff --git a/cpython.BUILD.bazel b/cpython.BUILD.bazel index 94d10c9..b652f26 100644 --- a/cpython.BUILD.bazel +++ b/cpython.BUILD.bazel @@ -18,7 +18,6 @@ load("@rules_cc//cc:cc_binary.bzl", "cc_binary") load("@rules_cc//cc:cc_import.bzl", "cc_import") load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_cc//cc:cc_shared_library.bzl", "cc_shared_library") -load("@rules_cc//cc:cc_test.bzl", "cc_test") load("//bazel:module_sources.bzl", "CPYTHON_MODULE_SOURCES") load("//bazel:release.bzl", "CPYTHON_RELEASE", "PYTHON_NEEDS_DEEPFREEZE", "PYTHON_RESOURCE_FIELD3", "PYTHON_SOABI", "PYTHON_VERSION") @@ -30,14 +29,12 @@ package( declare_cpython_target_config_settings() C_STANDARD_COPTS = select({ - ":windows_arm64": ["/std:c11"], - ":windows_x86_64": ["/std:c11"], + "@platforms//os:windows": ["/std:c11"], "//conditions:default": ["-std=c11"], }) OPTIMIZATION_COPTS = select({ - ":windows_arm64": ["/O2"], - ":windows_x86_64": ["/O2"], + "@platforms//os:windows": ["/O2"], "//conditions:default": ["-O3"], }) @@ -92,25 +89,12 @@ WINDOWS_RESOURCE_SYSTEM_INCLUDES = [ ] PLATFORM_LINKOPTS = select({ - ":darwin_arm64": [ + "@platforms//os:macos": [ "-framework", "CoreFoundation", "-lm", ], - ":linux_arm64": [ - "-ldl", - "-lm", - "-lpthread", - "-lrt", - "-lutil", - "-Wl,--export-dynamic", - ], - ":darwin_x86_64": [ - "-framework", - "CoreFoundation", - "-lm", - ], - ":linux_x86_64": [ + "@platforms//os:linux": [ "-ldl", "-lm", "-lpthread", @@ -118,23 +102,16 @@ PLATFORM_LINKOPTS = select({ "-lutil", "-Wl,--export-dynamic", ], - ":windows_arm64": WINDOWS_LINK_LIBRARIES, - ":windows_x86_64": WINDOWS_LINK_LIBRARIES, + "@platforms//os:windows": WINDOWS_LINK_LIBRARIES, }) PYTHON_LINKOPTS = PLATFORM_LINKOPTS + select({ - ":darwin_arm64": [ + "@platforms//os:macos": [ "-Wl,-export_dynamic", "-Wl,-stack_size,1000000", ], - ":darwin_x86_64": [ - "-Wl,-export_dynamic", - "-Wl,-stack_size,1000000", - ], - ":linux_arm64": [], - ":linux_x86_64": [], - ":windows_arm64": ["/STACK:2000000"], - ":windows_x86_64": ["/STACK:2000000"], + "@platforms//os:windows": ["/STACK:2000000"], + "//conditions:default": [], }) pyconfig( @@ -145,6 +122,7 @@ pyconfig( copy_file( name = "sqlite3_header", + allow_symlink = True, src = "@sqlite3//:sqlite3.h", out = "sqlite3.h", ) @@ -235,11 +213,43 @@ SYSCONFIG_COMMON_BUILD_VARS = { "srcdir": ".", } +LINUX_SYSCONFIG_BUILD_VARS = merge_sysconfig_build_vars(SYSCONFIG_COMMON_BUILD_VARS, { + "BLDSHARED": "clang -shared", + "LIBM": "-lm", + "LIBS": "-ldl -lm -lpthread -lrt -lutil", + "LINKFORSHARED": "-Wl,--export-dynamic", + "MACHDEP": "linux", +}) + +WINDOWS_SYSCONFIG_BUILD_VARS = merge_sysconfig_build_vars(SYSCONFIG_COMMON_BUILD_VARS, { + "AR": "llvm-lib", + "BLDSHARED": "lld-link /DLL", + "CC": "clang-cl", + "CCSHARED": "", + "CFLAGS": "/std:c11 /O2 /DNDEBUG", + "CFLAGSFORSHARED": "", + "EXE": ".exe", + "EXT_SUFFIX": ".pyd", + "LDSHARED": "lld-link /DLL", + "LIBM": "", + "LDLIBRARY": PYTHON_DLL, + "LIBDIR": "{}/libs".format(SYSCONFIG_PREFIX), + "LIBRARY": PYTHON_IMPORT_LIBRARY, + "LIBS": " ".join(WINDOWS_LINK_LIBRARIES), + "MACHDEP": "win32", + "MULTIARCH_CPPFLAGS": "", + "OBJEXT": ".obj", + "PY_CFLAGS": "/std:c11 /O2 /DNDEBUG", + "Py_ENABLE_SHARED": "1", + "SHLIB_SUFFIX": ".pyd", + "SOABI": "", +}) + cpython_sysconfig( name = "generated_sysconfig", build_details_schema = CPYTHON_RELEASE.build_details_schema or "", build_vars = select({ - ":darwin_arm64": merge_sysconfig_build_vars(SYSCONFIG_COMMON_BUILD_VARS, { + "@platforms//os:macos": merge_sysconfig_build_vars(SYSCONFIG_COMMON_BUILD_VARS, { "BLDSHARED": "clang -shared", "EXT_SUFFIX": ".{}-darwin.so".format(PYTHON_SOABI), "LIBM": "-lm", @@ -252,97 +262,31 @@ cpython_sysconfig( "MULTIARCH_CPPFLAGS": "-DMULTIARCH=\\\"darwin\\\"", "SOABI": "{}-darwin".format(PYTHON_SOABI), }), - ":darwin_x86_64": merge_sysconfig_build_vars(SYSCONFIG_COMMON_BUILD_VARS, { - "BLDSHARED": "clang -shared", - "EXT_SUFFIX": ".{}-darwin.so".format(PYTHON_SOABI), - "LIBM": "-lm", - "LIBPL": "{}/config-{}-darwin".format(SYSCONFIG_LIBDEST, PYTHON_VERSION), - "LIBS": "-lm", - "LINKFORSHARED": "-Wl,-stack_size,1000000 -framework CoreFoundation", - "MACOSX_DEPLOYMENT_TARGET": MACOSX_DEPLOYMENT_TARGET, - "MACHDEP": "darwin", - "MULTIARCH": "darwin", - "MULTIARCH_CPPFLAGS": "-DMULTIARCH=\\\"darwin\\\"", - "SOABI": "{}-darwin".format(PYTHON_SOABI), - }), - ":linux_arm64": merge_sysconfig_build_vars(SYSCONFIG_COMMON_BUILD_VARS, { - "BLDSHARED": "clang -shared", + ":linux_arm64": merge_sysconfig_build_vars(LINUX_SYSCONFIG_BUILD_VARS, { "EXT_SUFFIX": ".{}-aarch64-linux-gnu.so".format(PYTHON_SOABI), - "LIBM": "-lm", "LIBPL": "{}/config-{}-aarch64-linux-gnu".format(SYSCONFIG_LIBDEST, PYTHON_VERSION), - "LIBS": "-ldl -lm -lpthread -lrt -lutil", - "LINKFORSHARED": "-Wl,--export-dynamic", - "MACHDEP": "linux", "MULTIARCH": "aarch64-linux-gnu", "MULTIARCH_CPPFLAGS": "-DMULTIARCH=\\\"aarch64-linux-gnu\\\"", "SOABI": "{}-aarch64-linux-gnu".format(PYTHON_SOABI), }), - ":linux_x86_64": merge_sysconfig_build_vars(SYSCONFIG_COMMON_BUILD_VARS, { - "BLDSHARED": "clang -shared", + ":linux_x86_64": merge_sysconfig_build_vars(LINUX_SYSCONFIG_BUILD_VARS, { "EXT_SUFFIX": ".{}-x86_64-linux-gnu.so".format(PYTHON_SOABI), - "LIBM": "-lm", "LIBPL": "{}/config-{}-x86_64-linux-gnu".format(SYSCONFIG_LIBDEST, PYTHON_VERSION), - "LIBS": "-ldl -lm -lpthread -lrt -lutil", - "LINKFORSHARED": "-Wl,--export-dynamic", - "MACHDEP": "linux", "MULTIARCH": "x86_64-linux-gnu", "MULTIARCH_CPPFLAGS": "-DMULTIARCH=\\\"x86_64-linux-gnu\\\"", "SOABI": "{}-x86_64-linux-gnu".format(PYTHON_SOABI), }), - ":windows_arm64": merge_sysconfig_build_vars(SYSCONFIG_COMMON_BUILD_VARS, { - "AR": "llvm-lib", - "BLDSHARED": "lld-link /DLL", - "CC": "clang-cl", - "CCSHARED": "", - "CFLAGS": "/std:c11 /O2 /DNDEBUG", - "CFLAGSFORSHARED": "", - "EXE": ".exe", - "EXT_SUFFIX": ".pyd", - "LDSHARED": "lld-link /DLL", - "LIBM": "", - "LDLIBRARY": PYTHON_DLL, - "LIBDIR": "{}/libs".format(SYSCONFIG_PREFIX), - "LIBRARY": PYTHON_IMPORT_LIBRARY, + ":windows_arm64": merge_sysconfig_build_vars(WINDOWS_SYSCONFIG_BUILD_VARS, { "LIBPL": "{}/config-{}-arm64-windows".format(SYSCONFIG_LIBDEST, PYTHON_VERSION), - "LIBS": " ".join(WINDOWS_LINK_LIBRARIES), - "MACHDEP": "win32", "MULTIARCH": "win-arm64", - "MULTIARCH_CPPFLAGS": "", - "OBJEXT": ".obj", - "PY_CFLAGS": "/std:c11 /O2 /DNDEBUG", - "Py_ENABLE_SHARED": "1", - "SHLIB_SUFFIX": ".pyd", - "SOABI": "", }), - ":windows_x86_64": merge_sysconfig_build_vars(SYSCONFIG_COMMON_BUILD_VARS, { - "AR": "llvm-lib", - "BLDSHARED": "lld-link /DLL", - "CC": "clang-cl", - "CCSHARED": "", - "CFLAGS": "/std:c11 /O2 /DNDEBUG", - "CFLAGSFORSHARED": "", - "EXE": ".exe", - "EXT_SUFFIX": ".pyd", - "LDSHARED": "lld-link /DLL", - "LIBM": "", - "LDLIBRARY": PYTHON_DLL, - "LIBDIR": "{}/libs".format(SYSCONFIG_PREFIX), - "LIBRARY": PYTHON_IMPORT_LIBRARY, + ":windows_x86_64": merge_sysconfig_build_vars(WINDOWS_SYSCONFIG_BUILD_VARS, { "LIBPL": "{}/config-{}-amd64-windows".format(SYSCONFIG_LIBDEST, PYTHON_VERSION), - "LIBS": " ".join(WINDOWS_LINK_LIBRARIES), - "MACHDEP": "win32", "MULTIARCH": "win-amd64", - "MULTIARCH_CPPFLAGS": "", - "OBJEXT": ".obj", - "PY_CFLAGS": "/std:c11 /O2 /DNDEBUG", - "Py_ENABLE_SHARED": "1", - "SHLIB_SUFFIX": ".pyd", - "SOABI": "", }), }), integer_build_vars = select({ - ":windows_arm64": ["Py_ENABLE_SHARED"], - ":windows_x86_64": ["Py_ENABLE_SHARED"], + "@platforms//os:windows": ["Py_ENABLE_SHARED"], "//conditions:default": [], }), cache_tag = CPYTHON_RELEASE.cache_tag, @@ -374,6 +318,16 @@ filegroup( target_compatible_with = POSIX_TARGET_COMPATIBILITY, ) +HEADER_INCLUDE_DIRS = [ + ".", + "Include", + "Include/internal", + "Modules", +] + (["Include/internal/mimalloc"] if PYTHON_VERSION in ["3.13", "3.14"] else []) + select({ + "@platforms//os:windows": ["PC"], + "//conditions:default": [], +}) + cc_library( name = "headers", hdrs = glob([ @@ -384,16 +338,7 @@ cc_library( "PC/**/*.h", "Python/**/*.h", ]) + [":pyconfig_h"], - includes = [ - ".", - "Include", - "Include/internal", - "Modules", - ] + (["Include/internal/mimalloc"] if PYTHON_VERSION in ["3.13", "3.14"] else []) + select({ - ":windows_arm64": ["PC"], - ":windows_x86_64": ["PC"], - "//conditions:default": [], - }), + includes = HEADER_INCLUDE_DIRS, textual_hdrs = glob( [ "Modules/**/*.inc", @@ -416,19 +361,9 @@ cc_library( "PC/**/*.h", "Python/**/*.h", ]) + [":pyconfig_h"], - includes = [ - ".", - "Include", - "Include/internal", - "Modules", - ] + (["Include/internal/mimalloc"] if PYTHON_VERSION in ["3.13", "3.14"] else []) + select({ - ":windows_arm64": ["PC"], - ":windows_x86_64": ["PC"], - "//conditions:default": [], - }), + includes = HEADER_INCLUDE_DIRS, defines = select({ - ":windows_arm64": WINDOWS_BOOTSTRAP_DEFINES, - ":windows_x86_64": WINDOWS_BOOTSTRAP_DEFINES, + "@platforms//os:windows": WINDOWS_BOOTSTRAP_DEFINES, "//conditions:default": [], }), textual_hdrs = glob( @@ -447,14 +382,15 @@ bundled_libraries( version = PYTHON_VERSION, ) +WINDOWS_BUILD_CORE_COPTS = select({ + "@platforms//os:windows": ["-DPy_BUILD_CORE=1"], + "//conditions:default": [], +}) + cc_library( name = "pyconfig_contract", srcs = ["@cpython//python/private:pyconfig_contract.c"], - copts = C_STANDARD_COPTS + select({ - ":windows_arm64": ["-DPy_BUILD_CORE=1"], - ":windows_x86_64": ["-DPy_BUILD_CORE=1"], - "//conditions:default": [], - }), + copts = C_STANDARD_COPTS + WINDOWS_BUILD_CORE_COPTS, deps = [":headers"], ) @@ -494,127 +430,75 @@ CORE_BASE_SOURCES = glob([ "Modules/main.c", ] +POSIX_CORE_SOURCES = [ + "Python/dynload_shlib.c", + "Python/frozenmain.c", +] + CORE_SOURCES = CORE_BASE_SOURCES + select({ - ":darwin_arm64": [ - "Python/dynload_shlib.c", - "Python/frozenmain.c", - ], - ":darwin_x86_64": [ - "Python/dynload_shlib.c", - "Python/frozenmain.c", - ], - ":linux_arm64": [ - "Python/dynload_shlib.c", - "Python/frozenmain.c", - ], - ":linux_x86_64": [ - "Python/dynload_shlib.c", - "Python/frozenmain.c", - ], - ":windows_arm64": [ - "PC/invalid_parameter_handler.c", - "PC/dl_nt.c", - "Python/dynload_win.c", - ], - ":windows_x86_64": [ + "@platforms//os:windows": [ "PC/invalid_parameter_handler.c", "PC/dl_nt.c", "Python/dynload_win.c", ], + "//conditions:default": POSIX_CORE_SOURCES, }) BOOTSTRAP_CORE_SOURCES = CORE_BASE_SOURCES + select({ - ":darwin_arm64": [ - "Python/dynload_shlib.c", - "Python/frozenmain.c", - ], - ":darwin_x86_64": [ - "Python/dynload_shlib.c", - "Python/frozenmain.c", - ], - ":linux_arm64": [ - "Python/dynload_shlib.c", - "Python/frozenmain.c", - ], - ":linux_x86_64": [ - "Python/dynload_shlib.c", - "Python/frozenmain.c", - ], - ":windows_arm64": [ - "PC/invalid_parameter_handler.c", - "Python/dynload_win.c", - "@cpython//python/private:windows_bootstrap_support.c", - ], - ":windows_x86_64": [ + "@platforms//os:windows": [ "PC/invalid_parameter_handler.c", "Python/dynload_win.c", "@cpython//python/private:windows_bootstrap_support.c", ], + "//conditions:default": POSIX_CORE_SOURCES, }) +POSIX_COMMON_COPTS = [ + "-DABIFLAGS=\\\"\\\"", + "-DPLATLIBDIR=\\\"lib\\\"", +] + COMMON_COPTS = C_STANDARD_COPTS + OPTIMIZATION_COPTS + [ "-fwrapv", "-DNDEBUG", ] + select({ - ":darwin_arm64": [ - "-DABIFLAGS=\\\"\\\"", - "-DMULTIARCH=\\\"darwin\\\"", - "-DPLATFORM=\\\"darwin\\\"", - "-DPLATLIBDIR=\\\"lib\\\"", - "-DSOABI=\\\"%s-darwin\\\"" % PYTHON_SOABI, - ], - ":darwin_x86_64": [ - "-DABIFLAGS=\\\"\\\"", + "@platforms//os:windows": [], + "//conditions:default": POSIX_COMMON_COPTS, +}) + select({ + "@platforms//os:macos": [ "-DMULTIARCH=\\\"darwin\\\"", "-DPLATFORM=\\\"darwin\\\"", - "-DPLATLIBDIR=\\\"lib\\\"", "-DSOABI=\\\"%s-darwin\\\"" % PYTHON_SOABI, ], ":linux_arm64": [ - "-DABIFLAGS=\\\"\\\"", "-DMULTIARCH=\\\"aarch64-linux-gnu\\\"", "-DPLATFORM=\\\"linux\\\"", - "-DPLATLIBDIR=\\\"lib\\\"", "-DSOABI=\\\"%s-aarch64-linux-gnu\\\"" % PYTHON_SOABI, ], ":linux_x86_64": [ - "-DABIFLAGS=\\\"\\\"", "-DMULTIARCH=\\\"x86_64-linux-gnu\\\"", "-DPLATFORM=\\\"linux\\\"", - "-DPLATLIBDIR=\\\"lib\\\"", "-DSOABI=\\\"%s-x86_64-linux-gnu\\\"" % PYTHON_SOABI, ], - ":windows_arm64": [ - "-DPY3_DLLNAME=L\\\"python3\\\"", - ], - ":windows_x86_64": [ - "-DPY3_DLLNAME=L\\\"python3\\\"", - ], + "@platforms//os:windows": ["-DPY3_DLLNAME=L\\\"python3\\\""], }) -WINDOWS_REMOTE_DEBUG_COPTS = ["-DPy_REMOTE_DEBUG=1"] if PYTHON_VERSION == "3.14" else [] +WINDOWS_CORE_COPTS = ( + ["-DPy_REMOTE_DEBUG=1"] if PYTHON_VERSION == "3.14" else [] +) + ["-DVPATH=\\\".\\\""] CORE_COPTS = ["-DPy_BUILD_CORE=1"] + COMMON_COPTS + select({ - ":windows_arm64": [ - "-DMS_DLL_ID=\\\"%s-arm64\\\"" % PYTHON_VERSION, - ] + WINDOWS_REMOTE_DEBUG_COPTS + [ - "-DVPATH=\\\".\\\"", - ], - ":windows_x86_64": [ - "-DMS_DLL_ID=\\\"%s\\\"" % PYTHON_VERSION, - ] + WINDOWS_REMOTE_DEBUG_COPTS + [ - "-DVPATH=\\\".\\\"", - ], + ":windows_arm64": ["-DMS_DLL_ID=\\\"%s-arm64\\\"" % PYTHON_VERSION], + ":windows_x86_64": ["-DMS_DLL_ID=\\\"%s\\\"" % PYTHON_VERSION], + "//conditions:default": [], +}) + select({ + "@platforms//os:windows": WINDOWS_CORE_COPTS, "//conditions:default": [], }) CEVAL_COPTS = ["-finline-max-stacksize=512"] if PYTHON_VERSION == "3.14" else [] -RUNTIME_MODULE_COPTS = COMMON_COPTS + select({ - ":windows_arm64": ["-DPy_BUILD_CORE=1"], - ":windows_x86_64": ["-DPy_BUILD_CORE=1"], - "//conditions:default": [], -}) +RUNTIME_MODULE_COPTS = COMMON_COPTS + WINDOWS_BUILD_CORE_COPTS BOOTSTRAP_MODULES = declare_cpython_static_modules( name = "python_bootstrap_modules", @@ -669,12 +553,8 @@ cc_library( name = "python_ceval", srcs = ["Python/ceval.c"], copts = CORE_COPTS + select({ - ":darwin_arm64": CEVAL_COPTS, - ":darwin_x86_64": CEVAL_COPTS, - ":linux_arm64": CEVAL_COPTS, - ":linux_x86_64": CEVAL_COPTS, - ":windows_arm64": [], - ":windows_x86_64": [], + "@platforms//os:windows": [], + "//conditions:default": CEVAL_COPTS, }), deps = [ ":headers", @@ -718,43 +598,18 @@ cc_library( alwayslink = True, ) -cc_test( - name = "libffi_complex_test", - srcs = ["@cpython//python/private/libffi:complex_test.c"], - deps = ["@cpython_libffi//:libffi"], - tags = [] if PYTHON_VERSION == "3.14" else ["manual"], - target_compatible_with = select({ - ":windows_arm64": ["@platforms//:incompatible"], - ":windows_x86_64": ["@platforms//:incompatible"], - "//conditions:default": [], - }), -) - -cc_test( - name = "libffi_call_test", - srcs = ["@cpython//python/private/libffi:call_test.c"], - deps = ["@cpython_libffi//:libffi"], - tags = [] if PYTHON_VERSION == "3.14" else ["manual"], -) - -cc_test( - name = "libffi_closure_test", - srcs = ["@cpython//python/private/libffi:closure_test.c"], - deps = ["@cpython_libffi//:libffi"], - tags = [] if PYTHON_VERSION == "3.14" else ["manual"], -) - -cc_test( - name = "libffi_seh_test", - srcs = ["@cpython//python/private/libffi:seh_test.c"], - deps = ["@cpython_libffi//:libffi"], - tags = [] if PYTHON_VERSION == "3.14" else ["manual"], - target_compatible_with = select({ - ":windows_arm64": [], - ":windows_x86_64": [], - "//conditions:default": ["@platforms//:incompatible"], - }), -) +FREEZE_BOOTSTRAP_DEPS = select({ + "@platforms//os:windows": [ + STATIC_BOOTSTRAP_MODULES.library, + ":bootstrap_headers", + ":python_bootstrap_core_no_frozen", + ], + "//conditions:default": [ + BOOTSTRAP_MODULES.library, + ":headers", + ":python_core_no_frozen", + ], +}) cc_binary( name = "_freeze_module", @@ -763,23 +618,7 @@ cc_binary( "Programs/_freeze_module.c", ], copts = CORE_COPTS, - deps = select({ - ":windows_arm64": [ - STATIC_BOOTSTRAP_MODULES.library, - ":bootstrap_headers", - ":python_bootstrap_core_no_frozen", - ], - ":windows_x86_64": [ - STATIC_BOOTSTRAP_MODULES.library, - ":bootstrap_headers", - ":python_bootstrap_core_no_frozen", - ], - "//conditions:default": [ - BOOTSTRAP_MODULES.library, - ":headers", - ":python_core_no_frozen", - ], - }), + deps = FREEZE_BOOTSTRAP_DEPS, linkopts = PLATFORM_LINKOPTS, ) @@ -825,22 +664,13 @@ FROZEN_MODULES = { for output, (module_name, source) in FROZEN_MODULES.items() ] -GETPATH_COPTS = select({ - ":windows_arm64": [ - "-DEXEC_PREFIX=NULL", - "-DPLATLIBDIR=\\\"DLLs\\\"", - "-DPREFIX=NULL", - "-DPYDEBUGEXT=\\\"\\\"", - "-DVERSION=NULL", - "-DVPATH=\\\".\\\"", - ], - ":windows_x86_64": [ +GETPATH_COPTS = ["-DVPATH=\\\".\\\""] + select({ + "@platforms//os:windows": [ "-DEXEC_PREFIX=NULL", "-DPLATLIBDIR=\\\"DLLs\\\"", "-DPREFIX=NULL", "-DPYDEBUGEXT=\\\"\\\"", "-DVERSION=NULL", - "-DVPATH=\\\".\\\"", ], "//conditions:default": [ "-DEXEC_PREFIX=\\\"/python\\\"", @@ -848,28 +678,11 @@ GETPATH_COPTS = select({ "-DPREFIX=\\\"/python\\\"", "-DPYTHONPATH=\\\"\\\"", "-DVERSION=\\\"%s\\\"" % PYTHON_VERSION, - "-DVPATH=\\\".\\\"", ], }) DEEPFREEZE_SRCS = deepfreeze_sources( - bootstrap_deps = select({ - ":windows_arm64": [ - STATIC_BOOTSTRAP_MODULES.library, - ":bootstrap_headers", - ":python_bootstrap_core_no_frozen", - ], - ":windows_x86_64": [ - STATIC_BOOTSTRAP_MODULES.library, - ":bootstrap_headers", - ":python_bootstrap_core_no_frozen", - ], - "//conditions:default": [ - BOOTSTRAP_MODULES.library, - ":headers", - ":python_core_no_frozen", - ], - }), + bootstrap_deps = FREEZE_BOOTSTRAP_DEPS, core_copts = CORE_COPTS, frozen_modules = FROZEN_MODULES, getpath_copts = GETPATH_COPTS, @@ -915,11 +728,7 @@ cc_shared_library( ], features = ["no_windows_export_all_symbols"], shared_lib_name = "runtime/" + PYTHON_DLL, - target_compatible_with = select({ - ":windows_arm64": [], - ":windows_x86_64": [], - "//conditions:default": ["@platforms//:incompatible"], - }), + target_compatible_with = WINDOWS_TARGET_COMPATIBILITY, user_link_flags = WINDOWS_LINK_LIBRARIES + ["/OPT:REF,NOICF"], ) @@ -931,6 +740,7 @@ filegroup( copy_file( name = "python_import_library", + allow_symlink = True, src = ":python_dll_interface_library", out = "runtime/libs/" + PYTHON_IMPORT_LIBRARY, ) @@ -939,11 +749,7 @@ cc_import( name = "python_dll_import", interface_library = ":python_import_library", shared_library = ":python_dll", - target_compatible_with = select({ - ":windows_arm64": [], - ":windows_x86_64": [], - "//conditions:default": ["@platforms//:incompatible"], - }), + target_compatible_with = WINDOWS_TARGET_COMPATIBILITY, ) cc_shared_library( @@ -969,6 +775,7 @@ filegroup( copy_file( name = "python_install_import_library", + allow_symlink = True, src = ":python_install_dll_interface_library", out = "install_runtime/libs/" + PYTHON_IMPORT_LIBRARY, visibility = ["//visibility:private"], @@ -989,11 +796,7 @@ cc_library( copts = C_STANDARD_COPTS + [ "-DPYTHON_DLL_NAME=\\\"{}\\\"".format(PYTHON_DLL_BASENAME), ], - target_compatible_with = select({ - ":windows_arm64": [], - ":windows_x86_64": [], - "//conditions:default": ["@platforms//:incompatible"], - }), + target_compatible_with = WINDOWS_TARGET_COMPATIBILITY, ) cc_shared_library( @@ -1001,11 +804,7 @@ cc_shared_library( deps = [":python3_forwarder"], features = ["no_windows_export_all_symbols"], shared_lib_name = "runtime/python3.dll", - target_compatible_with = select({ - ":windows_arm64": [], - ":windows_x86_64": [], - "//conditions:default": ["@platforms//:incompatible"], - }), + target_compatible_with = WINDOWS_TARGET_COMPATIBILITY, user_link_flags = ["/NOENTRY"], ) @@ -1017,6 +816,7 @@ filegroup( copy_file( name = "python3_import_library", + allow_symlink = True, src = ":python3_dll_interface_library", out = "runtime/libs/python3.lib", ) @@ -1025,11 +825,7 @@ cc_import( name = "python3_dll_import", interface_library = ":python3_import_library", shared_library = ":python3_dll", - target_compatible_with = select({ - ":windows_arm64": [], - ":windows_x86_64": [], - "//conditions:default": ["@platforms//:incompatible"], - }), + target_compatible_with = WINDOWS_TARGET_COMPATIBILITY, ) windows_resource( @@ -1167,31 +963,27 @@ SHARED_EXTENSIONS = shared_extensions( stable_import = ":python3_dll_import", ) +PYTHON_RUNTIME_DEPS = select({ + "@platforms//os:windows": [ + ":headers", + ":python_dll_import", + ], + "//conditions:default": [ + ":headers", + ":python_frozen", + ":python_runtime_core", + ], +}) + NATIVE_TEST_PROGRAMS = native_test_programs( version = PYTHON_VERSION, - deps = select({ - ":windows_arm64": [ - ":headers", - ":python_dll_import", - ], - ":windows_x86_64": [ - ":headers", - ":python_dll_import", - ], - "//conditions:default": [ - ":headers", - ":python_frozen", - ":python_runtime_core", - ], - }), + deps = PYTHON_RUNTIME_DEPS, linkopts = PLATFORM_LINKOPTS + select({ - ":windows_arm64": ["/NODEFAULTLIB:" + PYTHON_IMPORT_LIBRARY], - ":windows_x86_64": ["/NODEFAULTLIB:" + PYTHON_IMPORT_LIBRARY], + "@platforms//os:windows": ["/NODEFAULTLIB:" + PYTHON_IMPORT_LIBRARY], "//conditions:default": [], }), local_defines = select({ - ":windows_arm64": [], - ":windows_x86_64": [], + "@platforms//os:windows": [], "//conditions:default": [ "Py_BUILD_CORE=1", "Py_BUILD_CORE_MODULE=1", @@ -1202,15 +994,10 @@ NATIVE_TEST_PROGRAMS = native_test_programs( copy_to_directory( name = "runtime_stdlib", srcs = glob(["Lib/**"]) + [":sysconfig_data"] + select({ - ":darwin_arm64": SHARED_EXTENSIONS.darwin_arm64, - ":darwin_x86_64": SHARED_EXTENSIONS.darwin_x86_64, + "@platforms//os:macos": SHARED_EXTENSIONS.darwin, ":linux_arm64": SHARED_EXTENSIONS.linux_arm64, ":linux_x86_64": SHARED_EXTENSIONS.linux_x86_64, - ":windows_arm64": SHARED_EXTENSIONS.windows + [ - ":runtime_stdlib_inputs/venv/scripts/nt/" + VENV_LAUNCHER_RUNTIME_NAME, - ":runtime_stdlib_inputs/venv/scripts/nt/" + VENVW_LAUNCHER_RUNTIME_NAME, - ], - ":windows_x86_64": SHARED_EXTENSIONS.windows + [ + "@platforms//os:windows": SHARED_EXTENSIONS.windows + [ ":runtime_stdlib_inputs/venv/scripts/nt/" + VENV_LAUNCHER_RUNTIME_NAME, ":runtime_stdlib_inputs/venv/scripts/nt/" + VENVW_LAUNCHER_RUNTIME_NAME, ], @@ -1226,8 +1013,7 @@ copy_to_directory( copy_to_directory( name = "runtime_include", srcs = glob(["Include/**"]) + select({ - ":windows_arm64": [":pyconfig_h"], - ":windows_x86_64": [":pyconfig_h"], + "@platforms//os:windows": [":pyconfig_h"], "//conditions:default": [], }), out = "runtime/Include", @@ -1239,6 +1025,7 @@ copy_to_directory( copy_file( name = "runtime_makefile", + allow_symlink = True, src = ":sysconfig_makefile", out = "runtime/Makefile", target_compatible_with = POSIX_TARGET_COMPATIBILITY, @@ -1246,6 +1033,7 @@ copy_file( copy_file( name = "runtime_pyconfig", + allow_symlink = True, src = ":pyconfig_h", out = "runtime/pyconfig.h", target_compatible_with = POSIX_TARGET_COMPATIBILITY, @@ -1253,6 +1041,7 @@ copy_file( copy_file( name = "runtime_setup_local", + allow_symlink = True, src = "Modules/Setup.local", out = "runtime/Modules/Setup.local", target_compatible_with = POSIX_TARGET_COMPATIBILITY, @@ -1260,6 +1049,7 @@ copy_file( copy_file( name = "runtime_pybuilddir", + allow_symlink = True, src = "pybuilddir.txt", out = "runtime/pybuilddir.txt", ) @@ -1268,14 +1058,7 @@ PYTHON_RUNTIME_DATA = [ ":runtime_include", ":runtime_stdlib", ] + NATIVE_TEST_PROGRAMS + select({ - ":windows_arm64": [ - ":python3_dll", - ":python3_import_library", - ":python_dll", - ":python_import_library", - ":runtime/pythonw", - ], - ":windows_x86_64": [ + "@platforms//os:windows": [ ":python3_dll", ":python3_import_library", ":python_dll", @@ -1290,65 +1073,40 @@ PYTHON_RUNTIME_DATA = [ ], }) -PYTHON_RUNTIME_DEPS = select({ - ":windows_arm64": [ - ":headers", - ":python_dll_import", - ], - ":windows_x86_64": [ - ":headers", - ":python_dll_import", - ], - "//conditions:default": [ - ":headers", - ":python_frozen", - ":python_runtime_core", - ], -}) - BUILD_METADATA = cpython_build_metadata( version = PYTHON_VERSION, ) +PYTHON_EXE_ADDITIONAL_LINKER_INPUTS = select({ + "@platforms//os:windows": [":python_exe_resource"], + "//conditions:default": [], +}) + +PYTHON_EXE_LINKOPTS = PYTHON_LINKOPTS + select({ + "@platforms//os:windows": [ + "/NODEFAULTLIB:" + PYTHON_IMPORT_LIBRARY, + "$(location :python_exe_resource)", + ], + "//conditions:default": [], +}) + cc_binary( name = "runtime/python", srcs = ["Programs/python.c"], - additional_linker_inputs = select({ - ":windows_arm64": [":python_exe_resource"], - ":windows_x86_64": [":python_exe_resource"], - "//conditions:default": [], - }), + additional_linker_inputs = PYTHON_EXE_ADDITIONAL_LINKER_INPUTS, copts = CORE_COPTS, data = PYTHON_RUNTIME_DATA + BUILD_METADATA.runtime_data, deps = PYTHON_RUNTIME_DEPS, - linkopts = PYTHON_LINKOPTS + select({ - ":windows_arm64": [ - "/NODEFAULTLIB:" + PYTHON_IMPORT_LIBRARY, - "$(location :python_exe_resource)", - ], - ":windows_x86_64": [ - "/NODEFAULTLIB:" + PYTHON_IMPORT_LIBRARY, - "$(location :python_exe_resource)", - ], - "//conditions:default": [], - }), + linkopts = PYTHON_EXE_LINKOPTS, ) cc_binary( name = "install_runtime/python", srcs = ["Programs/python.c"], - additional_linker_inputs = select({ - ":windows_arm64": [":python_exe_resource"], - ":windows_x86_64": [":python_exe_resource"], - "//conditions:default": [], - }), + additional_linker_inputs = PYTHON_EXE_ADDITIONAL_LINKER_INPUTS, copts = CORE_COPTS, deps = select({ - ":windows_arm64": [ - ":headers", - ":python_install_dll_import", - ], - ":windows_x86_64": [ + "@platforms//os:windows": [ ":headers", ":python_install_dll_import", ], @@ -1358,17 +1116,7 @@ cc_binary( ":python_install_runtime_core", ], }), - linkopts = PYTHON_LINKOPTS + select({ - ":windows_arm64": [ - "/NODEFAULTLIB:" + PYTHON_IMPORT_LIBRARY, - "$(location :python_exe_resource)", - ], - ":windows_x86_64": [ - "/NODEFAULTLIB:" + PYTHON_IMPORT_LIBRARY, - "$(location :python_exe_resource)", - ], - "//conditions:default": [], - }), + linkopts = PYTHON_EXE_LINKOPTS, visibility = ["//visibility:private"], ) @@ -1458,10 +1206,7 @@ copy_to_directory( copy_to_directory( name = "runtime_test_pc", - srcs = glob([ - "PC/pyconfig.h", - "PC/pyconfig.h.in", - ], allow_empty = True), + srcs = glob(["PC/pyconfig.h*"], allow_empty = True), out = "runtime/PC", root_paths = ["PC"], ) @@ -1470,6 +1215,7 @@ copy_file( name = "runtime_test_readme_rst", src = "README.rst", out = "runtime/README.rst", + allow_symlink = True, ) [ @@ -1477,6 +1223,7 @@ copy_file( name = "runtime_test_" + source.lower().replace(".", "_").replace("/", "_"), src = source, out = "runtime/" + source, + allow_symlink = True, target_compatible_with = POSIX_TARGET_COMPATIBILITY, ) for source in [ @@ -1491,6 +1238,7 @@ copy_file( name = "runtime_test_tools_buildbot_test_bat", src = "Tools/buildbot/test.bat", out = "runtime/Tools/buildbot/test.bat", + allow_symlink = True, target_compatible_with = WINDOWS_TARGET_COMPATIBILITY, ) @@ -1503,8 +1251,7 @@ filegroup( ":runtime_test_pc", ":runtime_test_readme_rst", ] + select({ - ":windows_arm64": [":runtime_test_tools_buildbot_test_bat"], - ":windows_x86_64": [":runtime_test_tools_buildbot_test_bat"], + "@platforms//os:windows": [":runtime_test_tools_buildbot_test_bat"], "//conditions:default": [ ":runtime_test_configure", ":runtime_test_configure_ac", @@ -1518,8 +1265,7 @@ upstream_regrtests( name = "upstream_tests", module_test_data = { "test_embed": select({ - ":windows_arm64": [":runtime_pybuilddir"], - ":windows_x86_64": [":runtime_pybuilddir"], + "@platforms//os:windows": [":runtime_pybuilddir"], "//conditions:default": [], }), }, diff --git a/docs/configure-check-audit.md b/docs/configure-check-audit.md index 6318883..272e095 100644 --- a/docs/configure-check-audit.md +++ b/docs/configure-check-audit.md @@ -705,7 +705,7 @@ Run `tools/configure_check_audit.sh` to regenerate this file. CI runs `tools/con | [x] | `_POSIX_THREADS` | `UNSUPPORTED_PLATFORM` | L4097, L4099, L4103, L4160 | L4411, L4413, L4417, L4474 | L4631, L4633, L4634, L4690 | L4693, L4695, L4696, L4752 | undefined (no producer) | undefined (no producer) | undefined (no producer) | undefined (no producer) | undefined (no producer) | undefined (no producer) | undefined (no producer) | undefined (no producer) | undefined (no producer) | undefined (no producer) | undefined (no producer) | undefined (no producer) | undefined (no producer) | undefined (no producer) | undefined (no producer) | undefined (no producer) | The symbol belongs to a platform outside the supported Linux and Darwin arm64 and x86_64 targets. | | [x] | `_PYTHONFRAMEWORK` | `AUTOCONF_PRODUCER` | L526 | L530 | L695 | L718 | `""` | `""` | `""` | `""` | `""` | `""` | `""` | `""` | `""` | `""` | `""` | `""` | `""` | `""` | `""` | `""` | Produced by rules_cc_autoconf in every applicable generated configuration. | | [x] | `_PYTHREAD_NAME_MAXLEN` | `PLATFORM_SPECIFIC_TARGET_FACT` | — | — | — | L7729, L7730, L7731, L7732, +7 | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | `63` | `63` | `15` | `15` | CPython 3.14 uses 15 on Linux and 63 on Darwin. | -| [x] | `_Py_FFI_SUPPORT_C_COMPLEX` | `DEPENDENCY_CONTRACT` | — | — | — | L4202 | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | `1` | `1` | `1` | `1` | The pinned libffi build passes libffi_complex_test on every supported POSIX target. | +| [x] | `_Py_FFI_SUPPORT_C_COMPLEX` | `DEPENDENCY_CONTRACT` | — | — | — | L4202 | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | `1` | `1` | `1` | `1` | The pinned hermetic libffi build provides ffi_type_complex_double on every supported POSIX target. | | [x] | `_Py_HACL_CAN_COMPILE_VEC128` | `FIXED_BUILD_POLICY` | — | — | — | L8057 | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | undefined (no producer) | undefined (no producer) | undefined (no producer) | undefined (no producer) | The Bazel HACL target compiles CPython 3.14's scalar HACL sources only. | | [x] | `_Py_HACL_CAN_COMPILE_VEC256` | `FIXED_BUILD_POLICY` | — | — | — | L8089 | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | undefined (no producer) | undefined (no producer) | undefined (no producer) | undefined (no producer) | The Bazel HACL target compiles CPython 3.14's scalar HACL sources only. | | [x] | `_Py_STACK_GROWS_DOWN` | `FIXED_TARGET_FACT` | — | — | — | L1207, L1208, L1209, L1211 | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | not in header | `1` | `1` | `1` | `1` | The stack grows downward on every supported POSIX target. | @@ -757,7 +757,6 @@ These decisions are maintained explicitly because they do not emit `pyconfig.h.i | `xz_dependency` | `DEPENDENCY_CONTRACT` | The _lzma module depends on the pinned xz Bazel module. | Header and function results are dependency contracts rather than host discovery. | | `libffi_dependency` | `DEPENDENCY_CONTRACT` | The _ctypes module depends on the pinned hermetic libffi build. | ffi_prep_cif_var, ffi_prep_closure_loc, and ffi_closure_alloc follow that dependency. | | `cpython_3_11_libffi_features` | `DEPENDENCY_CONTRACT` | cpython_static_module_manifest adds HAVE_FFI_CLOSURE_ALLOC, HAVE_FFI_PREP_CIF_VAR, and HAVE_FFI_PREP_CLOSURE_LOC only to the CPython 3.11 _ctypes target. | CPython 3.11 does not expose these extension-specific definitions through pyconfig.h.in. | -| `cpython_3_14_libffi_complex` | `DEPENDENCY_CONTRACT` | libffi_complex_test performs ffi_prep_cif and ffi_call with ffi_type_complex_double on every supported POSIX target. | The test reproduces CPython 3.14's runtime validation for _Py_FFI_SUPPORT_C_COMPLEX. | | `openssl_dependency` | `DEPENDENCY_CONTRACT` | The _ssl and _hashlib modules depend on the pinned OpenSSL Bazel module. | OpenSSL configuration does not inspect host libraries. | | `sqlite_dependency` | `DEPENDENCY_CONTRACT` | The _sqlite3 module depends on the pinned SQLite Bazel module. | PY_SQLITE_HAVE_SERIALIZE follows the pinned SQLite build; extension loading remains disabled. | | `unsupported_optional_dependencies` | `UNSUPPORTED_DEPENDENCY` | readline, curses, panel, gdbm, ndbm, uuid, Tcl/Tk, editline, crypt, zstd, and external libintl symbols have explicit undefined dispositions. | The Bazel module does not declare those optional dependency graphs or modules. | diff --git a/libffi.BUILD.bazel b/libffi.BUILD.bazel index 871fd89..9346431 100644 --- a/libffi.BUILD.bazel +++ b/libffi.BUILD.bazel @@ -65,21 +65,42 @@ config_setting( libffi_config(name = "libffi_config") +# configure.host selects sysv.S for arm64 on Darwin, Linux, and clang-cl Windows. +ARM64_SOURCES = [ + "src/aarch64/ffi.c", + "src/aarch64/sysv.S", +] + +POSIX_X86_64_SOURCES = [ + "src/x86/ffi64.c", + "src/x86/ffiw64.c", + "src/x86/unix64.S", + "src/x86/win64.S", +] + +LIBFFI_TARGET_COMPATIBILITY = select({ + "@platforms//os:linux": [], + "@platforms//os:macos": [], + "@platforms//os:windows": [], + "//conditions:default": ["@platforms//:incompatible"], +}) + select({ + ":arm64": [], + ":x86_64": [], + "//conditions:default": ["@platforms//:incompatible"], +}) + cc_library( name = "libffi", copts = select({ - ":windows_arm64": [], - ":windows_x86_64": [], + "@platforms//os:windows": [], "//conditions:default": ["-fexceptions"], }), defines = select({ - ":windows_arm64": ["FFI_STATIC_BUILD=1"], - ":windows_x86_64": ["FFI_STATIC_BUILD=1"], + "@platforms//os:windows": ["FFI_STATIC_BUILD=1"], "//conditions:default": [], }), features = select({ - ":windows_arm64": ["dynamic_link_msvcrt"], - ":windows_x86_64": ["dynamic_link_msvcrt"], + "@platforms//os:windows": ["dynamic_link_msvcrt"], "//conditions:default": [], }), srcs = [ @@ -90,31 +111,8 @@ cc_library( "src/tramp.c", "src/types.c", ] + select({ - ":darwin_arm64": [ - "src/aarch64/ffi.c", - "src/aarch64/sysv.S", - ], - ":darwin_x86_64": [ - "src/x86/ffi64.c", - "src/x86/ffiw64.c", - "src/x86/unix64.S", - "src/x86/win64.S", - ], - ":linux_arm64": [ - "src/aarch64/ffi.c", - "src/aarch64/sysv.S", - ], - ":linux_x86_64": [ - "src/x86/ffi64.c", - "src/x86/ffiw64.c", - "src/x86/unix64.S", - "src/x86/win64.S", - ], - ":windows_arm64": [ - # configure.host classifies clang-cl as Clang and selects sysv.S. - "src/aarch64/ffi.c", - "src/aarch64/sysv.S", - ], + ":arm64": ARM64_SOURCES, + ":x86_64": POSIX_X86_64_SOURCES, ":windows_x86_64": [ # configure.host classifies clang-cl as Clang and selects win64.S. "src/x86/ffiw64.c", @@ -148,14 +146,6 @@ cc_library( ":arm64": ["src/aarch64"], ":x86_64": ["src/x86"], }), - target_compatible_with = select({ - ":darwin_arm64": [], - ":darwin_x86_64": [], - ":linux_arm64": [], - ":linux_x86_64": [], - ":windows_arm64": [], - ":windows_x86_64": [], - "//conditions:default": ["@platforms//:incompatible"], - }), + target_compatible_with = LIBFFI_TARGET_COMPATIBILITY, textual_hdrs = ["src/dlmalloc.c"], ) diff --git a/python/private/install_tree.bzl b/python/private/install_tree.bzl index 763ffe0..a191fc8 100644 --- a/python/private/install_tree.bzl +++ b/python/private/install_tree.bzl @@ -102,57 +102,40 @@ def cpython_install_tree( ], exclude = _INSTALL_ONLY_STDLIB_EXCLUDES, ) + [pyconfig] + posix_sources = [ + python, + sysconfig_data, + "LICENSE", + ":_install_tree_posix_marker", + ] + windows_sources = [ + python, + pythonw, + windows_license, + ":_install_tree_windows_marker", + ] + ( + windows_core_libraries + + windows_runtime_libraries + + windows_venv_launchers + + _extension_labels(extensions.install_only_windows) + ) copy_to_directory( name = "install_tree", srcs = common_sources + install_metadata + select({ - ":darwin_arm64": [ - python, - sysconfig_data, - "LICENSE", - ":_install_tree_posix_marker", - ] + _extension_labels(extensions.install_only_darwin_arm64), - ":darwin_x86_64": [ - python, - sysconfig_data, - "LICENSE", - ":_install_tree_posix_marker", - ] + _extension_labels(extensions.install_only_darwin_x86_64), - ":linux_arm64": [ - python, - sysconfig_data, - "LICENSE", - ":_install_tree_posix_marker", - ] + _extension_labels(extensions.install_only_linux_arm64), - ":linux_x86_64": [ - python, - sysconfig_data, - "LICENSE", - ":_install_tree_posix_marker", - ] + _extension_labels(extensions.install_only_linux_x86_64), - ":windows_arm64": [ - python, - pythonw, - windows_license, - ":_install_tree_windows_marker", - ] + windows_core_libraries + windows_runtime_libraries + windows_venv_launchers + _extension_labels(extensions.install_only_windows), - ":windows_x86_64": [ - python, - pythonw, - windows_license, - ":_install_tree_windows_marker", - ] + windows_core_libraries + windows_runtime_libraries + windows_venv_launchers + _extension_labels(extensions.install_only_windows), + "@platforms//os:macos": posix_sources + _extension_labels(extensions.install_only_darwin), + ":linux_arm64": posix_sources + _extension_labels(extensions.install_only_linux_arm64), + ":linux_x86_64": posix_sources + _extension_labels(extensions.install_only_linux_x86_64), + "@platforms//os:windows": windows_sources, }), out = "install", hardlink = "off", include_external_repositories = ["*msvc_runtime*"], replace_prefixes = select({ - ":darwin_arm64": _posix_replacements(version, extensions.install_only_darwin_arm64), - ":darwin_x86_64": _posix_replacements(version, extensions.install_only_darwin_x86_64), + "@platforms//os:macos": _posix_replacements(version, extensions.install_only_darwin), ":linux_arm64": _posix_replacements(version, extensions.install_only_linux_arm64), ":linux_x86_64": _posix_replacements(version, extensions.install_only_linux_x86_64), - ":windows_arm64": _windows_replacements(version, extensions.install_only_windows), - ":windows_x86_64": _windows_replacements(version, extensions.install_only_windows), + "@platforms//os:windows": _windows_replacements(version, extensions.install_only_windows), }), root_paths = [ ".", diff --git a/python/private/libffi/BUILD.bazel b/python/private/libffi/BUILD.bazel index 64a91c1..e69de29 100644 --- a/python/private/libffi/BUILD.bazel +++ b/python/private/libffi/BUILD.bazel @@ -1,6 +0,0 @@ -exports_files([ - "call_test.c", - "closure_test.c", - "complex_test.c", - "seh_test.c", -]) diff --git a/python/private/libffi/call_test.c b/python/private/libffi/call_test.c deleted file mode 100644 index 0a8bf28..0000000 --- a/python/private/libffi/call_test.c +++ /dev/null @@ -1,30 +0,0 @@ -#include - -#include - -static int32_t compare_pointers(const void *left, const void *right) { - return left == right ? 0 : -1; -} - -int main(void) { - ffi_cif cif; - ffi_type *argument_types[] = { - &ffi_type_pointer, - &ffi_type_pointer, - }; - int marker; - void *left = ▮ - void *right = ▮ - void *arguments[] = { - &left, - &right, - }; - int32_t result = -1; - - if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_sint32, - argument_types) != FFI_OK) { - return 1; - } - ffi_call(&cif, FFI_FN(compare_pointers), &result, arguments); - return result != 0; -} diff --git a/python/private/libffi/closure_test.c b/python/private/libffi/closure_test.c deleted file mode 100644 index 0c61b72..0000000 --- a/python/private/libffi/closure_test.c +++ /dev/null @@ -1,54 +0,0 @@ -#include - -#include - -typedef int32_t (*binary_function)(int32_t, int32_t); - -static void -add_with_bias(ffi_cif *cif, void *result, void **arguments, void *user_data) -{ - int32_t left = *(int32_t *)arguments[0]; - int32_t right = *(int32_t *)arguments[1]; - int32_t bias = *(int32_t *)user_data; - - (void)cif; - *(int32_t *)result = left + right + bias; -} - -int -main(void) -{ - ffi_cif cif; - ffi_closure *closure; - ffi_type *argument_types[] = { - &ffi_type_sint32, - &ffi_type_sint32, - }; - void *code; - int32_t bias = 7; - binary_function function; - - if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_sint32, - argument_types) != FFI_OK) { - return 1; - } - - closure = ffi_closure_alloc(sizeof(ffi_closure), &code); - if (closure == NULL) { - return 2; - } - - if (ffi_prep_closure_loc(closure, &cif, add_with_bias, &bias, code) != FFI_OK) { - ffi_closure_free(closure); - return 3; - } - - function = (binary_function)code; - if (function(11, 13) != 31) { - ffi_closure_free(closure); - return 4; - } - - ffi_closure_free(closure); - return 0; -} diff --git a/python/private/libffi/complex_test.c b/python/private/libffi/complex_test.c deleted file mode 100644 index 40ea35b..0000000 --- a/python/private/libffi/complex_test.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -static int -z_is_expected(double complex z) -{ - const double complex expected = 1.25 - 0.5 * I; - return z == expected; -} - -int -main(void) -{ - double complex z = 1.25 - 0.5 * I; - ffi_type *args[1] = {&ffi_type_complex_double}; - void *values[1] = {&z}; - ffi_cif cif; - ffi_arg result; - - if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_sint, args) != FFI_OK) { - return 2; - } - ffi_call(&cif, FFI_FN(z_is_expected), &result, values); - return !result; -} diff --git a/python/private/libffi/seh_test.c b/python/private/libffi/seh_test.c deleted file mode 100644 index e80eef2..0000000 --- a/python/private/libffi/seh_test.c +++ /dev/null @@ -1,49 +0,0 @@ -#include - -#include - -__declspec(noinline) static void raise_access_violation( - void *argument0, void *argument1, void *argument2, void *argument3, - void *argument4, void *argument5, void *argument6, void *argument7, - void *argument8) { - (void)argument0; - (void)argument1; - (void)argument2; - (void)argument3; - (void)argument4; - (void)argument5; - (void)argument6; - (void)argument7; - (void)argument8; - RaiseException(EXCEPTION_ACCESS_VIOLATION, 0, 0, NULL); -} - -int main(void) { - ffi_cif cif; - ffi_type *argument_types[] = { - &ffi_type_pointer, &ffi_type_pointer, &ffi_type_pointer, - &ffi_type_pointer, &ffi_type_pointer, &ffi_type_pointer, - &ffi_type_pointer, &ffi_type_pointer, &ffi_type_pointer, - }; - void *argument = NULL; - void *arguments[] = { - &argument, &argument, &argument, - &argument, &argument, &argument, - &argument, &argument, &argument, - }; - - if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 9, &ffi_type_void, - argument_types) != FFI_OK) { - return 1; - } - - __try { - ffi_call(&cif, FFI_FN(raise_access_violation), NULL, arguments); - } __except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION - ? EXCEPTION_EXECUTE_HANDLER - : EXCEPTION_CONTINUE_SEARCH) { - return 0; - } - - return 2; -} diff --git a/python/private/pyconfig.bzl b/python/private/pyconfig.bzl index 8524f56..56289fe 100644 --- a/python/private/pyconfig.bzl +++ b/python/private/pyconfig.bzl @@ -1266,6 +1266,7 @@ def pyconfig(name, version, windows_pyconfig_template = False): windows_header = ":" + name + "_windows" copy_file( name = name + "_windows", + allow_symlink = True, src = "PC/pyconfig.h.in", out = "PC/pyconfig.h", ) @@ -1346,8 +1347,7 @@ def pyconfig(name, version, windows_pyconfig_template = False): target_policy_checks = select({ "//:darwin_arm64": _darwin_policy_checks(version, 1 if version in ["3.13", "3.14"] else 2), "//:darwin_x86_64": _darwin_policy_checks(version, 1), - "//:linux_arm64": _linux_policy_checks(version), - "//:linux_x86_64": _linux_policy_checks(version), + "@platforms//os:linux": _linux_policy_checks(version), }) autoconf( @@ -1393,8 +1393,7 @@ def pyconfig(name, version, windows_pyconfig_template = False): native.alias( name = name, actual = select({ - "//:windows_arm64": windows_header, - "//:windows_x86_64": windows_header, + "@platforms//os:windows": windows_header, "//conditions:default": ":" + name + "_posix", }), ) diff --git a/python/private/shared_extensions.bzl b/python/private/shared_extensions.bzl index acc98f7..64c8c1e 100644 --- a/python/private/shared_extensions.bzl +++ b/python/private/shared_extensions.bzl @@ -370,10 +370,8 @@ def shared_extensions( windows_outputs.append(":" + testconsole) return struct( - darwin_arm64 = posix_outputs["darwin"], - darwin_x86_64 = posix_outputs["darwin"], - install_only_darwin_arm64 = install_only_posix_outputs["darwin"], - install_only_darwin_x86_64 = install_only_posix_outputs["darwin"], + darwin = posix_outputs["darwin"], + install_only_darwin = install_only_posix_outputs["darwin"], install_only_linux_arm64 = install_only_posix_outputs["linux_arm64"], install_only_linux_x86_64 = install_only_posix_outputs["linux_x86_64"], install_only_windows = install_only_windows_outputs, diff --git a/tools/configure_check_dispositions.json b/tools/configure_check_dispositions.json index 70d6ced..0b451d8 100644 --- a/tools/configure_check_dispositions.json +++ b/tools/configure_check_dispositions.json @@ -341,7 +341,7 @@ }, "_Py_FFI_SUPPORT_C_COMPLEX": { "classification": "DEPENDENCY_CONTRACT", - "justification": "The pinned libffi build passes libffi_complex_test on every supported POSIX target.", + "justification": "The pinned hermetic libffi build provides ffi_type_complex_double on every supported POSIX target.", "expected_values": {"*:*": "1"} }, "_Py_HACL_CAN_COMPILE_VEC128": { @@ -539,12 +539,6 @@ "implementation": "cpython_static_module_manifest adds HAVE_FFI_CLOSURE_ALLOC, HAVE_FFI_PREP_CIF_VAR, and HAVE_FFI_PREP_CLOSURE_LOC only to the CPython 3.11 _ctypes target.", "justification": "CPython 3.11 does not expose these extension-specific definitions through pyconfig.h.in." }, - { - "name": "cpython_3_14_libffi_complex", - "classification": "DEPENDENCY_CONTRACT", - "implementation": "libffi_complex_test performs ffi_prep_cif and ffi_call with ffi_type_complex_double on every supported POSIX target.", - "justification": "The test reproduces CPython 3.14's runtime validation for _Py_FFI_SUPPORT_C_COMPLEX." - }, { "name": "openssl_dependency", "classification": "DEPENDENCY_CONTRACT",