From 8995d67dd90b12ba77c746a63fa145459c9060bb Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 5 Feb 2025 17:35:39 +0000 Subject: [PATCH 1/5] ci: test across Linux, MacOS and Windows runners --- .gitlab-ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 00715ee..ec203d6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,10 @@ include: - component: "${CI_SERVER_HOST}/ci/component/bazelisk/ruleset@v1.2.0" + inputs: + oses: + - linux + - windows + - macos default: tags: -- GitLab From 3716c29d09b8e065f037d2e451f25ba8a1ed7c86 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 5 Feb 2025 17:35:56 +0000 Subject: [PATCH 2/5] ci: test across Bazel 7/8/rc --- .gitlab-ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ec203d6..955dc75 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,6 +5,11 @@ include: - linux - windows - macos + versions: + - 7.4.0 + - 7.x + - 8.x + - last_rc default: tags: -- GitLab From f01f82b79af6d67b172a541beabaee1381dff237 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Thu, 6 Feb 2025 10:04:55 +0000 Subject: [PATCH 3/5] fix(toolchain_test): use `$@` rather than `${@}` `${@}` syntax is not supported on Bash 3.2 which is the default on MacOS. --- toolchain/test/posix.tmpl.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolchain/test/posix.tmpl.sh b/toolchain/test/posix.tmpl.sh index a4f9d6d..8643b9b 100644 --- a/toolchain/test/posix.tmpl.sh +++ b/toolchain/test/posix.tmpl.sh @@ -16,7 +16,7 @@ JUNIT="${XML_OUTPUT_FILE-junit.xml}" readonly JUNIT # Run the toolchain executable and validate the output -"${EXECUTABLE}" "${@}" >stdout.txt 2>stderr.txt && CODE=$? || CODE=$? +"${EXECUTABLE}" "$@" >stdout.txt 2>stderr.txt && CODE=$? || CODE=$? readonly CODE if test "${STATUS}" != "${CODE}"; then echo >&2 "Failed to run (${CODE}): ${EXECUTABLE} ${*}" -- GitLab From 8e99811faa93d3eea5b6d306b77f0b45248bad4a Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Thu, 6 Feb 2025 10:07:13 +0000 Subject: [PATCH 4/5] test: disable runfiles test on MacOS due to non-hermetic `rules_python` `rules_python` expects `install_name_tool` to be available on the system. This is not the case when MacOS does not have developer tools installed. `rules_python` attempts to perform the following: ``` /usr/bin/install_name_tool -id @rpath/libpython3.11.dylib lib/libpython3.11.dylib ``` We should do either: - Upstream support for hermetic `install_name_tool` - Switch the runfiles test to `rules_go` The latter is likely the best choice. --- e2e/toolchain/runfiles/BUILD.bazel | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/toolchain/runfiles/BUILD.bazel b/e2e/toolchain/runfiles/BUILD.bazel index ca44515..a5477b5 100644 --- a/e2e/toolchain/runfiles/BUILD.bazel +++ b/e2e/toolchain/runfiles/BUILD.bazel @@ -12,9 +12,9 @@ py_binary( name = "binary", srcs = ["binary.py"], data = [":fixture.txt"], - # FIXME: `rules_python` binary building on Windows seems borked target_compatible_with = select({ - "@platforms//os:windows": ["@platforms//:incompatible"], + "@platforms//os:windows": ["@platforms//:incompatible"], # FIXME: `rules_python` binary building on Windows seems borked + "@platforms//os:macos": ["@platforms//:incompatible"], # FIXME: `rules_python` is not hermetic on MacOS when developer tools are not installed "//conditions:default": [], }), deps = ["@rules_python//python/runfiles"], -- GitLab From d7f56fc5fa88653abb307a053b5982176bb2eeca Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Thu, 6 Feb 2025 10:20:15 +0000 Subject: [PATCH 5/5] test: switch to `rules_go` for the runfiles test --- e2e/.bazelrc | 3 --- e2e/MODULE.bazel | 12 ------------ e2e/MODULE.bazel.lock | 9 ++------- e2e/toolchain/runfiles/BUILD.bazel | 14 +++++--------- e2e/toolchain/runfiles/binary.go | 28 ++++++++++++++++++++++++++++ e2e/toolchain/runfiles/binary.py | 16 ---------------- 6 files changed, 35 insertions(+), 47 deletions(-) create mode 100644 e2e/toolchain/runfiles/binary.go delete mode 100644 e2e/toolchain/runfiles/binary.py diff --git a/e2e/.bazelrc b/e2e/.bazelrc index d422b08..19b7a92 100644 --- a/e2e/.bazelrc +++ b/e2e/.bazelrc @@ -1,6 +1,3 @@ -# Enable hermetic `rules_python` -common --@rules_python//python/config_settings:bootstrap_impl=script - # Build cache build --experimental_guard_against_concurrent_changes diff --git a/e2e/MODULE.bazel b/e2e/MODULE.bazel index 1ba1a26..b387cdc 100644 --- a/e2e/MODULE.bazel +++ b/e2e/MODULE.bazel @@ -7,7 +7,6 @@ module( bazel_dep(name = "platforms", version = "0.0.10") bazel_dep(name = "rules_go", version = "0.52.0") -bazel_dep(name = "rules_python", version = "1.0.0") bazel_dep(name = "bazel_skylib", version = "1.4.2") bazel_dep(name = "hermetic_cc_toolchain", version = "3.1.0", dev_dependency = True) @@ -18,17 +17,6 @@ local_path_override( path = "..", ) -# We have to avoid the `chmod`/`chown`/`id` unhermetic-ness -# TODO: remove this when `ignore_root_user_error` is hermetic -# https://github.com/bazelbuild/rules_python/issues/2016 -dev = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True) -dev.toolchain( - configure_coverage_tool = True, - # TODO: change the code to use Python for `chmod`/`id` - ignore_root_user_error = True, - python_version = "3.11", -) - which = use_repo_rule("@toolchain_utils//toolchain/local/which:defs.bzl", "toolchain_local_which") which( diff --git a/e2e/MODULE.bazel.lock b/e2e/MODULE.bazel.lock index 86d1397..74f953a 100644 --- a/e2e/MODULE.bazel.lock +++ b/e2e/MODULE.bazel.lock @@ -62,7 +62,6 @@ "https://bcr.bazel.build/modules/protobuf/27.0/MODULE.bazel": "7873b60be88844a0a1d8f80b9d5d20cfbd8495a689b8763e76c6372998d3f64c", "https://bcr.bazel.build/modules/protobuf/27.1/MODULE.bazel": "703a7b614728bb06647f965264967a8ef1c39e09e8f167b3ca0bb1fd80449c0d", "https://bcr.bazel.build/modules/protobuf/29.0-rc2/MODULE.bazel": "6241d35983510143049943fc0d57937937122baf1b287862f9dc8590fc4c37df", - "https://bcr.bazel.build/modules/protobuf/29.0-rc3/MODULE.bazel": "33c2dfa286578573afc55a7acaea3cada4122b9631007c594bf0729f41c8de92", "https://bcr.bazel.build/modules/protobuf/29.0/MODULE.bazel": "319dc8bf4c679ff87e71b1ccfb5a6e90a6dbc4693501d471f48662ac46d04e4e", "https://bcr.bazel.build/modules/protobuf/29.0/source.json": "b857f93c796750eef95f0d61ee378f3420d00ee1dd38627b27193aa482f4f981", "https://bcr.bazel.build/modules/protobuf/3.19.0/MODULE.bazel": "6b5fbb433f760a99a22b18b6850ed5784ef0e9928a72668b66e4d7ccd47db9b0", @@ -103,8 +102,6 @@ "https://bcr.bazel.build/modules/rules_java/7.2.0/MODULE.bazel": "06c0334c9be61e6cef2c8c84a7800cef502063269a5af25ceb100b192453d4ab", "https://bcr.bazel.build/modules/rules_java/7.3.2/MODULE.bazel": "50dece891cfdf1741ea230d001aa9c14398062f2b7c066470accace78e412bc2", "https://bcr.bazel.build/modules/rules_java/7.6.1/MODULE.bazel": "2f14b7e8a1aa2f67ae92bc69d1ec0fa8d9f827c4e17ff5e5f02e91caa3b2d0fe", - "https://bcr.bazel.build/modules/rules_java/8.3.2/MODULE.bazel": "7336d5511ad5af0b8615fdc7477535a2e4e723a357b6713af439fe8cf0195017", - "https://bcr.bazel.build/modules/rules_java/8.5.1/MODULE.bazel": "d8a9e38cc5228881f7055a6079f6f7821a073df3744d441978e7a43e20226939", "https://bcr.bazel.build/modules/rules_java/8.6.1/MODULE.bazel": "f4808e2ab5b0197f094cabce9f4b006a27766beb6a9975931da07099560ca9c2", "https://bcr.bazel.build/modules/rules_java/8.6.1/source.json": "f18d9ad3c4c54945bf422ad584fa6c5ca5b3116ff55a5b1bc77e5c1210be5960", "https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7", @@ -137,8 +134,7 @@ "https://bcr.bazel.build/modules/rules_python/0.31.0/MODULE.bazel": "93a43dc47ee570e6ec9f5779b2e64c1476a6ce921c48cc9a1678a91dd5f8fd58", "https://bcr.bazel.build/modules/rules_python/0.4.0/MODULE.bazel": "9208ee05fd48bf09ac60ed269791cf17fb343db56c8226a720fbb1cdf467166c", "https://bcr.bazel.build/modules/rules_python/0.40.0/MODULE.bazel": "9d1a3cd88ed7d8e39583d9ffe56ae8a244f67783ae89b60caafc9f5cf318ada7", - "https://bcr.bazel.build/modules/rules_python/1.0.0/MODULE.bazel": "898a3d999c22caa585eb062b600f88654bf92efb204fa346fb55f6f8edffca43", - "https://bcr.bazel.build/modules/rules_python/1.0.0/source.json": "b0162a65c6312e45e7912e39abd1a7f8856c2c7e41ecc9b6dc688a6f6400a917", + "https://bcr.bazel.build/modules/rules_python/0.40.0/source.json": "939d4bd2e3110f27bfb360292986bb79fd8dcefb874358ccd6cdaa7bda029320", "https://bcr.bazel.build/modules/rules_shell/0.2.0/MODULE.bazel": "fda8a652ab3c7d8fee214de05e7a9916d8b28082234e8d2c0094505c5268ed3c", "https://bcr.bazel.build/modules/rules_shell/0.3.0/MODULE.bazel": "de4402cd12f4cc8fda2354fce179fdb068c0b9ca1ec2d2b17b3e21b24c1a937b", "https://bcr.bazel.build/modules/rules_shell/0.3.0/source.json": "c55ed591aa5009401ddf80ded9762ac32c358d2517ee7820be981e2de9756cf3", @@ -147,8 +143,7 @@ "https://bcr.bazel.build/modules/stardoc/0.5.6/MODULE.bazel": "c43dabc564990eeab55e25ed61c07a1aadafe9ece96a4efabb3f8bf9063b71ef", "https://bcr.bazel.build/modules/stardoc/0.7.0/MODULE.bazel": "05e3d6d30c099b6770e97da986c53bd31844d7f13d41412480ea265ac9e8079c", "https://bcr.bazel.build/modules/stardoc/0.7.1/MODULE.bazel": "3548faea4ee5dda5580f9af150e79d0f6aea934fc60c1cc50f4efdd9420759e7", - "https://bcr.bazel.build/modules/stardoc/0.7.2/MODULE.bazel": "fc152419aa2ea0f51c29583fab1e8c99ddefd5b3778421845606ee628629e0e5", - "https://bcr.bazel.build/modules/stardoc/0.7.2/source.json": "58b029e5e901d6802967754adf0a9056747e8176f017cfe3607c0851f4d42216", + "https://bcr.bazel.build/modules/stardoc/0.7.1/source.json": "b6500ffcd7b48cd72c29bb67bcac781e12701cc0d6d55d266a652583cfcdab01", "https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/MODULE.bazel": "7298990c00040a0e2f121f6c32544bab27d4452f80d9ce51349b1a28f3005c43", "https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0", "https://bcr.bazel.build/modules/zlib/1.2.12/MODULE.bazel": "3b1a8834ada2a883674be8cbd36ede1b6ec481477ada359cd2d3ddc562340b27", diff --git a/e2e/toolchain/runfiles/BUILD.bazel b/e2e/toolchain/runfiles/BUILD.bazel index a5477b5..75511c8 100644 --- a/e2e/toolchain/runfiles/BUILD.bazel +++ b/e2e/toolchain/runfiles/BUILD.bazel @@ -1,4 +1,4 @@ -load("@rules_python//python:defs.bzl", "py_binary") +load("@rules_go//go:def.bzl", "go_binary") load("@toolchain_utils//toolchain/info:defs.bzl", "toolchain_info") load("@toolchain_utils//toolchain/test:defs.bzl", "toolchain_test") load("@bazel_skylib//rules:build_test.bzl", "build_test") @@ -8,16 +8,12 @@ toolchain_type( visibility = ["//visibility:public"], ) -py_binary( +go_binary( name = "binary", - srcs = ["binary.py"], + srcs = ["binary.go"], data = [":fixture.txt"], - target_compatible_with = select({ - "@platforms//os:windows": ["@platforms//:incompatible"], # FIXME: `rules_python` binary building on Windows seems borked - "@platforms//os:macos": ["@platforms//:incompatible"], # FIXME: `rules_python` is not hermetic on MacOS when developer tools are not installed - "//conditions:default": [], - }), - deps = ["@rules_python//python/runfiles"], + pure = "on", + deps = ["@rules_go//go/runfiles"], ) toolchain_info( diff --git a/e2e/toolchain/runfiles/binary.go b/e2e/toolchain/runfiles/binary.go new file mode 100644 index 0000000..6c68463 --- /dev/null +++ b/e2e/toolchain/runfiles/binary.go @@ -0,0 +1,28 @@ +package main + +import ( + "github.com/bazelbuild/rules_go/go/runfiles" + "io" + "log" + "os" +) + +func main() { + if len(os.Args) > 1 { + log.Fatal("no arguments, please") + } + + path, err := runfiles.Rlocation("_main/toolchain/runfiles/fixture.txt") + if err != nil { + log.Fatalf("no runfile found: %s", err) + } + + fd, err := os.Open(path) + if err != nil { + log.Fatalf("failed to open runfile: %s", err) + } + + if _, err := io.Copy(os.Stdout, fd); err != nil { + log.Fatalf("failed to copy to stdout: %s", err) + } +} diff --git a/e2e/toolchain/runfiles/binary.py b/e2e/toolchain/runfiles/binary.py deleted file mode 100644 index ba464f0..0000000 --- a/e2e/toolchain/runfiles/binary.py +++ /dev/null @@ -1,16 +0,0 @@ -#! /usr/bin/env python3 - -from sys import argv, stdout - -from python.runfiles import Runfiles - -first, *rest = argv -assert not rest, "No arguments, please" - -runfiles = Runfiles.Create() -resolved = runfiles.Rlocation("_main/toolchain/runfiles/fixture.txt") -assert resolved, "No runfile found" - -with open(resolved) as stream: - for line in stream: - stdout.write(line) -- GitLab