From 9076606a3ba4e4cf08f5d7d4c782583c9062539a Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 21 Nov 2025 21:27:25 +0000 Subject: [PATCH 1/2] Add support for using directory instead of all files This has major implications on bazel merkle tree and sandboxing perf. This requires some nesting because of the linked issue. I left the old files target around for compatibility (although targets moved) --- bazel-cc-sysroot-generator | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/bazel-cc-sysroot-generator b/bazel-cc-sysroot-generator index 748f41f..ac2a170 100755 --- a/bazel-cc-sysroot-generator +++ b/bazel-cc-sysroot-generator @@ -220,7 +220,7 @@ def _cleanup_linux_sysroot( def _write_bazel_files(sysroot_dir: Path) -> None: name = sysroot_dir.name - (sysroot_dir / "BUILD.bazel").write_text(f"""\ + (sysroot_dir / "BUILD.bazel").write_text("""\ load("@bazel_skylib//rules/directory:directory.bzl", "directory") directory( @@ -229,8 +229,15 @@ directory( visibility = ["//visibility:public"], ) +# NOTE: Using this is better for merkle tree performance filegroup( - name = "{name}", + name = "directory", + srcs = ["."], + visibility = ["//visibility:public"], +) + +filegroup( + name = "all_files", srcs = glob(["**"]), visibility = ["//visibility:public"], ) @@ -242,6 +249,16 @@ bazel_dep(name = "bazel_skylib", version = "1.7.1") """) +# https://github.com/bazelbuild/bazel/issues/27028 +def _nest_all_files(sysroot_dir: Path) -> None: + nested_dir = sysroot_dir / "sysroot" + nested_dir.mkdir() + for item in sysroot_dir.iterdir(): + if item.name == "sysroot": + continue + shutil.move(item, nested_dir / item.name) + + def _archive(sysroot_dir: Path) -> None: # https://stackoverflow.com/questions/1094841/get-a-human-readable-version-of-a-file-size def sizeof_fmt(num: float) -> str: @@ -335,6 +352,7 @@ def _generate_ubuntu_sysroot(os_name: str, platform: dict[str, Any]) -> None: _download_packages(os_name, arch, repositories, packages, sysroot_dir) _cleanup_linux_sysroot(arch, deleted_patterns, sysroot_dir) _write_bazel_files(sysroot_dir) + _nest_all_files(sysroot_dir) _archive(sysroot_dir) @@ -359,6 +377,7 @@ def _generate_macos_sysroot(platform: dict[str, Any]) -> None: _validate_relative_symlinks(sysroot_dir) _write_bazel_files(sysroot_dir) + _nest_all_files(sysroot_dir) _archive(sysroot_dir) From 537bd88e8174af23de81aa2babd39a8dc5a13ed3 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 21 Nov 2025 21:30:01 +0000 Subject: [PATCH 2/2] don't move --- bazel-cc-sysroot-generator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bazel-cc-sysroot-generator b/bazel-cc-sysroot-generator index ac2a170..834c1b1 100755 --- a/bazel-cc-sysroot-generator +++ b/bazel-cc-sysroot-generator @@ -254,7 +254,7 @@ def _nest_all_files(sysroot_dir: Path) -> None: nested_dir = sysroot_dir / "sysroot" nested_dir.mkdir() for item in sysroot_dir.iterdir(): - if item.name == "sysroot": + if item.name in {"sysroot", "MODULE.bazel"}: continue shutil.move(item, nested_dir / item.name)