diff --git a/MODULE.bazel b/MODULE.bazel index be39664a1d..04549791aa 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -198,6 +198,7 @@ single_version_override( patch_strip = 1, patches = [ "//patches/rules_python:single_import_lib.patch", + "//patches/rules_python:install_name_tool.patch", "//patches/rules_python:lock_extension.patch", ], version = "2.4.6", diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 52744a798d..28f58da550 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -59317,7 +59317,7 @@ }, "@@rules_python+//python/extensions:python.bzl%python": { "os:linux,arch:aarch64": { - "bzlTransitiveDigest": "QgUTRy/OdnNi7uR9hLrlfSTb7bBo5YV16nhznd8HKdE=", + "bzlTransitiveDigest": "8Z7mqxfm12rhCiU+Iz5KRfyXKcINNwgXCJFj0r8VpHI=", "usagesDigest": "Ly043mKod3pIlMqbsOauaTJWdMSwoX0jfjq354u2r7g=", "recordedInputs": [ "ENV:RULES_PYTHON_BZLMOD_DEBUG \\0", @@ -62973,7 +62973,7 @@ } }, "os:linux,arch:amd64": { - "bzlTransitiveDigest": "QgUTRy/OdnNi7uR9hLrlfSTb7bBo5YV16nhznd8HKdE=", + "bzlTransitiveDigest": "8Z7mqxfm12rhCiU+Iz5KRfyXKcINNwgXCJFj0r8VpHI=", "usagesDigest": "Ly043mKod3pIlMqbsOauaTJWdMSwoX0jfjq354u2r7g=", "recordedInputs": [ "ENV:RULES_PYTHON_BZLMOD_DEBUG \\0", @@ -66679,7 +66679,7 @@ } }, "os:osx,arch:aarch64": { - "bzlTransitiveDigest": "QgUTRy/OdnNi7uR9hLrlfSTb7bBo5YV16nhznd8HKdE=", + "bzlTransitiveDigest": "8Z7mqxfm12rhCiU+Iz5KRfyXKcINNwgXCJFj0r8VpHI=", "usagesDigest": "Ly043mKod3pIlMqbsOauaTJWdMSwoX0jfjq354u2r7g=", "recordedInputs": [ "ENV:RULES_PYTHON_BZLMOD_DEBUG \\0", @@ -70335,7 +70335,7 @@ } }, "os:windows,arch:aarch64": { - "bzlTransitiveDigest": "QgUTRy/OdnNi7uR9hLrlfSTb7bBo5YV16nhznd8HKdE=", + "bzlTransitiveDigest": "8Z7mqxfm12rhCiU+Iz5KRfyXKcINNwgXCJFj0r8VpHI=", "usagesDigest": "Ly043mKod3pIlMqbsOauaTJWdMSwoX0jfjq354u2r7g=", "recordedInputs": [ "ENV:RULES_PYTHON_BZLMOD_DEBUG \\0", @@ -73947,7 +73947,7 @@ } }, "os:windows,arch:amd64": { - "bzlTransitiveDigest": "QgUTRy/OdnNi7uR9hLrlfSTb7bBo5YV16nhznd8HKdE=", + "bzlTransitiveDigest": "8Z7mqxfm12rhCiU+Iz5KRfyXKcINNwgXCJFj0r8VpHI=", "usagesDigest": "Ly043mKod3pIlMqbsOauaTJWdMSwoX0jfjq354u2r7g=", "recordedInputs": [ "ENV:RULES_PYTHON_BZLMOD_DEBUG \\0", diff --git a/patches/README.md b/patches/README.md index 7f402eec3f..7dcd34c404 100644 --- a/patches/README.md +++ b/patches/README.md @@ -38,6 +38,7 @@ The Version column is generated from `MODULE.bazel`, and every patch it applies | `rules_swift` | 4.2.2 | `windows_swift_testing.patch` | Root only. The Windows toolchain puts the Swift Testing module and import library directories on the compile and link paths | | `rules_swift` | 4.2.2 | `windows_unknown_vendor.patch` | Root only. Windows target triples use the `unknown` vendor | | `rules_python` | 2.4.6 | `single_import_lib.patch` | `py_extension` on Windows links one CPython import library: the stable ABI one for limited API modules, else the versioned one. It passed both as one linker argument (bazel-contrib/rules_python#4426; drop when a rules_python release has it). Consumer fix: #11418 | +| `rules_python` | 2.4.6 | `install_name_tool.patch` | Root only. The macOS `python_repository` skips the LC_ID_DYLIB fixup, which needs `install_name_tool` on PATH, when `libpython` already names itself `@rpath/` | | `rules_python` | 2.4.6 | `lock_extension.patch` | Root only. The `python` extension is OS and architecture dependent and not reproducible, so a lockfile written on one host does not pin another | | `rules_py` | 2.0.0-alpha.11 | `py_cc_toolchain_platform.patch` | `py_cc_toolchain` picks the cc toolchain for the target platform. Consumer fix: #11398 | | `rules_py` | 2.0.0-alpha.11 | `native_sdist_toolchain_flags.patch` | Native sdist builds get the cc toolchain flags (aspect-build/rules_py#1664). Consumer fix: #11398 | @@ -45,7 +46,7 @@ The Version column is generated from `MODULE.bazel`, and every patch it applies | `rules_py` | 2.0.0-alpha.11 | `venv_bin_files.patch` | The runtime sets `venv_bin_files`, so `java_binary` analyzes on Windows; there the venv's `python.exe` and DLLs are file symlinks and wheels join `sys.path` through `.pth` lines, so the launcher does not hit `CreateProcess failed` and wheel imports resolve (aspect-build/rules_py#1670). Consumer fix: #11398 | | `rules_py` | 2.0.0-alpha.11 | `host_interpreter_windows_arm64.patch` | rules_py can see its `python_3_13_aarch64_pc_windows_msvc` interpreter, so sdist builds load on Windows ARM64 hosts (aspect-build/rules_py#1676). Consumer fix: #11398 | | `rules_py` | 2.0.0-alpha.11 | `external_repo_pytest_paths.patch` | `py_pytest_main` finds `.pytest_paths` for targets in an external repository under `..//`. Consumer fix: #11398 | -| `rules_py` | 2.0.0-alpha.11 | `host_libc_glibc.patch` | The uv host repo reports glibc 2.28 on Linux without running `ldd`, so it fetches where no host `ldd` is on PATH. Consumer fix: #12482 | +| `rules_py` | 2.0.0-alpha.11 | `host_libc_glibc.patch` | The uv host repo reports glibc 2.28 on Linux without running `ldd` and libsystem 14.0 on macOS without running `sw_vers`, so it fetches where neither is on PATH. Consumer fix: #12482 | | `rules_py` | 2.0.0-alpha.11 | `win32_x86_32.patch` | The `win32` wheel tag matches `@platforms//cpu:x86_32`, so x86_64 Windows selects the `win_amd64` wheel. Consumer fix: #12277 | | `hermetic_launcher` | 0.0.17 | `windows_arm64_toolchains.patch` | Registers template and finalizer toolchains for the prebuilt aarch64 Windows stubs (hermeticbuild/hermetic-launcher#94). Consumer fix: #11416 | | `avro-cpp` | 1.12.0.bcr.1 | `iterator.patch` | Missing std includes (``, ``, ``) with libc++, added to the headers that use them; `Exception.hh` includes `fmt/format.h` for fmt 12. Consumer fix: #6592 | diff --git a/patches/rules_py/host_libc_glibc.patch b/patches/rules_py/host_libc_glibc.patch index 23e371dcaa..2322aabf07 100644 --- a/patches/rules_py/host_libc_glibc.patch +++ b/patches/rules_py/host_libc_glibc.patch @@ -1,11 +1,13 @@ --- a/uv/private/host/repository.bzl +++ b/uv/private/host/repository.bzl -@@ -25,35 +25,9 @@ +@@ -23,38 +23,10 @@ + os = _translate_os(rctx.os.name) + if os == "osx": - res = rctx.execute(["sw_vers", "-productVersion"]) -+ res = rctx.execute(["/usr/bin/sw_vers", "-productVersion"]) - ver = res.stdout.strip().split(".") - return "libsystem", "{}.{}".format(ver[0], ver[1]) +- ver = res.stdout.strip().split(".") +- return "libsystem", "{}.{}".format(ver[0], ver[1]) ++ return "libsystem", "14.0" elif os == "linux": - res = rctx.execute(["ldd", "--version"]) diff --git a/patches/rules_python/BUILD.bazel b/patches/rules_python/BUILD.bazel index dee864a05a..e949fa441b 100644 --- a/patches/rules_python/BUILD.bazel +++ b/patches/rules_python/BUILD.bazel @@ -1,6 +1,7 @@ load("@rules_dx//core/quality:fixtures.bzl", "real_source_target") exports_files([ + "install_name_tool.patch", "lock_extension.patch", "single_import_lib.patch", ]) diff --git a/patches/rules_python/install_name_tool.patch b/patches/rules_python/install_name_tool.patch new file mode 100644 index 0000000000..2164d98c89 --- /dev/null +++ b/patches/rules_python/install_name_tool.patch @@ -0,0 +1,22 @@ +--- a/python/private/python_repository.bzl ++++ b/python/private/python_repository.bzl +@@ -215,12 +215,13 @@ + # it appears in the Bazel workspace as its LC_ID_DYLIB using + # the `install_name_tool` bundled with macOS. + dylib = "libpython{}.dylib".format(python_short_version) +- repo_utils.execute_checked( +- rctx, +- op = "python_repository.FixUpDyldIdPath", +- arguments = [repo_utils.which_checked(rctx, "install_name_tool"), "-id", "@rpath/{}".format(dylib), "lib/{}".format(dylib)], +- logger = logger, +- ) ++ if "@rpath/{}".format(dylib) not in rctx.read("lib/{}".format(dylib)): ++ repo_utils.execute_checked( ++ rctx, ++ op = "python_repository.FixUpDyldIdPath", ++ arguments = [repo_utils.which_checked(rctx, "install_name_tool"), "-id", "@rpath/{}".format(dylib), "lib/{}".format(dylib)], ++ logger = logger, ++ ) + + _create_pycache_symlinks(rctx, logger) + python_bin = "python.exe" if ("windows" in platform) else "bin/python3" diff --git a/tools/testing/hermetic/src/lib.rs b/tools/testing/hermetic/src/lib.rs index aec87ee8bf..d7f9b177f5 100644 --- a/tools/testing/hermetic/src/lib.rs +++ b/tools/testing/hermetic/src/lib.rs @@ -364,6 +364,12 @@ pub fn miss_marker(os: &str) -> &'static str { } } +/// The bash Bazel's repository rules run `patch_cmds` with. +pub const UNIX_BAZEL_SH: &str = "BAZEL_SH=/bin/bash"; + +/// The arguments before the command a Unix probe records: `env -i`, its variables, `sh -c SCRIPT` and the workspace. +const UNIX_ENV_PREFIX: usize = 11; + pub const HOME_RC: &str = "build --action_env=DX_HOME_CONFIG=present\n"; pub const LEAKS_PACKAGE: &str = "dx_hermetic_leaks"; @@ -1401,6 +1407,7 @@ impl Session { format!("PATH={}", self.applets.display()), format!("BAZELISK_HOME={}", self.bazelisk_home.display()), format!("XDG_CACHE_HOME={}", cache_home(probe.output_root).display()), + UNIX_BAZEL_SH.to_owned(), "/bin/sh".to_owned(), "-c".to_owned(), "cd \"$0\" && \"$@\"; rc=$?; \"$1\" \"$2\" \"$3\" \"$4\" shutdown >/dev/null 2>&1; exit $rc" @@ -1518,6 +1525,7 @@ impl Session { format!("PATH={}:{}", bin.display(), self.applets.display()), format!("BAZELISK_HOME={}", self.bazelisk_home.display()), format!("XDG_CACHE_HOME={}", cache_home(output_root).display()), + UNIX_BAZEL_SH.to_owned(), "/bin/sh".to_owned(), "-c".to_owned(), "cd \"$0\" && \"$@\"; rc=$?; bazel --max_idle_secs=60 shutdown >/dev/null 2>&1; exit $rc" @@ -1526,7 +1534,7 @@ impl Session { self.manifest.dx.to_string_lossy().into_owned(), ]; invocation.extend(args); - let recorded = invocation.get(10..).unwrap_or_default().to_vec(); + let recorded = invocation.get(UNIX_ENV_PREFIX..).unwrap_or_default().to_vec(); // Lint exits 1 when it reports findings, which the manifest then compares. let expect = if command == "lint" { Expect::Findings @@ -1569,7 +1577,7 @@ impl Session { }); } let argv = self.bazel_argv(probe); - let recorded = argv.get(10..).unwrap_or_default().to_vec(); + let recorded = argv.get(UNIX_ENV_PREFIX..).unwrap_or_default().to_vec(); self.execute(Exec { name: &probe.name, net: probe.net, diff --git a/tools/testing/hermetic/src/tests.rs b/tools/testing/hermetic/src/tests.rs index f36a8bc60b..665a07eb9f 100644 --- a/tools/testing/hermetic/src/tests.rs +++ b/tools/testing/hermetic/src/tests.rs @@ -1137,7 +1137,7 @@ fn check_windows_sh_rejects_the_wsl_stub_and_an_empty_path() { fn bazel_argv_pins_startup_and_build_flags_before_the_targets() { let argv = fixture_session().bazel_argv(&fixture_probe()); assert_eq!( - argv[..6], + argv[..7], [ "/usr/bin/env", "-i", @@ -1145,6 +1145,7 @@ fn bazel_argv_pins_startup_and_build_flags_before_the_targets() { "PATH=/q/applets", "BAZELISK_HOME=/q/bazelisk", "XDG_CACHE_HOME=/q/cold_cache", + "BAZEL_SH=/bin/bash", ] ); let gc_size = format!( @@ -1156,7 +1157,7 @@ fn bazel_argv_pins_startup_and_build_flags_before_the_targets() { dx_process::DISK_CACHE_GC_MAX_AGE ); assert_eq!( - argv[9..], + argv[10..], [ "/q/consumer ws", "/q/bin/bazelisk", @@ -1180,7 +1181,7 @@ fn bazel_argv_pins_startup_and_build_flags_before_the_targets() { "//...", ] ); - assert!(argv[8].contains("shutdown"), "{}", argv[8]); + assert!(argv[9].contains("shutdown"), "{}", argv[9]); } #[test]