Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bazelisk test //:all_integration_tests
- name: Run with extra exec platforms
run: bazelisk run //:buildifier --extra_execution_platforms="//:non_host_platform,@platforms//host" '--' -help

example_simple:
strategy:
Expand Down
9 changes: 9 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ alias(

# MARK: - Integration Test

# A platform used for tests that must not match the host platform
platform(
name = "non_host_platform",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:riscv64",
],
)

filegroup(
name = "local_repository_files",
srcs = [
Expand Down
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module(
compatibility_level = 1,
)

bazel_dep(name = "bazel_features", version = "1.45.0")
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "platforms", version = "0.0.11")
bazel_dep(name = "rules_shell", version = "0.6.1")
Expand Down
10 changes: 7 additions & 3 deletions buildifier/buildifier_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Simple rule for running buildifier from the toolchain config
"""

load("@bazel_features//:features.bzl", "bazel_features")
load("@platforms//host:constraints.bzl", "HOST_CONSTRAINTS")

def _buildifier_binary(ctx):
Expand All @@ -22,8 +23,11 @@ def _buildifier_binary(ctx):

buildifier_binary = rule(
implementation = _buildifier_binary,
attrs = {},
exec_compatible_with = HOST_CONSTRAINTS,
toolchains = ["@buildifier_prebuilt//buildifier:toolchain"],
exec_compatible_with = [] if bazel_features.toolchains.has_default_test_toolchain_type else HOST_CONSTRAINTS,
toolchains = [
"@buildifier_prebuilt//buildifier:toolchain",
] + ([
"@bazel_tools//tools/test:default_test_toolchain_type",
] if bazel_features.toolchains.has_default_test_toolchain_type else []),
executable = True,
)
5 changes: 4 additions & 1 deletion buildifier/factory.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ def buildifier_impl_factory(ctx, *, test_rule):
fail("Cannot use 'no_sandbox' without a 'workspace'")
workspace = ctx.file.workspace.path

toolchain = ctx.toolchains["@buildifier_prebuilt//buildifier:toolchain"]
if test_rule:
toolchain = ctx.exec_groups["test"].toolchains["@buildifier_prebuilt//buildifier:toolchain"]
else:
toolchain = ctx.toolchains["@buildifier_prebuilt//buildifier:toolchain"]
buildifier = toolchain._tool
runner = toolchain._runner

Expand Down
10 changes: 7 additions & 3 deletions buildozer/buildozer_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Simple rule for running buildozer from the toolchain config
"""

load("@bazel_features//:features.bzl", "bazel_features")
load("@platforms//host:constraints.bzl", "HOST_CONSTRAINTS")

def _buildozer_binary(ctx):
Expand All @@ -22,8 +23,11 @@ def _buildozer_binary(ctx):

buildozer_binary = rule(
implementation = _buildozer_binary,
attrs = {},
exec_compatible_with = HOST_CONSTRAINTS,
toolchains = ["@buildifier_prebuilt//buildozer:toolchain"],
exec_compatible_with = [] if bazel_features.toolchains.has_default_test_toolchain_type else HOST_CONSTRAINTS,
toolchains = [
"@buildifier_prebuilt//buildozer:toolchain",
] + ([
"@bazel_tools//tools/test:default_test_toolchain_type",
] if bazel_features.toolchains.has_default_test_toolchain_type else []),
executable = True,
)
8 changes: 8 additions & 0 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ def buildifier_prebuilt_deps():
strip_prefix = "rules_shell-0.6.1",
url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.6.1/rules_shell-v0.6.1.tar.gz",
)

maybe(
http_archive,
name = "bazel_features",
sha256 = "adfdb3cffab3a99a63363d844d559a81965d2b61a6062dd51a3d2478d416768f",
strip_prefix = "bazel_features-1.45.0",
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.45.0/bazel_features-v1.45.0.tar.gz",
)
4 changes: 4 additions & 0 deletions examples/simple/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")

buildifier_prebuilt_deps()

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()
Expand Down
4 changes: 4 additions & 0 deletions examples/specify_assets/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")

buildifier_prebuilt_deps()

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()
Expand Down
19 changes: 16 additions & 3 deletions rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Rules to use the prebuilt buildifier / buildozer binaries
"""

load("@bazel_features//:features.bzl", "bazel_features")
load("@platforms//host:constraints.bzl", "HOST_CONSTRAINTS")
load("//buildifier:buildifier_binary.bzl", _buildifier_binary = "buildifier_binary")
load(
Expand All @@ -20,8 +21,12 @@ def _buildifier_impl(ctx):
buildifier = rule(
implementation = _buildifier_impl,
attrs = buildifier_attr_factory(test_rule = False),
exec_compatible_with = HOST_CONSTRAINTS,
toolchains = ["@buildifier_prebuilt//buildifier:toolchain"],
exec_compatible_with = [] if bazel_features.toolchains.has_default_test_toolchain_type else HOST_CONSTRAINTS,
toolchains = [
"@buildifier_prebuilt//buildifier:toolchain",
] + ([
"@bazel_tools//tools/test:default_test_toolchain_type",
] if bazel_features.toolchains.has_default_test_toolchain_type else []),
executable = True,
)

Expand All @@ -32,7 +37,15 @@ _buildifier_test = rule(
implementation = _buildifier_test_impl,
attrs = buildifier_attr_factory(test_rule = True),
exec_compatible_with = HOST_CONSTRAINTS,
toolchains = ["@buildifier_prebuilt//buildifier:toolchain"],
exec_groups = {
"test": exec_group(
toolchains = [
"@buildifier_prebuilt//buildifier:toolchain",
] + ([
"@bazel_tools//tools/test:default_test_toolchain_type",
] if bazel_features.toolchains.has_default_test_toolchain_type else []),
),
},
test = True,
)

Expand Down
Loading