From ef46df052bda76dc85a11e867b7d02de216f2327 Mon Sep 17 00:00:00 2001 From: lalten Date: Sat, 4 Apr 2026 01:29:54 +0200 Subject: [PATCH] Correctly run containerized tests on macOS --- .bazelrc | 1 - BUILD | 1 + MODULE.bazel | 5 ++- tests/BUILD | 1 + tests/build_working_directory/BUILD | 1 + tests/cc_runfiles/container/BUILD | 16 ++++++-- tests/rules_pycross/BUILD | 40 +++++++++++++------ .../rules_pycross/test_appimage_isolated.yaml | 2 +- 8 files changed, 47 insertions(+), 20 deletions(-) diff --git a/.bazelrc b/.bazelrc index a24607b8..1c5f8588 100644 --- a/.bazelrc +++ b/.bazelrc @@ -19,5 +19,4 @@ test --test_output=errors test --test_verbose_timeout_warnings common --enable_platform_specific_config -build:macos --deleted_packages=tests/rules_pycross,tests/cc_runfiles/container build:macos --macos_minimum_os=10.15 diff --git a/BUILD b/BUILD index 770b2c60..68f4987b 100644 --- a/BUILD +++ b/BUILD @@ -8,6 +8,7 @@ load("//:deps.bzl", "ARCHS") "@platforms//os:linux", "@platforms//cpu:" + arch, ], + visibility = ["//:__subpackages__"], ) for arch in ARCHS.keys()] compile_pip_requirements( diff --git a/MODULE.bazel b/MODULE.bazel index c94de5be..6846e3ba 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -13,8 +13,9 @@ bazel_dep(name = "rules_shell", version = "0.7.1") bazel_dep(name = "squashfs-tools", version = "4.7.5") bazel_dep(name = "bazel_lib", version = "3.2.2", dev_dependency = True) -bazel_dep(name = "container_structure_test", version = "1.22.1", dev_dependency = True) +bazel_dep(name = "container_structure_test", version = "1.21.1", dev_dependency = True) bazel_dep(name = "libmagic", version = "5.47", dev_dependency = True) +bazel_dep(name = "llvm", version = "0.7.0", dev_dependency = True) bazel_dep(name = "rules_oci", version = "2.3.0", dev_dependency = True) bazel_dep(name = "rules_pkg", version = "1.2.0", dev_dependency = True) bazel_dep(name = "rules_pycross", version = "0.8.1", dev_dependency = True) @@ -22,6 +23,8 @@ bazel_dep(name = "rules_testing", version = "0.9.0", dev_dependency = True) bazel_dep(name = "stardoc", version = "0.8.1", dev_dependency = True) bazel_dep(name = "with_cfg.bzl", version = "0.14.6", dev_dependency = True) +register_toolchains("@llvm//toolchain:all") + single_version_override( module_name = "stardoc", patches = ["//third_party:stardoc.diff"], # https://github.com/bazelbuild/stardoc/pull/303 diff --git a/tests/BUILD b/tests/BUILD index 19463ee8..9e217640 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -155,6 +155,7 @@ py_test( appimage( name = "external_bin.appimage", binary = "@rules_python//tools:wheelmaker", + target_compatible_with = ["@platforms//os:linux"], ) sh_test( diff --git a/tests/build_working_directory/BUILD b/tests/build_working_directory/BUILD index c292e5af..bc61f5b3 100644 --- a/tests/build_working_directory/BUILD +++ b/tests/build_working_directory/BUILD @@ -10,6 +10,7 @@ sh_binary( appimage( name = "test.appimage", binary = ":entrypoint", + target_compatible_with = ["@platforms//os:linux"], ) sh_test( diff --git a/tests/cc_runfiles/container/BUILD b/tests/cc_runfiles/container/BUILD index c04a8313..48aa261b 100644 --- a/tests/cc_runfiles/container/BUILD +++ b/tests/cc_runfiles/container/BUILD @@ -1,3 +1,4 @@ +load("@bazel_lib//lib:transitions.bzl", "platform_transition_filegroup") load("@container_structure_test//:defs.bzl", "container_structure_test") load("@rules_appimage//appimage:appimage.bzl", "appimage") load("@rules_cc//cc:defs.bzl", "cc_binary") @@ -13,14 +14,13 @@ cc_binary( "//tests/cc_runfiles:file.txt", "@appimage_runtime_aarch64//file", ], - linkopts = ["-static"], # avoid issues with glibcxx version mismatch inside the container + target_compatible_with = ["@platforms//os:linux"], deps = ["@rules_cc//cc/runfiles"], ) appimage( name = "bin.appimage", binary = ":bin", - tags = ["requires-fakeroot"], target_compatible_with = ["@platforms//os:linux"], ) @@ -50,14 +50,22 @@ oci_image( ], ) +platform_transition_filegroup( + name = "container_structure_test_image_linux", + srcs = [":container_structure_test_image"], + target_platform = select({ + "@platforms//cpu:aarch64": "@llvm//platforms:linux_aarch64_musl", + "//conditions:default": "@llvm//platforms:linux_amd64_musl", + }), +) + container_structure_test( name = "container_structure_test", timeout = "short", configs = ["test_appimage_isolated.yaml"], - image = "container_structure_test_image", + image = ":container_structure_test_image_linux", platform = select({ "@platforms//cpu:aarch64": "linux/arm64", "//conditions:default": "linux/amd64", }), - target_compatible_with = ["@platforms//os:linux"], ) diff --git a/tests/rules_pycross/BUILD b/tests/rules_pycross/BUILD index 47f056a0..80712a05 100644 --- a/tests/rules_pycross/BUILD +++ b/tests/rules_pycross/BUILD @@ -1,8 +1,9 @@ +load("@bazel_lib//lib:transitions.bzl", "platform_transition_filegroup") load("@container_structure_test//:defs.bzl", "container_structure_test") -load("@rules_appimage//appimage:appimage.bzl", "appimage_test") +load("@rules_appimage//appimage:appimage.bzl", "appimage") load("@rules_oci//oci:defs.bzl", "oci_image") load("@rules_pkg//pkg:tar.bzl", "pkg_tar") -load("@rules_python//python:defs.bzl", "py_test") +load("@rules_python//python:defs.bzl", "py_binary", "py_test") py_test( name = "test", @@ -11,31 +12,44 @@ py_test( deps = ["@pdm_deps//:humanize"], ) -appimage_test( - name = "test.appimage", - timeout = "short", - binary = ":test", - tags = ["requires-fakeroot"], +py_binary( + name = "bin", + srcs = ["test.py"], + main = "test.py", + deps = ["@pdm_deps//:humanize"], +) + +appimage( + name = "bin.appimage", + binary = ":bin", + target_compatible_with = ["@platforms//os:linux"], ) pkg_tar( - name = "test.appimage.tar", - testonly = True, - srcs = [":test.appimage"], + name = "bin.appimage.tar", + srcs = [":bin.appimage"], ) oci_image( name = "container_structure_test_image", - testonly = True, base = "@python3-slim", - tars = [":test.appimage.tar"], + tars = [":bin.appimage.tar"], +) + +platform_transition_filegroup( + name = "container_structure_test_image_linux", + srcs = [":container_structure_test_image"], + target_platform = select({ + "@platforms//cpu:aarch64": "@llvm//platforms:linux_aarch64_musl", + "//conditions:default": "@llvm//platforms:linux_amd64_musl", + }), ) container_structure_test( name = "container_structure_test", timeout = "short", configs = ["test_appimage_isolated.yaml"], - image = "container_structure_test_image", + image = ":container_structure_test_image_linux", platform = select({ "@platforms//cpu:aarch64": "linux/arm64", "//conditions:default": "linux/amd64", diff --git a/tests/rules_pycross/test_appimage_isolated.yaml b/tests/rules_pycross/test_appimage_isolated.yaml index 65d6df6c..91d7fa1f 100644 --- a/tests/rules_pycross/test_appimage_isolated.yaml +++ b/tests/rules_pycross/test_appimage_isolated.yaml @@ -2,5 +2,5 @@ schemaVersion: 2.0.0 commandTests: - name: run test - command: /test.appimage + command: /bin.appimage args: [--appimage-extract-and-run]