Skip to content

Commit 41c2189

Browse files
committed
Support noenable bzlmod in bazel7
1 parent 563d8ee commit 41c2189

12 files changed

Lines changed: 315 additions & 1 deletion

File tree

.bazelignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
examples
1+
examples

.github/actions/build-test/action.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ runs:
3737
bazel run //:gazelle
3838
bazel run //:gazelle_check
3939
shell: bash
40+
- name: Test Bazel 7 targets
41+
run: |
42+
cd examples/bazel7
43+
./tools/cue/test.sh
44+
shell: bash

cue/deps.bzl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
load(
2+
"//cue/private/tools/cue:toolchain.bzl",
3+
"download_tool",
4+
"known_release_versions",
5+
)
6+
7+
def _cue_tool(name = "cue_tool", version = None, register_toolchains = True):
8+
download_tool(
9+
name = name,
10+
version = version,
11+
)
12+
if register_toolchains:
13+
native.register_toolchains("@{}_toolchains//:all".format(name))
14+
15+
# Register the Cue toolchain for the specified version
16+
def cue_register_toolchains(name = "cue_tool", version = None, register_toolchains = True):
17+
latest_release = known_release_versions()[0] # Get the latest version from the known release versions
18+
if not version:
19+
version = latest_release # Use the latest version if none is specified
20+
_cue_tool(name = name, version = version, register_toolchains = register_toolchains)

examples/bazel7/.bazelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Disable Bazel Modules. No-op in Bazel 6 as this is the default but Bazel 7 enables them by default.
2+
build --noenable_bzlmod
3+
query --noenable_bzlmod
4+
fetch --noenable_bzlmod

examples/bazel7/.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.6.1

examples/bazel7/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/bazel-bin
2+
/bazel-out
3+
/bazel-testlogs
4+
/bazel-bazel7
5+
6+
*~

examples/bazel7/WORKSPACE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
workspace(name = "bazel7")
2+
3+
# load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
# http_archive(
6+
# name = "rules_cue",
7+
# sha256 = "22eee0fbce6274af199421d3192f403da171d90b4193ed36513669f7615ccd0c",
8+
# strip_prefix = "rules_cue-0.15.0",
9+
# url = "https://github.com/seh/rules_cue/releases/download/v0.15.0/vcs-archive-v0.15.0.tar.gz",
10+
# )
11+
12+
local_repository(
13+
name = "rules_cue",
14+
path = "../..",
15+
)
16+
17+
load("@rules_cue//cue:deps.bzl", "cue_register_toolchains")
18+
19+
cue_register_toolchains(version = "v0.15.1")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load("//tools/cue:cmd.bzl", "cue_binary")
2+
3+
exports_files(glob(["*.bzl"]) + ["cmd.sh.tpl"])
4+
5+
cue_binary(
6+
name = "cue",
7+
visibility = ["//visibility:public"],
8+
)

examples/bazel7/tools/cue/cmd.bzl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
This module contains a rule for running cue commands.
3+
"""
4+
5+
def _cue_cmd_impl(ctx):
6+
cue_tool = ctx.toolchains["@rules_cue//tools/cue:toolchain_type"].cueinfo.tool
7+
cmd_sh = ctx.actions.declare_file(ctx.attr.name + ".sh")
8+
substitutions = {
9+
"%{BUILT_IN}": ctx.attr.built_in,
10+
"%{COMMAND}": ctx.attr.command,
11+
"%{CUE}": cue_tool.path,
12+
"%{CWD}": ctx.label.package,
13+
}
14+
ctx.actions.expand_template(
15+
template = ctx.file._cmd_tpl,
16+
output = cmd_sh,
17+
substitutions = substitutions,
18+
)
19+
20+
return DefaultInfo(
21+
executable = cmd_sh,
22+
runfiles = ctx.runfiles(
23+
files = [
24+
cue_tool,
25+
],
26+
),
27+
)
28+
29+
cue_cmd = rule(
30+
attrs = {
31+
# The cue built-in command to run (e.g., "fmt", "vet").
32+
# See https://cuelang.org/docs/reference/command/
33+
"built_in": attr.string(
34+
mandatory = False,
35+
default = "",
36+
),
37+
# User command to run with cue cmd {command}.
38+
# keep name 'command' for backward compatibility
39+
# See https://cuelang.org/docs/reference/command/cue-help-commands/
40+
"command": attr.string(
41+
mandatory = False,
42+
),
43+
"_cmd_tpl": attr.label(
44+
default = Label("//tools/cue:cmd.sh.tpl"),
45+
allow_single_file = True,
46+
),
47+
},
48+
implementation = _cue_cmd_impl,
49+
executable = True,
50+
toolchains = ["@rules_cue//tools/cue:toolchain_type"],
51+
)
52+
53+
def cue_binary(name, **kwargs):
54+
"""
55+
A convenience alias for cue_cmd.
56+
57+
Args:
58+
name: The name of the rule.
59+
**kwargs: Additional arguments to pass to cue_cmd.
60+
"""
61+
cue_cmd(
62+
name = name,
63+
built_in = "",
64+
**kwargs
65+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set +ex
4+
5+
CUE=$(readlink -f %{CUE})
6+
cd "${BUILD_WORKSPACE_DIRECTORY}/%{CWD}"
7+
8+
if [ -n "%{COMMAND}" ]; then
9+
CUE_DEBUG=sortfields $CUE cmd %{COMMAND} "$@"
10+
else
11+
CUE_DEBUG=sortfields $CUE %{BUILT_IN} "$@"
12+
fi

0 commit comments

Comments
 (0)