From ee3f24aadd8e731a718ca741916716b554e118aa Mon Sep 17 00:00:00 2001 From: Manuel Naranjo Date: Fri, 14 Jun 2024 12:04:52 +0200 Subject: [PATCH 01/11] Enable building with multiple bazel versions Adding CI that can build into multiple bazel versions, right now focusing on the latest of each of the LTS version --- .github/workflows/action.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index def1794..81d87da 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -8,9 +8,26 @@ on: jobs: + # TODO: rename to build-bazel-6 once we move into bazel 7 as the default, to be deprecated by Dec 2025 build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: bazelbuild/setup-bazelisk@v1 - run: bazel build //... && bazel test //... + + # TODO: deprecate by Jan 2025 https://bazel.build/release + build-bazel-5: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: bazelbuild/setup-bazelisk@v1 + - run: export USE_BAZEL_VERSION=5.x && bazel build //... && bazel test //... + + # TODO: rename to build once we move into bazel 7 as the default + build-bazel-7: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: bazelbuild/setup-bazelisk@v1 + - run: export USE_BAZEL_VERSION=6.x && bazel build //... && bazel test //... From 9efa413575e044023b9889accf8a499c96cbbf06 Mon Sep 17 00:00:00 2001 From: Manuel Naranjo Date: Fri, 14 Jun 2024 12:09:46 +0200 Subject: [PATCH 02/11] bazel: bump version Making 6.5.0 the default bazel version --- .bazelversion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bazelversion b/.bazelversion index 831446c..f22d756 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -5.1.0 +6.5.0 From 683141c46a6c2c03e10a0a29c2c7726d544d1a28 Mon Sep 17 00:00:00 2001 From: Manuel Naranjo Date: Fri, 14 Jun 2024 12:12:22 +0200 Subject: [PATCH 03/11] bazel: moving to rules_pkg Our tests where using the old and deprecated bundled pkg_tar rule, now we need to grab it from rules_pkg instead. Adding the results of running buildifier over the files. --- BUILD.bazel | 10 ++++------ WORKSPACE | 12 ++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index c258f99..5b42f56 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,20 +1,18 @@ load("@bazel_gazelle//:def.bzl", "gazelle") +load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier") +load("@rules_pkg//pkg:tar.bzl", "pkg_tar") +load("//bazeldnf:def.bzl", "bazeldnf") +load(":deps.bzl", "rpmtree", "tar2files") # gazelle:prefix github.com/rmohr/bazeldnf # gazelle:resolve go github.com/bazelbuild/buildtools/build @com_github_bazelbuild_buildtools//build:go_default_library # gazelle:resolve go github.com/bazelbuild/buildtools/edit @com_github_bazelbuild_buildtools//edit:go_default_library gazelle(name = "gazelle") -load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier") - buildifier( name = "buildifier", ) -load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar") -load("//:deps.bzl", "rpmtree", "tar2files") -load("//:def.bzl", "bazeldnf") - bazeldnf( name = "bazeldnf", ) diff --git a/WORKSPACE b/WORKSPACE index b0e032a..d1c1f73 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -79,3 +79,15 @@ rpm( "https://storage.googleapis.com/builddeps/2ebb715341b57a74759aff415e0ff53df528c49abaa7ba5b794b4047461fa8d6", ], ) + +http_archive( + name = "rules_pkg", + sha256 = "cad05f864a32799f6f9022891de91ac78f30e0fa07dc68abac92a628121b5b11", + urls = [ + "https://github.com/bazelbuild/rules_pkg/releases/download/1.0.0/rules_pkg-1.0.0.tar.gz", + ], +) + +load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") + +rules_pkg_dependencies() From 6d33d40185995b09ff0e625c528ada15799ac849 Mon Sep 17 00:00:00 2001 From: Manuel Naranjo Date: Fri, 14 Jun 2024 12:13:57 +0200 Subject: [PATCH 04/11] bazel: adopt prebuilt_buildifier Turns out there's a prebuilt buildifier that speeds up things a lot by not having to rebuild the binary on each checkout of the repository --- BUILD.bazel | 2 +- WORKSPACE | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/BUILD.bazel b/BUILD.bazel index 5b42f56..91273ea 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,5 +1,5 @@ load("@bazel_gazelle//:def.bzl", "gazelle") -load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier") +load("@buildifier_prebuilt//:rules.bzl", "buildifier") load("@rules_pkg//pkg:tar.bzl", "pkg_tar") load("//bazeldnf:def.bzl", "bazeldnf") load(":deps.bzl", "rpmtree", "tar2files") diff --git a/WORKSPACE b/WORKSPACE index d1c1f73..6f52866 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -91,3 +91,20 @@ http_archive( load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") rules_pkg_dependencies() + +http_archive( + name = "buildifier_prebuilt", + sha256 = "8ada9d88e51ebf5a1fdff37d75ed41d51f5e677cdbeafb0a22dda54747d6e07e", + strip_prefix = "buildifier-prebuilt-6.4.0", + urls = [ + "http://github.com/keith/buildifier-prebuilt/archive/6.4.0.tar.gz", + ], +) + +load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps") + +buildifier_prebuilt_deps() + +load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains") + +buildifier_prebuilt_register_toolchains() From d6cd5e01f1051cbaeb250f76403aeadbd005cd62 Mon Sep 17 00:00:00 2001 From: Manuel Naranjo Date: Fri, 14 Jun 2024 12:19:35 +0200 Subject: [PATCH 05/11] bazel: adopt aspect.dev bazelrc suggested flags We all know the joke of Bazel just got it's 1000+1 flag each time a new feature gets released, the aspect.dev folks have condensed a few flags that speed up things and make sure bazel is used in the right way, so let's start adopting it. --- .aspect/bazelrc/BUILD.bazel | 5 ++ .aspect/bazelrc/bazel6.bazelrc | 27 +++++++++++ .aspect/bazelrc/bazel7.bazelrc | 11 +++++ .aspect/bazelrc/ci.bazelrc | 66 +++++++++++++++++++++++++ .aspect/bazelrc/convenience.bazelrc | 28 +++++++++++ .aspect/bazelrc/correctness.bazelrc | 75 +++++++++++++++++++++++++++++ .aspect/bazelrc/debug.bazelrc | 19 ++++++++ .aspect/bazelrc/javascript.bazelrc | 11 +++++ .aspect/bazelrc/performance.bazelrc | 20 ++++++++ .bazelrc | 16 ++++++ .gitignore | 1 + WORKSPACE | 17 +++++++ 12 files changed, 296 insertions(+) create mode 100644 .aspect/bazelrc/BUILD.bazel create mode 100644 .aspect/bazelrc/bazel6.bazelrc create mode 100644 .aspect/bazelrc/bazel7.bazelrc create mode 100644 .aspect/bazelrc/ci.bazelrc create mode 100644 .aspect/bazelrc/convenience.bazelrc create mode 100644 .aspect/bazelrc/correctness.bazelrc create mode 100644 .aspect/bazelrc/debug.bazelrc create mode 100644 .aspect/bazelrc/javascript.bazelrc create mode 100644 .aspect/bazelrc/performance.bazelrc create mode 100644 .bazelrc diff --git a/.aspect/bazelrc/BUILD.bazel b/.aspect/bazelrc/BUILD.bazel new file mode 100644 index 0000000..bfa2fb3 --- /dev/null +++ b/.aspect/bazelrc/BUILD.bazel @@ -0,0 +1,5 @@ +"Aspect bazelrc presets; see https://docs.aspect.build/guides/bazelrc" + +load("@aspect_bazel_lib//lib:bazelrc_presets.bzl", "write_aspect_bazelrc_presets") + +write_aspect_bazelrc_presets(name = "update_aspect_bazelrc_presets") diff --git a/.aspect/bazelrc/bazel6.bazelrc b/.aspect/bazelrc/bazel6.bazelrc new file mode 100644 index 0000000..f6a155c --- /dev/null +++ b/.aspect/bazelrc/bazel6.bazelrc @@ -0,0 +1,27 @@ +# Speed up all builds by not checking if external repository files have been modified. +# Docs: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java#L244 +build --noexperimental_check_external_repository_files +fetch --noexperimental_check_external_repository_files +query --noexperimental_check_external_repository_files + +# Directories used by sandboxed non-worker execution may be reused to avoid unnecessary setup costs. +# Save time on Sandbox creation and deletion when many of the same kind of action run during the +# build. +# Docs: https://bazel.build/reference/command-line-reference#flag--reuse_sandbox_directories +build --reuse_sandbox_directories + +# Avoid this flag being enabled by remote_download_minimal or remote_download_toplevel +# See https://meroton.com/blog/bazel-6-errors-build-without-the-bytes/ +build --noexperimental_action_cache_store_output_metadata + +# Speed up all builds by not checking if output files have been modified. Lets you make changes to +# the output tree without triggering a build for local debugging. For example, you can modify +# [rules_js](https://github.com/aspect-build/rules_js) 3rd party npm packages in the output tree +# when local debugging. +# Docs: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/pkgcache/PackageOptions.java#L185 +# NB: This flag is in bazel6.bazelrc as when used in Bazel 7 is has been observed to break +# "build without the bytes" --remote_download_outputs=toplevel. See https://github.com/aspect-build/bazel-lib/pull/711 +# for more info. +build --noexperimental_check_output_files +fetch --noexperimental_check_output_files +query --noexperimental_check_output_files diff --git a/.aspect/bazelrc/bazel7.bazelrc b/.aspect/bazelrc/bazel7.bazelrc new file mode 100644 index 0000000..212c26e --- /dev/null +++ b/.aspect/bazelrc/bazel7.bazelrc @@ -0,0 +1,11 @@ +# Speed up all builds by not checking if external repository files have been modified. +# Docs: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java#L244 +build --noexperimental_check_external_repository_files +fetch --noexperimental_check_external_repository_files +query --noexperimental_check_external_repository_files + +# Directories used by sandboxed non-worker execution may be reused to avoid unnecessary setup costs. +# Save time on Sandbox creation and deletion when many of the same kind of action run during the +# build. +# Docs: https://bazel.build/reference/command-line-reference#flag--reuse_sandbox_directories +build --reuse_sandbox_directories diff --git a/.aspect/bazelrc/ci.bazelrc b/.aspect/bazelrc/ci.bazelrc new file mode 100644 index 0000000..11aae33 --- /dev/null +++ b/.aspect/bazelrc/ci.bazelrc @@ -0,0 +1,66 @@ +# Set this flag to enable re-tries of failed tests on CI. +# When any test target fails, try one or more times. This applies regardless of whether the "flaky" +# tag appears on the target definition. +# This is a tradeoff: legitimately failing tests will take longer to report, +# but we can paper over flaky tests that pass most of the time. +# The alternative is to mark every flaky test with the `flaky = True` attribute, but this requires +# the buildcop to make frequent code edits. +# Not recommended for local builds so that the flakiness is observed during development and thus +# is more likely to get fixed. +# Note that when passing after the first attempt, Bazel will give a special "FLAKY" status. +# Docs: https://bazel.build/docs/user-manual#flaky-test-attempts +test --flaky_test_attempts=2 + +# Announce all announces command options read from the bazelrc file(s) when starting up at the +# beginning of each Bazel invocation. This is very useful on CI to be able to inspect what Bazel rc +# settings are being applied on each run. +# Docs: https://bazel.build/docs/user-manual#announce-rc +build --announce_rc + +# Add a timestamp to each message generated by Bazel specifying the time at which the message was +# displayed. +# Docs: https://bazel.build/docs/user-manual#show-timestamps +build --show_timestamps + +# Only show progress every 60 seconds on CI. +# We want to find a compromise between printing often enough to show that the build isn't stuck, +# but not so often that we produce a long log file that requires a lot of scrolling. +# https://bazel.build/reference/command-line-reference#flag--show_progress_rate_limit +build --show_progress_rate_limit=60 + +# Use cursor controls in screen output. +# Docs: https://bazel.build/docs/user-manual#curses +build --curses=yes + +# Use colors to highlight output on the screen. Set to `no` if your CI does not display colors. +# Docs: https://bazel.build/docs/user-manual#color +build --color=yes + +# The terminal width in columns. Configure this to override the default value based on what your CI system renders. +# Docs: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/runtime/UiOptions.java#L151 +build --terminal_columns=143 + +###################################### +# Generic remote cache configuration # +###################################### + +# Only download remote outputs of top level targets to the local machine. +# Docs: https://bazel.build/reference/command-line-reference#flag--remote_download_toplevel +build --remote_download_toplevel + +# The maximum amount of time to wait for remote execution and cache calls. +# https://bazel.build/reference/command-line-reference#flag--remote_timeout +build --remote_timeout=3600 + +# Upload locally executed action results to the remote cache. +# Docs: https://bazel.build/reference/command-line-reference#flag--remote_upload_local_results +build --remote_upload_local_results + +# Fall back to standalone local execution strategy if remote execution fails. If the grpc remote +# cache connection fails, it will fail the build, add this so it falls back to the local cache. +# Docs: https://bazel.build/reference/command-line-reference#flag--remote_local_fallback +build --remote_local_fallback + +# Fixes builds hanging on CI that get the TCP connection closed without sending RST packets. +# Docs: https://bazel.build/reference/command-line-reference#flag--grpc_keepalive_time +build --grpc_keepalive_time=30s diff --git a/.aspect/bazelrc/convenience.bazelrc b/.aspect/bazelrc/convenience.bazelrc new file mode 100644 index 0000000..c674569 --- /dev/null +++ b/.aspect/bazelrc/convenience.bazelrc @@ -0,0 +1,28 @@ +# Attempt to build & test every target whose prerequisites were successfully built. +# Docs: https://bazel.build/docs/user-manual#keep-going +build --keep_going + +# Output test errors to stderr so users don't have to `cat` or open test failure log files when test +# fail. This makes the log noiser in exchange for reducing the time-to-feedback on test failures for +# users. +# Docs: https://bazel.build/docs/user-manual#test-output +test --test_output=errors + +# Show the output files created by builds that requested more than one target. This helps users +# locate the build outputs in more cases +# Docs: https://bazel.build/docs/user-manual#show-result +build --show_result=20 + +# Bazel picks up host-OS-specific config lines from bazelrc files. For example, if the host OS is +# Linux and you run bazel build, Bazel picks up lines starting with build:linux. Supported OS +# identifiers are `linux`, `macos`, `windows`, `freebsd`, and `openbsd`. Enabling this flag is +# equivalent to using `--config=linux` on Linux, `--config=windows` on Windows, etc. +# Docs: https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config +common --enable_platform_specific_config + +# Output a heap dump if an OOM is thrown during a Bazel invocation +# (including OOMs due to `--experimental_oom_more_eagerly_threshold`). +# The dump will be written to `/.heapdump.hprof`. +# You may need to configure CI to capture this artifact and upload for later use. +# Docs: https://bazel.build/reference/command-line-reference#flag--heap_dump_on_oom +common --heap_dump_on_oom diff --git a/.aspect/bazelrc/correctness.bazelrc b/.aspect/bazelrc/correctness.bazelrc new file mode 100644 index 0000000..a599f6d --- /dev/null +++ b/.aspect/bazelrc/correctness.bazelrc @@ -0,0 +1,75 @@ +# Do not upload locally executed action results to the remote cache. +# This should be the default for local builds so local builds cannot poison the remote cache. +# It should be flipped to `--remote_upload_local_results` on CI +# by using `--bazelrc=.aspect/bazelrc/ci.bazelrc`. +# Docs: https://bazel.build/reference/command-line-reference#flag--remote_upload_local_results +build --noremote_upload_local_results + +# Don't allow network access for build actions in the sandbox. +# Ensures that you don't accidentally make non-hermetic actions/tests which depend on remote +# services. +# Developers should tag targets with `tags=["requires-network"]` to opt-out of the enforcement. +# Docs: https://bazel.build/reference/command-line-reference#flag--sandbox_default_allow_network +build --sandbox_default_allow_network=false + +# Warn if a test's timeout is significantly longer than the test's actual execution time. +# Bazel's default for test_timeout is medium (5 min), but most tests should instead be short (1 min). +# While a test's timeout should be set such that it is not flaky, a test that has a highly +# over-generous timeout can hide real problems that crop up unexpectedly. +# For instance, a test that normally executes in a minute or two should not have a timeout of +# ETERNAL or LONG as these are much, much too generous. +# Docs: https://bazel.build/docs/user-manual#test-verbose-timeout-warnings +test --test_verbose_timeout_warnings + +# Allow the Bazel server to check directory sources for changes. Ensures that the Bazel server +# notices when a directory changes, if you have a directory listed in the srcs of some target. +# Recommended when using +# [copy_directory](https://github.com/aspect-build/bazel-lib/blob/main/docs/copy_directory.md) and +# [rules_js](https://github.com/aspect-build/rules_js) since npm package are source directories +# inputs to copy_directory actions. +# Docs: https://bazel.build/reference/command-line-reference#flag--host_jvm_args +startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1 + +# Allow exclusive tests to run in the sandbox. Fixes a bug where Bazel doesn't enable sandboxing for +# tests with `tags=["exclusive"]`. +# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_exclusive_test_sandboxed +test --incompatible_exclusive_test_sandboxed + +# Use a static value for `PATH` and does not inherit `LD_LIBRARY_PATH`. Doesn't let environment +# variables like `PATH` sneak into the build, which can cause massive cache misses when they change. +# Use `--action_env=ENV_VARIABLE` if you want to inherit specific environment variables from the +# client, but note that doing so can prevent cross-user caching if a shared cache is used. +# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_strict_action_env +build --incompatible_strict_action_env + +# Propagate tags from a target declaration to the actions' execution requirements. +# Ensures that tags applied in your BUILD file, like `tags=["no-remote"]` +# get propagated to actions created by the rule. +# Without this option, you rely on rules authors to manually check the tags you passed +# and apply relevant ones to the actions they create. +# See https://github.com/bazelbuild/bazel/issues/8830 for details. +# Docs: https://bazel.build/reference/command-line-reference#flag--experimental_allow_tags_propagation +build --experimental_allow_tags_propagation +fetch --experimental_allow_tags_propagation +query --experimental_allow_tags_propagation + +# Do not automatically create `__init__.py` files in the runfiles of Python targets. Fixes the wrong +# default that comes from Google's internal monorepo by using `__init__.py` to delimit a Python +# package. Precisely, when a `py_binary` or `py_test` target has `legacy_create_init` set to `auto (the +# default), it is treated as false if and only if this flag is set. See +# https://github.com/bazelbuild/bazel/issues/10076. +# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_default_to_explicit_init_py +build --incompatible_default_to_explicit_init_py + +# Set default value of `allow_empty` to `False` in `glob()`. This prevents a common mistake when +# attempting to use `glob()` to match files in a subdirectory that is opaque to the current package +# because it contains a BUILD file. See https://github.com/bazelbuild/bazel/issues/8195. +# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_disallow_empty_glob +common --incompatible_disallow_empty_glob + +# Always download coverage files for tests from the remote cache. By default, coverage files are not +# downloaded on test result cahce hits when --remote_download_minimal is enabled, making it impossible +# to generate a full coverage report. +# Docs: https://bazel.build/reference/command-line-reference#flag--experimental_fetch_all_coverage_outputs +# detching remote cache results +test --experimental_fetch_all_coverage_outputs diff --git a/.aspect/bazelrc/debug.bazelrc b/.aspect/bazelrc/debug.bazelrc new file mode 100644 index 0000000..bfb0bdd --- /dev/null +++ b/.aspect/bazelrc/debug.bazelrc @@ -0,0 +1,19 @@ +############################################################ +# Use `bazel test --config=debug` to enable these settings # +############################################################ + +# Stream stdout/stderr output from each test in real-time. +# Docs: https://bazel.build/docs/user-manual#test-output +test:debug --test_output=streamed + +# Run one test at a time. +# Docs: https://bazel.build/reference/command-line-reference#flag--test_strategy +test:debug --test_strategy=exclusive + +# Prevent long running tests from timing out. +# Docs: https://bazel.build/docs/user-manual#test-timeout +test:debug --test_timeout=9999 + +# Always run tests even if they have cached results. +# Docs: https://bazel.build/docs/user-manual#cache-test-results +test:debug --nocache_test_results diff --git a/.aspect/bazelrc/javascript.bazelrc b/.aspect/bazelrc/javascript.bazelrc new file mode 100644 index 0000000..ace9d60 --- /dev/null +++ b/.aspect/bazelrc/javascript.bazelrc @@ -0,0 +1,11 @@ +# Aspect recommended Bazel flags when using Aspect's JavaScript rules: https://github.com/aspect-build/rules_js +# Docs for Node.js flags: https://nodejs.org/en/docs/guides/debugging-getting-started/#command-line-options + +# Support for debugging Node.js tests. Use bazel run with `--config=debug` to turn on the NodeJS +# inspector agent. The node process will break before user code starts and wait for the debugger to +# connect. Pass the --inspect-brk option to all tests which enables the node inspector agent. See +# https://nodejs.org/de/docs/guides/debugging-getting-started/#command-line-options for more +# details. +# Docs: https://nodejs.org/en/docs/guides/debugging-getting-started/#command-line-options +run:debug -- --node_options=--inspect-brk +test:debug --test_env=NODE_OPTIONS=--inspect-brk diff --git a/.aspect/bazelrc/performance.bazelrc b/.aspect/bazelrc/performance.bazelrc new file mode 100644 index 0000000..acc48c5 --- /dev/null +++ b/.aspect/bazelrc/performance.bazelrc @@ -0,0 +1,20 @@ +# Don't apply `--noremote_upload_local_results` and `--noremote_accept_cached` to the disk cache. +# If you have both `--noremote_upload_local_results` and `--disk_cache`, then this fixes a bug where +# Bazel doesn't write to the local disk cache as it treats as a remote cache. +# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_remote_results_ignore_disk +build --incompatible_remote_results_ignore_disk + +# Directories used by sandboxed non-worker execution may be reused to avoid unnecessary setup costs. +# Save time on Sandbox creation and deletion when many of the same kind of action run during the +# build. +# No longer experimental in Bazel 6: https://github.com/bazelbuild/bazel/commit/c1a95501a5611878e5cc43a3cc531f2b9e47835b +# Docs: https://bazel.build/reference/command-line-reference#flag--reuse_sandbox_directories +build --experimental_reuse_sandbox_directories + +# Do not build runfiles symlink forests for external repositories under +# `.runfiles/wsname/external/repo` (in addition to `.runfiles/repo`). This reduces runfiles & +# sandbox creation times & prevents accidentally depending on this feature which may flip to off by +# default in the future. Note, some rules may fail under this flag, please file issues with the rule +# author. +# Docs: https://bazel.build/reference/command-line-reference#flag--legacy_external_runfiles +build --nolegacy_external_runfiles diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 0000000..64ccc73 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,16 @@ +# Import Aspect bazelrc presets +try-import %workspace%/.aspect/bazelrc/local/bazel7.bazelrc # will only work in bazel7+ +try-import %workspace%/.aspect/bazelrc/bazel6.bazelrc # will only work in bazel6+ +import %workspace%/.aspect/bazelrc/convenience.bazelrc +import %workspace%/.aspect/bazelrc/correctness.bazelrc +import %workspace%/.aspect/bazelrc/debug.bazelrc +import %workspace%/.aspect/bazelrc/javascript.bazelrc +import %workspace%/.aspect/bazelrc/performance.bazelrc + +# Specific project flags go here if we have some + +# Load any settings & overrides specific to the current user from `.bazelrc.user`. +# This file should appear in `.gitignore` so that settings are not shared with team members. This +# should be last statement in this config so the user configuration is able to overwrite flags from +# this file. See https://bazel.build/configure/best-practices#bazelrc-file. +try-import %workspace%/.bazelrc.user diff --git a/.gitignore b/.gitignore index f09076a..4e5c253 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ repo.yaml .bazeldnf dist cmd/cmd +.bazelrc.user diff --git a/WORKSPACE b/WORKSPACE index 6f52866..4966bfb 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -108,3 +108,20 @@ buildifier_prebuilt_deps() load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains") buildifier_prebuilt_register_toolchains() + +http_archive( + name = "aspect_bazel_lib", + sha256 = "6d758a8f646ecee7a3e294fbe4386daafbe0e5966723009c290d493f227c390b", + strip_prefix = "bazel-lib-2.7.7", + url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.7.7/bazel-lib-v2.7.7.tar.gz", +) + +load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "aspect_bazel_lib_register_toolchains") + +# Required bazel-lib dependencies + +aspect_bazel_lib_dependencies() + +# Register bazel-lib toolchains + +aspect_bazel_lib_register_toolchains() From 431844e7a5f3fadb159b1b7b71cf43f22fe8d216 Mon Sep 17 00:00:00 2001 From: Manuel Naranjo Date: Sun, 16 Jun 2024 09:26:50 +0200 Subject: [PATCH 06/11] bazel: bump skylib bumping skylib so we can use the platforms repository properly now --- WORKSPACE | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 4966bfb..2e43970 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -4,10 +4,10 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "bazel_skylib", - sha256 = "f24ab666394232f834f74d19e2ff142b0af17466ea0c69a3f4c276ee75f6efce", + sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.0/bazel-skylib-1.4.0.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.0/bazel-skylib-1.4.0.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", ], ) From 8bed31bb59c86a24526f8b3045c9f3a8eaa4f236 Mon Sep 17 00:00:00 2001 From: Manuel Naranjo Date: Sun, 16 Jun 2024 09:30:22 +0200 Subject: [PATCH 07/11] bazel: refactor the repository external API Following conventions from other rules so that there's a directory that can be entirely built from other workspaces with `bazel build @bazeldnf//bazeldnf/...`. It should be self contained and inject as many dependencies into the parent workspace as needed. --- BUILD.bazel | 3 +- README.md | 13 +++---- WORKSPACE | 2 +- bazeldnf/BUILD.bazel | 9 +++++ bazeldnf/defs.bzl | 22 +++++++++++ bazeldnf/deps.bzl | 77 ++++++++++++++++++++++++++++++++++++++ def.bzl | 6 ++- deps.bzl | 83 ++++++++++++----------------------------- hack/prepare-release.sh | 27 ++------------ 9 files changed, 147 insertions(+), 95 deletions(-) create mode 100644 bazeldnf/BUILD.bazel create mode 100644 bazeldnf/defs.bzl create mode 100644 bazeldnf/deps.bzl diff --git a/BUILD.bazel b/BUILD.bazel index 91273ea..dac6aa5 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,8 +1,7 @@ load("@bazel_gazelle//:def.bzl", "gazelle") load("@buildifier_prebuilt//:rules.bzl", "buildifier") load("@rules_pkg//pkg:tar.bzl", "pkg_tar") -load("//bazeldnf:def.bzl", "bazeldnf") -load(":deps.bzl", "rpmtree", "tar2files") +load("//bazeldnf:defs.bzl", "bazeldnf", "rpmtree", "tar2files") # gazelle:prefix github.com/rmohr/bazeldnf # gazelle:resolve go github.com/bazelbuild/buildtools/build @com_github_bazelbuild_buildtools//build:go_default_library diff --git a/README.md b/README.md index c002fd7..99c5c19 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ The `rpm` rule represents a pure RPM dependency. This dependency is not processed in any way. They can be added to your `WORKSPACE` file like this: ```python -load("@bazeldnf//:deps.bzl", "rpm") +load("@bazeldnf//bazeldnf:deps.bzl", "rpm") rpm( name = "libvirt-devel-6.1.0-2.fc32.x86_64.rpm", @@ -29,7 +29,7 @@ rpm( `tar` package. `rpmtree` rules can be added like this to your `BUILD` files: ```python -load("@bazeldnf//:deps.bzl", "rpmtree") +load("@bazeldnf//bazeldnf:defs.bzl", "rpmtree") rpmtree( name = "rpmarchive", @@ -91,7 +91,7 @@ http_archive( ], ) -load("@bazeldnf//:deps.bzl", "bazeldnf_dependencies") +load("@bazeldnf//bazeldnf:deps.bzl", "bazeldnf_dependencies") bazeldnf_dependencies() ``` @@ -99,7 +99,7 @@ bazeldnf_dependencies() Define the `bazeldnf` executable rule in your `BUILD.bazel` file: ```python -load("@bazeldnf//:def.bzl", "bazeldnf") +load("@bazeldnf//bazeldnf:defs.bzl", "bazeldnf") bazeldnf(name = "bazeldnf") ``` @@ -121,7 +121,7 @@ a subset of libraries and headers and providing them to `cc_library` targets. An example: ```python -load("@bazeldnf//:deps.bzl", "rpm", "rpmtree", "tar2files") +load("@bazeldnf//bazeldnf:defs.bzl", "rpm", "rpmtree", "tar2files") tar2files( name = "libvirt-libs", @@ -170,8 +170,7 @@ and create `tar2files` rules for you, based on a provided set of libraries. First define a target like this: ```python -load("@bazeldnf//:deps.bzl", "rpm", "rpmtree", "tar2files") -load("@bazeldnf//:def.bzl", "bazeldnf") +load("@bazeldnf//bazeldnf:defs.bzl", "bazeldnf", "rpm", "rpmtree", "tar2files") bazeldnf( name = "ldd", diff --git a/WORKSPACE b/WORKSPACE index 2e43970..254d3a6 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -49,7 +49,7 @@ http_archive( load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") load("//:build_deps.bzl", "bazeldnf_build_dependencies") -load("//:deps.bzl", "bazeldnf_dependencies", "rpm") +load("//bazeldnf:deps.bzl", "bazeldnf_dependencies", "rpm") # gazelle:repository_macro build_deps.bzl%bazeldnf_build_dependencies bazeldnf_build_dependencies() diff --git a/bazeldnf/BUILD.bazel b/bazeldnf/BUILD.bazel new file mode 100644 index 0000000..a467dd9 --- /dev/null +++ b/bazeldnf/BUILD.bazel @@ -0,0 +1,9 @@ +# this directory contains the public API from bazeldnf, anything on this directory +# should be buildable withtout dev dependencies +# + +# bazeldnf toolchain type +toolchain_type( + name = "toolchain", + visibility = ["//visibility:public"], +) diff --git a/bazeldnf/defs.bzl b/bazeldnf/defs.bzl new file mode 100644 index 0000000..4680e46 --- /dev/null +++ b/bazeldnf/defs.bzl @@ -0,0 +1,22 @@ +""" +Public API to use bazeldnf from other repositories +""" + +load( + "@bazeldnf//internal:bazeldnf.bzl", + _bazeldnf = "bazeldnf", +) +load( + "@bazeldnf//internal:rpmtree.bzl", + _rpmtree = "rpmtree", + _tar2files = "tar2files", +) +load( + "@bazeldnf//internal:xattrs.bzl", + _xattrs = "xattrs", +) + +bazeldnf = _bazeldnf +rpmtree = _rpmtree +tar2files = _tar2files +xattrs = _xattrs diff --git a/bazeldnf/deps.bzl b/bazeldnf/deps.bzl new file mode 100644 index 0000000..63a4f4d --- /dev/null +++ b/bazeldnf/deps.bzl @@ -0,0 +1,77 @@ +"""bazeldnf public dependency for WORKSPACE""" + +load( + "@bazel_tools//tools/build_defs/repo:http.bzl", + "http_archive", + "http_file", +) +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +load( + "@bazeldnf//internal:rpm.bzl", + _rpm = "rpm", +) + +rpm = _rpm + +def bazeldnf_dependencies(): + """bazeldnf dependencies when consuming the repo externally""" + http_file( + name = "bazeldnf-linux-amd64", + executable = True, + sha256 = "7e1035d8bd2f25b787b04843f4d6a05e7cdbd3995926497c2a587e52da6262a8", + urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-amd64"], + ) + http_file( + name = "bazeldnf-linux-arm64", + executable = True, + sha256 = "d954b785bfd79dbbd66a2f3df02b0d3a51f1fed4508a6d88fda13a9d24c878cc", + urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-arm64"], + ) + http_file( + name = "bazeldnf-darwin-amd64", + executable = True, + sha256 = "92afc7f6475981adf9ae32b563b051869d433d8d8c9666e28a1c1c6e840394cd", + urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-darwin-amd64"], + ) + http_file( + name = "bazeldnf-darwin-arm64", + executable = True, + sha256 = "c5e99ed72448026ee63259a0a28440f8b43a125414fa312edbd569c2976515a3", + urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-darwin-arm64"], + ) + http_file( + name = "bazeldnf-linux-ppc64", + executable = True, + sha256 = "9d5337c1afe4bab858742718ac4c230d9ca368299cb97c50078eef14ae180922", + urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-ppc64"], + ) + http_file( + name = "bazeldnf-linux-ppc64le", + executable = True, + sha256 = "7ea4db00947914bc1c51e8f042fe220a3167c65815c487eccd0c541ecfa78aa1", + urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-ppc64le"], + ) + http_file( + name = "bazeldnf-linux-s390x", + executable = True, + sha256 = "09aa4abcb1d85da11642889826b982ef90547eb32099fc8177456c92f66a4cfd", + urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-s390x"], + ) + maybe( + http_archive, + name = "bazel_skylib", + sha256 = "f24ab666394232f834f74d19e2ff142b0af17466ea0c69a3f4c276ee75f6efce", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.0/bazel-skylib-1.4.0.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.0/bazel-skylib-1.4.0.tar.gz", + ], + ) + maybe( + http_archive, + name = "platforms", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", + "https://github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", + ], + sha256 = "218efe8ee736d26a3572663b374a253c012b716d8af0c07e842e82f238a0a7ee", + ) diff --git a/def.bzl b/def.bzl index fa61449..119dd1f 100644 --- a/def.bzl +++ b/def.bzl @@ -1,6 +1,8 @@ load( - "@bazeldnf//internal:bazeldnf.bzl", + "@bazeldnf//bazeldnf:defs.bzl", _bazeldnf = "bazeldnf", ) -bazeldnf = _bazeldnf +def bazeldnf(*args, **kwargs): + print("import this method from @bazeldnf//bazeldnf:defs.bzl") + _bazeldnf(*args, **kwargs) diff --git a/deps.bzl b/deps.bzl index c5d500a..e85cea8 100644 --- a/deps.bzl +++ b/deps.bzl @@ -1,69 +1,34 @@ +"""legacy API for bazeldnf dependencies""" + load( - "@bazel_tools//tools/build_defs/repo:http.bzl", - "http_file", -) -load( - "@bazeldnf//internal:rpm.bzl", + "@bazeldnf//bazeldnf:defs.bzl", _rpm = "rpm", -) -load( - "@bazeldnf//internal:rpmtree.bzl", _rpmtree = "rpmtree", -) -load( - "@bazeldnf//internal:rpmtree.bzl", _tar2files = "tar2files", + _xattrs = "xattrs", ) load( - "@bazeldnf//internal:xattrs.bzl", - _xattrs = "xattrs", + "@bazeldnf//bazeldnf:deps.bzl", + _bazeldnf_dependencies = "bazeldnf_dependencies", ) -rpm = _rpm -rpmtree = _rpmtree -tar2files = _tar2files -xattrs = _xattrs +def rpm(*args, **kwargs): + print("import rpm method from @bazeldnf//bazeldnf:defs.bzl") + _rpm(*args, **kwargs) + +def rpmtree(*args, **kwargs): + print("import rpmtree method from @bazeldnf//bazeldnf:defs.bzl") + _rpmtree(*args, **kwargs) + +def tar2files(*args, **kwargs): + print("import tar2files method from @bazeldnf//bazeldnf:defs.bzl") + _tar2files(*args, **kwargs) + +def xattrs(*args, **kwargs): + print("import xattrs method from @bazeldnf//bazeldnf:defs.bzl") + _xattrs(*args, **kwargs) def bazeldnf_dependencies(): - http_file( - name = "bazeldnf-linux-amd64", - executable = True, - sha256 = "7e1035d8bd2f25b787b04843f4d6a05e7cdbd3995926497c2a587e52da6262a8", - urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-amd64"], - ) - http_file( - name = "bazeldnf-linux-arm64", - executable = True, - sha256 = "d954b785bfd79dbbd66a2f3df02b0d3a51f1fed4508a6d88fda13a9d24c878cc", - urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-arm64"], - ) - http_file( - name = "bazeldnf-darwin-amd64", - executable = True, - sha256 = "92afc7f6475981adf9ae32b563b051869d433d8d8c9666e28a1c1c6e840394cd", - urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-darwin-amd64"], - ) - http_file( - name = "bazeldnf-darwin-arm64", - executable = True, - sha256 = "c5e99ed72448026ee63259a0a28440f8b43a125414fa312edbd569c2976515a3", - urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-darwin-arm64"], - ) - http_file( - name = "bazeldnf-linux-ppc64", - executable = True, - sha256 = "9d5337c1afe4bab858742718ac4c230d9ca368299cb97c50078eef14ae180922", - urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-ppc64"], - ) - http_file( - name = "bazeldnf-linux-ppc64le", - executable = True, - sha256 = "7ea4db00947914bc1c51e8f042fe220a3167c65815c487eccd0c541ecfa78aa1", - urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-ppc64le"], - ) - http_file( - name = "bazeldnf-linux-s390x", - executable = True, - sha256 = "09aa4abcb1d85da11642889826b982ef90547eb32099fc8177456c92f66a4cfd", - urls = ["https://github.com/rmohr/bazeldnf/releases/download/v0.5.9/bazeldnf-v0.5.9-linux-s390x"], - ) + """Download bazeldnf dependencies""" + print("import bazeldnf_dependencies method from @bazeldnf//bazeldnf:deps.bzl") + _bazeldnf_dependencies() diff --git a/hack/prepare-release.sh b/hack/prepare-release.sh index 3629dfd..9477341 100755 --- a/hack/prepare-release.sh +++ b/hack/prepare-release.sh @@ -25,7 +25,7 @@ function write_arch() { arch=$2 DIGEST=$(sha256sum dist/bazeldnf-${VERSION}-${os}-${arch} | cut -d " " -f 1) - cat <>./deps.bzl + cat <>bazeldnf/deps.bzl http_file( name = "bazeldnf-${os}-${arch}", executable = True, @@ -44,32 +44,11 @@ build_arch linux ppc64 build_arch linux ppc64le build_arch linux s390x -cat <./deps.bzl +cat <bazeldnf/deps.bzl load( "@bazel_tools//tools/build_defs/repo:http.bzl", "http_file", ) -load( - "@bazeldnf//internal:rpm.bzl", - _rpm = "rpm", -) -load( - "@bazeldnf//internal:rpmtree.bzl", - _rpmtree = "rpmtree", -) -load( - "@bazeldnf//internal:rpmtree.bzl", - _tar2files = "tar2files", -) -load( - "@bazeldnf//internal:xattrs.bzl", - _xattrs = "xattrs", -) - -rpm = _rpm -rpmtree = _rpmtree -tar2files = _tar2files -xattrs = _xattrs def bazeldnf_dependencies(): EOT @@ -102,7 +81,7 @@ http_archive( ], ) -load("@bazeldnf//:deps.bzl", "bazeldnf_dependencies") +load("@bazeldnf//bazeldnf:deps.bzl", "bazeldnf_dependencies") bazeldnf_dependencies() \`\`\` From fd6ef20cfce4aec7cc07d87aea238fc18194a43a Mon Sep 17 00:00:00 2001 From: Manuel Naranjo Date: Sun, 16 Jun 2024 09:32:41 +0200 Subject: [PATCH 08/11] bazel: adopt toolchain approach By providing a proper toolchain instead of an alias we remove the dependency on rules_go when someone uses bazeldnf externally, but also works better for cross compilation and other kind of processes --- .bazelrc | 14 +++++- .github/workflows/action.yml | 5 +- WORKSPACE | 4 ++ bazeldnf/toolchain.bzl | 94 ++++++++++++++++++++++++++++++++++++ cmd/BUILD.bazel | 23 ++++----- internal/bazeldnf.bzl | 14 +++--- internal/rpmtree.bzl | 20 +++----- 7 files changed, 134 insertions(+), 40 deletions(-) create mode 100644 bazeldnf/toolchain.bzl diff --git a/.bazelrc b/.bazelrc index 64ccc73..9c719c2 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,14 +1,24 @@ # Import Aspect bazelrc presets try-import %workspace%/.aspect/bazelrc/local/bazel7.bazelrc # will only work in bazel7+ -try-import %workspace%/.aspect/bazelrc/bazel6.bazelrc # will only work in bazel6+ +import %workspace%/.aspect/bazelrc/bazel6.bazelrc # will only work in bazel6+ import %workspace%/.aspect/bazelrc/convenience.bazelrc import %workspace%/.aspect/bazelrc/correctness.bazelrc import %workspace%/.aspect/bazelrc/debug.bazelrc -import %workspace%/.aspect/bazelrc/javascript.bazelrc import %workspace%/.aspect/bazelrc/performance.bazelrc # Specific project flags go here if we have some +# register toolchains with prebuilts +common:prebuilt-toolchain --extra_toolchains=@bazeldnf_prebuilt//:linux-amd64-toolchain +common:prebuilt-toolchain --extra_toolchains=@bazeldnf_prebuilt//:linux-arm64-toolchain +common:prebuilt-toolchain --extra_toolchains=@bazeldnf_prebuilt//:linux-ppc64-toolchain +common:prebuilt-toolchain --extra_toolchains=@bazeldnf_prebuilt//:linux-ppc64le-toolchain +common:prebuilt-toolchain --extra_toolchains=@bazeldnf_prebuilt//:linux-s390x-toolchain +common:prebuilt-toolchain --extra_toolchains=@bazeldnf_prebuilt//:darwin-amd64-toolchain +common:prebuilt-toolchain --extra_toolchains=@bazeldnf_prebuilt//:darwin-arm64-toolchain + +common:built-toolchain --extra_toolchains=//cmd:bazeldnf-host-toolchain + # Load any settings & overrides specific to the current user from `.bazelrc.user`. # This file should appear in `.gitignore` so that settings are not shared with team members. This # should be last statement in this config so the user configuration is able to overwrite flags from diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 81d87da..c9362a7 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -8,13 +8,12 @@ on: jobs: - # TODO: rename to build-bazel-6 once we move into bazel 7 as the default, to be deprecated by Dec 2025 - build: + build-and-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: bazelbuild/setup-bazelisk@v1 - - run: bazel build //... && bazel test //... + - run: bazel build --config=built-toolchain //... && bazel test --config=built-toolchain //... # TODO: deprecate by Jan 2025 https://bazel.build/release build-bazel-5: diff --git a/WORKSPACE b/WORKSPACE index 254d3a6..6b7049e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -125,3 +125,7 @@ aspect_bazel_lib_dependencies() # Register bazel-lib toolchains aspect_bazel_lib_register_toolchains() + +load("@bazeldnf//bazeldnf:toolchain.bzl", "bazeldnf_prebuilt_register_toolchains") + +bazeldnf_prebuilt_register_toolchains(name = "bazeldnf_prebuilt", register_toolchains = False) diff --git a/bazeldnf/toolchain.bzl b/bazeldnf/toolchain.bzl new file mode 100644 index 0000000..63a9854 --- /dev/null +++ b/bazeldnf/toolchain.bzl @@ -0,0 +1,94 @@ +def _bazeldnf_toolchain(ctx): + return [ + platform_common.ToolchainInfo( + _tool = ctx.executable.tool, + ), + ] + +bazeldnf_toolchain = rule( + _bazeldnf_toolchain, + attrs = { + "tool": attr.label( + allow_single_file = True, + mandatory = True, + cfg = "exec", + executable = True, + doc = "bazeldnf executable", + ), + }, + provides = [platform_common.ToolchainInfo], +) + +PLATFORMS = [ + "linux-amd64", + "linux-arm64", + "linux-ppc64", + "linux-ppc64le", + "linux-s390x", + "darwin-amd64", + "darwin-arm64", +] + +BAZELDNF_TOOLCHAIN = "@bazeldnf//bazeldnf:toolchain" + +def declare_toolchain(toolchain_prefix, os, arch): # buildifier: disable=unnamed-macro + """Create the custom and native toolchain for a platform + + Args: + toolchain_prefix: The tool the toolchain is being used for + os: The OS the toolchain is compatible with + arch: The arch the toolchain is compatible with + """ + + name = "%s-%s" % (os, arch) + bazeldnf_toolchain( + name = name, + tool = "@%s-%s//file" % (toolchain_prefix, name), + ) + + if os == "darwin": + os = "osx" + if arch == "amd64": + arch = "x86_64" + if arch == "ppc64": + arch = "ppc" + + native.toolchain( + name = name + "-toolchain", + toolchain_type = "@bazeldnf//bazeldnf:toolchain", + exec_compatible_with = [ + "@platforms//os:%s" % os, + "@platforms//cpu:%s" % arch, + ], + toolchain = name, + ) + +def _bazeldnf_prebuilt_setup_impl(repo_ctx): + toolchain_prefix = repo_ctx.attr.toolchain_prefix + build_bzl = 'load("@bazeldnf//bazeldnf:toolchain.bzl", "declare_toolchain")' + + for plat in PLATFORMS: + os, arch = plat.split("-") + build_bzl += '\ndeclare_toolchain( toolchain_prefix = "{toolchain_prefix}", os = "{os}", arch = "{arch}")'.format( + toolchain_prefix = toolchain_prefix, + os = os, + arch = arch, + ) + repo_ctx.file("BUILD.bazel", build_bzl) + +_bazeldnf_prebuilt_setup = repository_rule( + implementation = _bazeldnf_prebuilt_setup_impl, + attrs = { + "toolchain_prefix": attr.string(), + }, +) + +def bazeldnf_prebuilt_register_toolchains(name, toolchain_prefix = "bazeldnf", register_toolchains = True): + _bazeldnf_prebuilt_setup( + name = name, + toolchain_prefix = toolchain_prefix, + ) + + if register_toolchains: + toolchains = ["@%s//:%s-toolchain" % (name, x) for x in PLATFORMS] + native.register_toolchains(*toolchains) diff --git a/cmd/BUILD.bazel b/cmd/BUILD.bazel index 67b0911..1e5eae3 100644 --- a/cmd/BUILD.bazel +++ b/cmd/BUILD.bazel @@ -1,4 +1,5 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") +load("//bazeldnf:toolchain.bzl", "bazeldnf_toolchain") go_library( name = "cmd_lib", @@ -48,17 +49,13 @@ go_binary( visibility = ["//visibility:public"], ) -alias( - name = "prebuilt", - actual = select({ - "@io_bazel_rules_go//go/platform:linux_amd64": "@bazeldnf-linux-amd64//file:downloaded", - "@io_bazel_rules_go//go/platform:linux_arm64": "@bazeldnf-linux-arm64//file:downloaded", - "@io_bazel_rules_go//go/platform:linux_ppc64": "@bazeldnf-linux-ppc64//file:downloaded", - "@io_bazel_rules_go//go/platform:linux_ppc64le": "@bazeldnf-linux-ppc64le//file:downloaded", - "@io_bazel_rules_go//go/platform:linux_s390x": "@bazeldnf-linux-s390x//file:downloaded", - "@io_bazel_rules_go//go/platform:darwin_amd64": "@bazeldnf-darwin-amd64//file:downloaded", - "@io_bazel_rules_go//go/platform:darwin_arm64": "@bazeldnf-darwin-arm64//file:downloaded", - "//conditions:default": "cmd", - }), - visibility = ["//visibility:public"], +bazeldnf_toolchain( + name = "host-toolchain", + tool = ":cmd" +) + +toolchain( + name = "bazeldnf-host-toolchain", + toolchain_type = "//bazeldnf:toolchain", + toolchain = ":host-toolchain", ) diff --git a/internal/bazeldnf.bzl b/internal/bazeldnf.bzl index f17870c..5cfb51a 100644 --- a/internal/bazeldnf.bzl +++ b/internal/bazeldnf.bzl @@ -1,4 +1,5 @@ load("@bazel_skylib//lib:shell.bzl", "shell") +load("//bazeldnf:toolchain.bzl", "BAZELDNF_TOOLCHAIN") def _bazeldnf_impl(ctx): transitive_dependencies = [] @@ -16,8 +17,10 @@ def _bazeldnf_impl(ctx): for lib in ctx.attr.libs: args += [lib] + toolchain = ctx.toolchains[BAZELDNF_TOOLCHAIN] + substitutions = { - "@@BAZELDNF_SHORT_PATH@@": shell.quote(ctx.executable._bazeldnf.short_path), + "@@BAZELDNF_SHORT_PATH@@": shell.quote(toolchain._tool.short_path), "@@ARGS@@": shell.array_literal(args), } ctx.actions.expand_template( @@ -27,7 +30,7 @@ def _bazeldnf_impl(ctx): is_executable = True, ) runfiles = ctx.runfiles( - files = [ctx.executable._bazeldnf], + files = [toolchain._tool], transitive_files = depset([], transitive = transitive_dependencies), ) return [DefaultInfo( @@ -51,17 +54,12 @@ _bazeldnf = rule( "rpmtree": attr.string(), "libs": attr.string_list(), "tar": attr.label(allow_single_file = True), - "_bazeldnf": attr.label( - default = "@bazeldnf//cmd:prebuilt", - cfg = "host", - executable = True, - allow_files = True, - ), "_runner": attr.label( default = "@bazeldnf//internal:runner.bash.template", allow_single_file = True, ), }, + toolchains = [BAZELDNF_TOOLCHAIN], executable = True, ) diff --git a/internal/rpmtree.bzl b/internal/rpmtree.bzl index c4fe8aa..d020008 100644 --- a/internal/rpmtree.bzl +++ b/internal/rpmtree.bzl @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("//bazeldnf:toolchain.bzl", "BAZELDNF_TOOLCHAIN") + def _rpm2tar_impl(ctx): rpms = [] for rpm in ctx.files.rpms: @@ -46,7 +48,7 @@ def _rpm2tar_impl(ctx): arguments = args, mnemonic = "Rpm2Tar", progress_message = "Converting %s to tar" % ctx.label.name, - executable = ctx.executable._bazeldnf, + executable = ctx.toolchains[BAZELDNF_TOOLCHAIN]._tool, ) return [DefaultInfo(files = depset([ctx.outputs.out]))] @@ -64,19 +66,13 @@ def _tar2files_impl(ctx): arguments = args, mnemonic = "Tar2Files", progress_message = "Extracting files", - executable = ctx.executable._bazeldnf, + executable = ctx.toolchains[BAZELDNF_TOOLCHAIN]._tool, ) return [DefaultInfo(files = depset(ctx.outputs.out))] _rpm2tar_attrs = { "rpms": attr.label_list(allow_files = True), - "_bazeldnf": attr.label( - executable = True, - cfg = "exec", - allow_files = True, - default = Label("//cmd:prebuilt"), - ), "symlinks": attr.string_dict(), "capabilities": attr.string_list_dict(), "selinux_labels": attr.string_list_dict(), @@ -85,12 +81,6 @@ _rpm2tar_attrs = { _tar2files_attrs = { "tar": attr.label(allow_single_file = True), - "_bazeldnf": attr.label( - executable = True, - cfg = "exec", - allow_files = True, - default = Label("//cmd:prebuilt"), - ), "prefix": attr.string(), "out": attr.output_list(mandatory = True), } @@ -98,11 +88,13 @@ _tar2files_attrs = { _rpm2tar = rule( implementation = _rpm2tar_impl, attrs = _rpm2tar_attrs, + toolchains = [BAZELDNF_TOOLCHAIN], ) _tar2files = rule( implementation = _tar2files_impl, attrs = _tar2files_attrs, + toolchains = [BAZELDNF_TOOLCHAIN], ) def rpmtree(**kwargs): From 9a0b3e3e0f1bb0f5f69046cf304df67146269fd3 Mon Sep 17 00:00:00 2001 From: Manuel Naranjo Date: Sun, 16 Jun 2024 09:35:01 +0200 Subject: [PATCH 09/11] ci: adding e2e for bazel5 Now we provide an e2e test for bazel5 with no bzlmod, it shows the minimal setup to consume from bazeldnf rules --- .bazelignore | 1 + .github/workflows/action.yml | 4 ++-- .gitignore | 1 + WORKSPACE | 18 ++---------------- e2e/bazel-5/.bazelrc | 13 +++++++++++++ e2e/bazel-5/.bazelversion | 1 + e2e/bazel-5/BUILD.bazel | 36 ++++++++++++++++++++++++++++++++++++ e2e/bazel-5/WORKSPACE | 35 +++++++++++++++++++++++++++++++++++ test_deps.bzl | 22 ++++++++++++++++++++++ 9 files changed, 113 insertions(+), 18 deletions(-) create mode 100644 .bazelignore create mode 100644 e2e/bazel-5/.bazelrc create mode 100644 e2e/bazel-5/.bazelversion create mode 100644 e2e/bazel-5/BUILD.bazel create mode 100644 e2e/bazel-5/WORKSPACE create mode 100644 test_deps.bzl diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 0000000..c7ca8d0 --- /dev/null +++ b/.bazelignore @@ -0,0 +1 @@ +e2e diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index c9362a7..b58a5a5 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -16,12 +16,12 @@ jobs: - run: bazel build --config=built-toolchain //... && bazel test --config=built-toolchain //... # TODO: deprecate by Jan 2025 https://bazel.build/release - build-bazel-5: + build-e2e-bazel-5: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: bazelbuild/setup-bazelisk@v1 - - run: export USE_BAZEL_VERSION=5.x && bazel build //... && bazel test //... + - run: cd e2e/bazel-5 && bazel build //... # TODO: rename to build once we move into bazel 7 as the default build-bazel-7: diff --git a/.gitignore b/.gitignore index 4e5c253..3a395cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /bazel-* +/e2e/*/bazel-* /.idea repo.yaml .bazeldnf diff --git a/WORKSPACE b/WORKSPACE index 6b7049e..9f41f49 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -62,23 +62,9 @@ go_register_toolchains(version = "1.19.2") gazelle_dependencies() -rpm( - name = "libvirt-libs-6.1.0-2.fc32.x86_64.rpm", - sha256 = "3a0a3d88c6cb90008fbe49fe05e7025056fb9fa3a887c4a78f79e63f8745c845", - urls = [ - "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/32/Everything/x86_64/os/Packages/l/libvirt-libs-6.1.0-2.fc32.x86_64.rpm", - "https://storage.googleapis.com/builddeps/3a0a3d88c6cb90008fbe49fe05e7025056fb9fa3a887c4a78f79e63f8745c845", - ], -) +load(":test_deps.bzl", "bazeldnf_test_dependencies") -rpm( - name = "libvirt-devel-6.1.0-2.fc32.x86_64.rpm", - sha256 = "2ebb715341b57a74759aff415e0ff53df528c49abaa7ba5b794b4047461fa8d6", - urls = [ - "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/32/Everything/x86_64/os/Packages/l/libvirt-devel-6.1.0-2.fc32.x86_64.rpm", - "https://storage.googleapis.com/builddeps/2ebb715341b57a74759aff415e0ff53df528c49abaa7ba5b794b4047461fa8d6", - ], -) +bazeldnf_test_dependencies() http_archive( name = "rules_pkg", diff --git a/e2e/bazel-5/.bazelrc b/e2e/bazel-5/.bazelrc new file mode 100644 index 0000000..33dee03 --- /dev/null +++ b/e2e/bazel-5/.bazelrc @@ -0,0 +1,13 @@ +# Import Aspect bazelrc presets +import %workspace%/../../.aspect/bazelrc/convenience.bazelrc +import %workspace%/../../.aspect/bazelrc/correctness.bazelrc +import %workspace%/../../.aspect/bazelrc/debug.bazelrc +import %workspace%/../../.aspect/bazelrc/performance.bazelrc + +# Specific project flags go here if we have some + +# Load any settings & overrides specific to the current user from `.bazelrc.user`. +# This file should appear in `.gitignore` so that settings are not shared with team members. This +# should be last statement in this config so the user configuration is able to overwrite flags from +# this file. See https://bazel.build/configure/best-practices#bazelrc-file. +try-import %workspace%/../../.bazelrc.user diff --git a/e2e/bazel-5/.bazelversion b/e2e/bazel-5/.bazelversion new file mode 100644 index 0000000..42267a2 --- /dev/null +++ b/e2e/bazel-5/.bazelversion @@ -0,0 +1 @@ +5.x diff --git a/e2e/bazel-5/BUILD.bazel b/e2e/bazel-5/BUILD.bazel new file mode 100644 index 0000000..48e40e6 --- /dev/null +++ b/e2e/bazel-5/BUILD.bazel @@ -0,0 +1,36 @@ +load("@bazeldnf//bazeldnf:defs.bzl", "bazeldnf", "rpmtree", "tar2files") +load("@rules_pkg//pkg:tar.bzl", "pkg_tar") + +bazeldnf( + name = "bazeldnf", +) + +rpmtree( + name = "something", + rpms = [ + "@libvirt-libs-6.1.0-2.fc32.x86_64.rpm//rpm", + "@libvirt-devel-6.1.0-2.fc32.x86_64.rpm//rpm", + ], +) + +tar2files( + name = "something_libs", + files = { + "/usr/lib64": [ + "libvirt.so.0", + "libvirt.so.0.6001.0", + ], + }, + tar = ":something", + visibility = ["//visibility:public"], +) + +pkg_tar( + name = "whatever", + deps = [":something"], +) + +cc_library( + name = "bar", + srcs = ["//:something_libs/usr/lib64"], +) diff --git a/e2e/bazel-5/WORKSPACE b/e2e/bazel-5/WORKSPACE new file mode 100644 index 0000000..2e6ce02 --- /dev/null +++ b/e2e/bazel-5/WORKSPACE @@ -0,0 +1,35 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +local_repository( + name = "bazeldnf", + path = "../../", +) + +load("@bazeldnf//bazeldnf:deps.bzl", "bazeldnf_dependencies") + +bazeldnf_dependencies() + +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") + +bazel_skylib_workspace() + +# dependencies for integration tests +load("@bazeldnf//:test_deps.bzl", "bazeldnf_test_dependencies") + +bazeldnf_test_dependencies() + +http_archive( + name = "rules_pkg", + sha256 = "cad05f864a32799f6f9022891de91ac78f30e0fa07dc68abac92a628121b5b11", + urls = [ + "https://github.com/bazelbuild/rules_pkg/releases/download/1.0.0/rules_pkg-1.0.0.tar.gz", + ], +) + +load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") + +rules_pkg_dependencies() + +load("@bazeldnf//bazeldnf:toolchain.bzl", "bazeldnf_prebuilt_register_toolchains") + +bazeldnf_prebuilt_register_toolchains(name = "bazeldnf_prebuilt") diff --git a/test_deps.bzl b/test_deps.bzl new file mode 100644 index 0000000..1c788f1 --- /dev/null +++ b/test_deps.bzl @@ -0,0 +1,22 @@ +"bazeldnf repo integration test dependencies" + +load("@bazeldnf//bazeldnf:deps.bzl", "rpm") + +def bazeldnf_test_dependencies(): + rpm( + name = "libvirt-libs-6.1.0-2.fc32.x86_64.rpm", + sha256 = "3a0a3d88c6cb90008fbe49fe05e7025056fb9fa3a887c4a78f79e63f8745c845", + urls = [ + "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/32/Everything/x86_64/os/Packages/l/libvirt-libs-6.1.0-2.fc32.x86_64.rpm", + "https://storage.googleapis.com/builddeps/3a0a3d88c6cb90008fbe49fe05e7025056fb9fa3a887c4a78f79e63f8745c845", + ], + ) + + rpm( + name = "libvirt-devel-6.1.0-2.fc32.x86_64.rpm", + sha256 = "2ebb715341b57a74759aff415e0ff53df528c49abaa7ba5b794b4047461fa8d6", + urls = [ + "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/32/Everything/x86_64/os/Packages/l/libvirt-devel-6.1.0-2.fc32.x86_64.rpm", + "https://storage.googleapis.com/builddeps/2ebb715341b57a74759aff415e0ff53df528c49abaa7ba5b794b4047461fa8d6", + ], + ) From 535a1ce78938569da7ecb2fb35e9eb215a462e33 Mon Sep 17 00:00:00 2001 From: Manuel Naranjo Date: Sun, 16 Jun 2024 09:42:51 +0200 Subject: [PATCH 10/11] ci: adding e2e test for bazel6 no bzlmod make sure bazel6 repos can consume bazeldnf when bzlmod is off --- .github/workflows/action.yml | 5 ++--- e2e/bazel-6/.bazelrc | 15 +++++++++++++++ e2e/bazel-6/.bazelversion | 1 + e2e/bazel-6/BUILD.bazel | 36 ++++++++++++++++++++++++++++++++++++ e2e/bazel-6/WORKSPACE | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 e2e/bazel-6/.bazelrc create mode 100644 e2e/bazel-6/.bazelversion create mode 100644 e2e/bazel-6/BUILD.bazel create mode 100644 e2e/bazel-6/WORKSPACE diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index b58a5a5..114405a 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -23,10 +23,9 @@ jobs: - uses: bazelbuild/setup-bazelisk@v1 - run: cd e2e/bazel-5 && bazel build //... - # TODO: rename to build once we move into bazel 7 as the default - build-bazel-7: + build-e2e-bazel-6-nobzlmod: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: bazelbuild/setup-bazelisk@v1 - - run: export USE_BAZEL_VERSION=6.x && bazel build //... && bazel test //... + - run: cd e2e/bazel-6 && bazel build //... diff --git a/e2e/bazel-6/.bazelrc b/e2e/bazel-6/.bazelrc new file mode 100644 index 0000000..ba3f375 --- /dev/null +++ b/e2e/bazel-6/.bazelrc @@ -0,0 +1,15 @@ +# Import Aspect bazelrc presets + +import %workspace%/../../.aspect/bazelrc/bazel6.bazelrc +import %workspace%/../../.aspect/bazelrc/convenience.bazelrc +import %workspace%/../../.aspect/bazelrc/correctness.bazelrc +import %workspace%/../../.aspect/bazelrc/debug.bazelrc +import %workspace%/../../.aspect/bazelrc/performance.bazelrc + +# Specific project flags go here if we have some + +# Load any settings & overrides specific to the current user from `.bazelrc.user`. +# This file should appear in `.gitignore` so that settings are not shared with team members. This +# should be last statement in this config so the user configuration is able to overwrite flags from +# this file. See https://bazel.build/configure/best-practices#bazelrc-file. +try-import %workspace%/../../.bazelrc.user diff --git a/e2e/bazel-6/.bazelversion b/e2e/bazel-6/.bazelversion new file mode 100644 index 0000000..8f0591a --- /dev/null +++ b/e2e/bazel-6/.bazelversion @@ -0,0 +1 @@ +6.x diff --git a/e2e/bazel-6/BUILD.bazel b/e2e/bazel-6/BUILD.bazel new file mode 100644 index 0000000..48e40e6 --- /dev/null +++ b/e2e/bazel-6/BUILD.bazel @@ -0,0 +1,36 @@ +load("@bazeldnf//bazeldnf:defs.bzl", "bazeldnf", "rpmtree", "tar2files") +load("@rules_pkg//pkg:tar.bzl", "pkg_tar") + +bazeldnf( + name = "bazeldnf", +) + +rpmtree( + name = "something", + rpms = [ + "@libvirt-libs-6.1.0-2.fc32.x86_64.rpm//rpm", + "@libvirt-devel-6.1.0-2.fc32.x86_64.rpm//rpm", + ], +) + +tar2files( + name = "something_libs", + files = { + "/usr/lib64": [ + "libvirt.so.0", + "libvirt.so.0.6001.0", + ], + }, + tar = ":something", + visibility = ["//visibility:public"], +) + +pkg_tar( + name = "whatever", + deps = [":something"], +) + +cc_library( + name = "bar", + srcs = ["//:something_libs/usr/lib64"], +) diff --git a/e2e/bazel-6/WORKSPACE b/e2e/bazel-6/WORKSPACE new file mode 100644 index 0000000..2e6ce02 --- /dev/null +++ b/e2e/bazel-6/WORKSPACE @@ -0,0 +1,35 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +local_repository( + name = "bazeldnf", + path = "../../", +) + +load("@bazeldnf//bazeldnf:deps.bzl", "bazeldnf_dependencies") + +bazeldnf_dependencies() + +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") + +bazel_skylib_workspace() + +# dependencies for integration tests +load("@bazeldnf//:test_deps.bzl", "bazeldnf_test_dependencies") + +bazeldnf_test_dependencies() + +http_archive( + name = "rules_pkg", + sha256 = "cad05f864a32799f6f9022891de91ac78f30e0fa07dc68abac92a628121b5b11", + urls = [ + "https://github.com/bazelbuild/rules_pkg/releases/download/1.0.0/rules_pkg-1.0.0.tar.gz", + ], +) + +load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") + +rules_pkg_dependencies() + +load("@bazeldnf//bazeldnf:toolchain.bzl", "bazeldnf_prebuilt_register_toolchains") + +bazeldnf_prebuilt_register_toolchains(name = "bazeldnf_prebuilt") From 9a015bda46f098924332f13f57450ef4bc211c09 Mon Sep 17 00:00:00 2001 From: Manuel Naranjo Date: Sun, 16 Jun 2024 09:41:54 +0200 Subject: [PATCH 11/11] ci: adding e2e test for bazel7 with no bzlmod adding one more e2e test for the rule --- .github/workflows/action.yml | 7 +++ e2e/bazel-7/.bazelrc | 15 +++++ e2e/bazel-7/.bazelversion | 1 + e2e/bazel-7/BUILD.bazel | 36 +++++++++++ e2e/bazel-7/MODULE.bazel | 6 ++ e2e/bazel-7/MODULE.bazel.lock | 110 ++++++++++++++++++++++++++++++++++ e2e/bazel-7/WORKSPACE | 35 +++++++++++ 7 files changed, 210 insertions(+) create mode 100644 e2e/bazel-7/.bazelrc create mode 100644 e2e/bazel-7/.bazelversion create mode 100644 e2e/bazel-7/BUILD.bazel create mode 100644 e2e/bazel-7/MODULE.bazel create mode 100644 e2e/bazel-7/MODULE.bazel.lock create mode 100644 e2e/bazel-7/WORKSPACE diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 114405a..da4bd5a 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -29,3 +29,10 @@ jobs: - uses: actions/checkout@v2 - uses: bazelbuild/setup-bazelisk@v1 - run: cd e2e/bazel-6 && bazel build //... + + build-e2e-bazel-7-nobzlmod: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: bazelbuild/setup-bazelisk@v1 + - run: cd e2e/bazel-7 && bazel build //... diff --git a/e2e/bazel-7/.bazelrc b/e2e/bazel-7/.bazelrc new file mode 100644 index 0000000..bb32d4e --- /dev/null +++ b/e2e/bazel-7/.bazelrc @@ -0,0 +1,15 @@ +# Import Aspect bazelrc presets +import %workspace%/../../.aspect/bazelrc/convenience.bazelrc +import %workspace%/../../.aspect/bazelrc/bazel6.bazelrc +import %workspace%/../../.aspect/bazelrc/bazel7.bazelrc +import %workspace%/../../.aspect/bazelrc/correctness.bazelrc +import %workspace%/../../.aspect/bazelrc/debug.bazelrc +import %workspace%/../../.aspect/bazelrc/performance.bazelrc + +# Specific project flags go here if we have some + +# Load any settings & overrides specific to the current user from `.bazelrc.user`. +# This file should appear in `.gitignore` so that settings are not shared with team members. This +# should be last statement in this config so the user configuration is able to overwrite flags from +# this file. See https://bazel.build/configure/best-practices#bazelrc-file. +try-import %workspace%/../../.bazelrc.user diff --git a/e2e/bazel-7/.bazelversion b/e2e/bazel-7/.bazelversion new file mode 100644 index 0000000..35907cd --- /dev/null +++ b/e2e/bazel-7/.bazelversion @@ -0,0 +1 @@ +7.x diff --git a/e2e/bazel-7/BUILD.bazel b/e2e/bazel-7/BUILD.bazel new file mode 100644 index 0000000..48e40e6 --- /dev/null +++ b/e2e/bazel-7/BUILD.bazel @@ -0,0 +1,36 @@ +load("@bazeldnf//bazeldnf:defs.bzl", "bazeldnf", "rpmtree", "tar2files") +load("@rules_pkg//pkg:tar.bzl", "pkg_tar") + +bazeldnf( + name = "bazeldnf", +) + +rpmtree( + name = "something", + rpms = [ + "@libvirt-libs-6.1.0-2.fc32.x86_64.rpm//rpm", + "@libvirt-devel-6.1.0-2.fc32.x86_64.rpm//rpm", + ], +) + +tar2files( + name = "something_libs", + files = { + "/usr/lib64": [ + "libvirt.so.0", + "libvirt.so.0.6001.0", + ], + }, + tar = ":something", + visibility = ["//visibility:public"], +) + +pkg_tar( + name = "whatever", + deps = [":something"], +) + +cc_library( + name = "bar", + srcs = ["//:something_libs/usr/lib64"], +) diff --git a/e2e/bazel-7/MODULE.bazel b/e2e/bazel-7/MODULE.bazel new file mode 100644 index 0000000..00bb183 --- /dev/null +++ b/e2e/bazel-7/MODULE.bazel @@ -0,0 +1,6 @@ +############################################################################### +# Bazel now uses Bzlmod by default to manage external dependencies. +# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel. +# +# For more details, please check https://github.com/bazelbuild/bazel/issues/18958 +############################################################################### diff --git a/e2e/bazel-7/MODULE.bazel.lock b/e2e/bazel-7/MODULE.bazel.lock new file mode 100644 index 0000000..f5cd531 --- /dev/null +++ b/e2e/bazel-7/MODULE.bazel.lock @@ -0,0 +1,110 @@ +{ + "lockFileVersion": 11, + "registryFileHashes": { + "https://bcr.bazel.build/bazel_registry.json": "8a28e4aff06ee60aed2a8c281907fb8bcbf3b753c91fb5a5c57da3215d5b3497", + "https://bcr.bazel.build/modules/abseil-cpp/20210324.2/MODULE.bazel": "7cd0312e064fde87c8d1cd79ba06c876bd23630c83466e9500321be55c96ace2", + "https://bcr.bazel.build/modules/abseil-cpp/20211102.0/MODULE.bazel": "70390338f7a5106231d20620712f7cccb659cd0e9d073d1991c038eb9fc57589", + "https://bcr.bazel.build/modules/abseil-cpp/20211102.0/source.json": "7e3a9adf473e9af076ae485ed649d5641ad50ec5c11718103f34de03170d94ad", + "https://bcr.bazel.build/modules/apple_support/1.5.0/MODULE.bazel": "50341a62efbc483e8a2a6aec30994a58749bd7b885e18dd96aa8c33031e558ef", + "https://bcr.bazel.build/modules/apple_support/1.5.0/source.json": "eb98a7627c0bc486b57f598ad8da50f6625d974c8f723e9ea71bd39f709c9862", + "https://bcr.bazel.build/modules/bazel_features/1.11.0/MODULE.bazel": "f9382337dd5a474c3b7d334c2f83e50b6eaedc284253334cf823044a26de03e8", + "https://bcr.bazel.build/modules/bazel_features/1.11.0/source.json": "c9320aa53cd1c441d24bd6b716da087ad7e4ff0d9742a9884587596edfe53015", + "https://bcr.bazel.build/modules/bazel_skylib/1.0.3/MODULE.bazel": "bcb0fd896384802d1ad283b4e4eb4d718eebd8cb820b0a2c3a347fb971afd9d8", + "https://bcr.bazel.build/modules/bazel_skylib/1.2.1/MODULE.bazel": "f35baf9da0efe45fa3da1696ae906eea3d615ad41e2e3def4aeb4e8bc0ef9a7a", + "https://bcr.bazel.build/modules/bazel_skylib/1.3.0/MODULE.bazel": "20228b92868bf5cfc41bda7afc8a8ba2a543201851de39d990ec957b513579c5", + "https://bcr.bazel.build/modules/bazel_skylib/1.6.1/MODULE.bazel": "8fdee2dbaace6c252131c00e1de4b165dc65af02ea278476187765e1a617b917", + "https://bcr.bazel.build/modules/bazel_skylib/1.6.1/source.json": "082ed5f9837901fada8c68c2f3ddc958bb22b6d654f71dd73f3df30d45d4b749", + "https://bcr.bazel.build/modules/buildozer/7.1.2/MODULE.bazel": "2e8dd40ede9c454042645fd8d8d0cd1527966aa5c919de86661e62953cd73d84", + "https://bcr.bazel.build/modules/buildozer/7.1.2/source.json": "c9028a501d2db85793a6996205c8de120944f50a0d570438fcae0457a5f9d1f8", + "https://bcr.bazel.build/modules/googletest/1.11.0/MODULE.bazel": "3a83f095183f66345ca86aa13c58b59f9f94a2f81999c093d4eeaa2d262d12f4", + "https://bcr.bazel.build/modules/googletest/1.11.0/source.json": "c73d9ef4268c91bd0c1cd88f1f9dfa08e814b1dbe89b5f594a9f08ba0244d206", + "https://bcr.bazel.build/modules/platforms/0.0.4/MODULE.bazel": "9b328e31ee156f53f3c416a64f8491f7eb731742655a47c9eec4703a71644aee", + "https://bcr.bazel.build/modules/platforms/0.0.5/MODULE.bazel": "5733b54ea419d5eaf7997054bb55f6a1d0b5ff8aedf0176fef9eea44f3acda37", + "https://bcr.bazel.build/modules/platforms/0.0.6/MODULE.bazel": "ad6eeef431dc52aefd2d77ed20a4b353f8ebf0f4ecdd26a807d2da5aa8cd0615", + "https://bcr.bazel.build/modules/platforms/0.0.7/MODULE.bazel": "72fd4a0ede9ee5c021f6a8dd92b503e089f46c227ba2813ff183b71616034814", + "https://bcr.bazel.build/modules/platforms/0.0.9/MODULE.bazel": "4a87a60c927b56ddd67db50c89acaa62f4ce2a1d2149ccb63ffd871d5ce29ebc", + "https://bcr.bazel.build/modules/platforms/0.0.9/source.json": "cd74d854bf16a9e002fb2ca7b1a421f4403cda29f824a765acd3a8c56f8d43e6", + "https://bcr.bazel.build/modules/protobuf/21.7/MODULE.bazel": "a5a29bb89544f9b97edce05642fac225a808b5b7be74038ea3640fae2f8e66a7", + "https://bcr.bazel.build/modules/protobuf/21.7/source.json": "bbe500720421e582ff2d18b0802464205138c06056f443184de39fbb8187b09b", + "https://bcr.bazel.build/modules/protobuf/3.19.0/MODULE.bazel": "6b5fbb433f760a99a22b18b6850ed5784ef0e9928a72668b66e4d7ccd47db9b0", + "https://bcr.bazel.build/modules/protobuf/3.19.6/MODULE.bazel": "9233edc5e1f2ee276a60de3eaa47ac4132302ef9643238f23128fea53ea12858", + "https://bcr.bazel.build/modules/rules_cc/0.0.1/MODULE.bazel": "cb2aa0747f84c6c3a78dad4e2049c154f08ab9d166b1273835a8174940365647", + "https://bcr.bazel.build/modules/rules_cc/0.0.2/MODULE.bazel": "6915987c90970493ab97393024c156ea8fb9f3bea953b2f3ec05c34f19b5695c", + "https://bcr.bazel.build/modules/rules_cc/0.0.8/MODULE.bazel": "964c85c82cfeb6f3855e6a07054fdb159aced38e99a5eecf7bce9d53990afa3e", + "https://bcr.bazel.build/modules/rules_cc/0.0.9/MODULE.bazel": "836e76439f354b89afe6a911a7adf59a6b2518fafb174483ad78a2a2fde7b1c5", + "https://bcr.bazel.build/modules/rules_cc/0.0.9/source.json": "1f1ba6fea244b616de4a554a0f4983c91a9301640c8fe0dd1d410254115c8430", + "https://bcr.bazel.build/modules/rules_java/4.0.0/MODULE.bazel": "5a78a7ae82cd1a33cef56dc578c7d2a46ed0dca12643ee45edbb8417899e6f74", + "https://bcr.bazel.build/modules/rules_java/7.6.1/MODULE.bazel": "2f14b7e8a1aa2f67ae92bc69d1ec0fa8d9f827c4e17ff5e5f02e91caa3b2d0fe", + "https://bcr.bazel.build/modules/rules_java/7.6.1/source.json": "8f3f3076554e1558e8e468b2232991c510ecbcbed9e6f8c06ac31c93bcf38362", + "https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7", + "https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/source.json": "a075731e1b46bc8425098512d038d416e966ab19684a10a34f4741295642fc35", + "https://bcr.bazel.build/modules/rules_license/0.0.3/MODULE.bazel": "627e9ab0247f7d1e05736b59dbb1b6871373de5ad31c3011880b4133cafd4bd0", + "https://bcr.bazel.build/modules/rules_license/0.0.7/MODULE.bazel": "088fbeb0b6a419005b89cf93fe62d9517c0a2b8bb56af3244af65ecfe37e7d5d", + "https://bcr.bazel.build/modules/rules_license/0.0.7/source.json": "355cc5737a0f294e560d52b1b7a6492d4fff2caf0bef1a315df5a298fca2d34a", + "https://bcr.bazel.build/modules/rules_pkg/0.7.0/MODULE.bazel": "df99f03fc7934a4737122518bb87e667e62d780b610910f0447665a7e2be62dc", + "https://bcr.bazel.build/modules/rules_pkg/0.7.0/source.json": "c2557066e0c0342223ba592510ad3d812d4963b9024831f7f66fd0584dd8c66c", + "https://bcr.bazel.build/modules/rules_proto/4.0.0/MODULE.bazel": "a7a7b6ce9bee418c1a760b3d84f83a299ad6952f9903c67f19e4edd964894e06", + "https://bcr.bazel.build/modules/rules_proto/5.3.0-21.7/MODULE.bazel": "e8dff86b0971688790ae75528fe1813f71809b5afd57facb44dad9e8eca631b7", + "https://bcr.bazel.build/modules/rules_proto/5.3.0-21.7/source.json": "d57902c052424dfda0e71646cb12668d39c4620ee0544294d9d941e7d12bc3a9", + "https://bcr.bazel.build/modules/rules_python/0.10.2/MODULE.bazel": "cc82bc96f2997baa545ab3ce73f196d040ffb8756fd2d66125a530031cd90e5f", + "https://bcr.bazel.build/modules/rules_python/0.22.1/MODULE.bazel": "26114f0c0b5e93018c0c066d6673f1a2c3737c7e90af95eff30cfee38d0bbac7", + "https://bcr.bazel.build/modules/rules_python/0.22.1/source.json": "57226905e783bae7c37c2dd662be078728e48fa28ee4324a7eabcafb5a43d014", + "https://bcr.bazel.build/modules/rules_python/0.4.0/MODULE.bazel": "9208ee05fd48bf09ac60ed269791cf17fb343db56c8226a720fbb1cdf467166c", + "https://bcr.bazel.build/modules/stardoc/0.5.1/MODULE.bazel": "1a05d92974d0c122f5ccf09291442580317cdd859f07a8655f1db9a60374f9f8", + "https://bcr.bazel.build/modules/stardoc/0.5.1/source.json": "a96f95e02123320aa015b956f29c00cb818fa891ef823d55148e1a362caacf29", + "https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/MODULE.bazel": "7298990c00040a0e2f121f6c32544bab27d4452f80d9ce51349b1a28f3005c43", + "https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/source.json": "f1ef7d3f9e0e26d4b23d1c39b5f5de71f584dd7d1b4ef83d9bbba6ec7a6a6459", + "https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0", + "https://bcr.bazel.build/modules/zlib/1.2.12/MODULE.bazel": "3b1a8834ada2a883674be8cbd36ede1b6ec481477ada359cd2d3ddc562340b27", + "https://bcr.bazel.build/modules/zlib/1.3/MODULE.bazel": "6a9c02f19a24dcedb05572b2381446e27c272cd383aed11d41d99da9e3167a72", + "https://bcr.bazel.build/modules/zlib/1.3/source.json": "b6b43d0737af846022636e6e255fd4a96fee0d34f08f3830e6e0bac51465c37c" + }, + "selectedYankedVersions": {}, + "moduleExtensions": { + "@@apple_support~//crosstool:setup.bzl%apple_cc_configure_extension": { + "general": { + "bzlTransitiveDigest": "PjIds3feoYE8SGbbIq2SFTZy3zmxeO2tQevJZNDo7iY=", + "usagesDigest": "aLmqbvowmHkkBPve05yyDNGN7oh7QE9kBADr3QIZTZs=", + "recordedFileInputs": {}, + "recordedDirentsInputs": {}, + "envVariables": {}, + "generatedRepoSpecs": { + "local_config_apple_cc": { + "bzlFile": "@@apple_support~//crosstool:setup.bzl", + "ruleClassName": "_apple_cc_autoconf", + "attributes": {} + }, + "local_config_apple_cc_toolchains": { + "bzlFile": "@@apple_support~//crosstool:setup.bzl", + "ruleClassName": "_apple_cc_autoconf_toolchains", + "attributes": {} + } + }, + "recordedRepoMappingEntries": [ + [ + "apple_support~", + "bazel_tools", + "bazel_tools" + ] + ] + } + }, + "@@platforms//host:extension.bzl%host_platform": { + "general": { + "bzlTransitiveDigest": "xelQcPZH8+tmuOHVjL9vDxMnnQNMlwj0SlvgoqBkm4U=", + "usagesDigest": "meSzxn3DUCcYEhq4HQwExWkWtU4EjriRBQLsZN+Q0SU=", + "recordedFileInputs": {}, + "recordedDirentsInputs": {}, + "envVariables": {}, + "generatedRepoSpecs": { + "host_platform": { + "bzlFile": "@@platforms//host:extension.bzl", + "ruleClassName": "host_platform_repo", + "attributes": {} + } + }, + "recordedRepoMappingEntries": [] + } + } + } +} diff --git a/e2e/bazel-7/WORKSPACE b/e2e/bazel-7/WORKSPACE new file mode 100644 index 0000000..2e6ce02 --- /dev/null +++ b/e2e/bazel-7/WORKSPACE @@ -0,0 +1,35 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +local_repository( + name = "bazeldnf", + path = "../../", +) + +load("@bazeldnf//bazeldnf:deps.bzl", "bazeldnf_dependencies") + +bazeldnf_dependencies() + +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") + +bazel_skylib_workspace() + +# dependencies for integration tests +load("@bazeldnf//:test_deps.bzl", "bazeldnf_test_dependencies") + +bazeldnf_test_dependencies() + +http_archive( + name = "rules_pkg", + sha256 = "cad05f864a32799f6f9022891de91ac78f30e0fa07dc68abac92a628121b5b11", + urls = [ + "https://github.com/bazelbuild/rules_pkg/releases/download/1.0.0/rules_pkg-1.0.0.tar.gz", + ], +) + +load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") + +rules_pkg_dependencies() + +load("@bazeldnf//bazeldnf:toolchain.bzl", "bazeldnf_prebuilt_register_toolchains") + +bazeldnf_prebuilt_register_toolchains(name = "bazeldnf_prebuilt")