Skip to content
Open
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: 1 addition & 1 deletion .bazelignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
examples
examples
5 changes: 5 additions & 0 deletions .github/actions/build-test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ runs:
bazel run //:gazelle
bazel run //:gazelle_check
shell: bash
- name: Test Bazel 7 targets
run: |
cd examples/bazel7
./tools/cue/test.sh
shell: bash
20 changes: 20 additions & 0 deletions cue/deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load(
"//cue/private/tools/cue:toolchain.bzl",
"download_tool",
"known_release_versions",
)

def _cue_tool(name = "cue_tool", version = None, register_toolchains = True):
download_tool(
name = name,
version = version,
)
if register_toolchains:
native.register_toolchains("@{}_toolchains//:all".format(name))

# Register the Cue toolchain for the specified version
def cue_register_toolchains(name = "cue_tool", version = None, register_toolchains = True):
latest_release = known_release_versions()[0] # Get the latest version from the known release versions
if not version:
version = latest_release # Use the latest version if none is specified
_cue_tool(name = name, version = version, register_toolchains = register_toolchains)
4 changes: 4 additions & 0 deletions examples/bazel7/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Disable Bazel Modules. No-op in Bazel 6 as this is the default but Bazel 7 enables them by default.
build --noenable_bzlmod
query --noenable_bzlmod
fetch --noenable_bzlmod
1 change: 1 addition & 0 deletions examples/bazel7/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.6.1
6 changes: 6 additions & 0 deletions examples/bazel7/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/bazel-bin
/bazel-out
/bazel-testlogs
/bazel-bazel7

*~
19 changes: 19 additions & 0 deletions examples/bazel7/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
workspace(name = "bazel7")

# load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# http_archive(
# name = "rules_cue",
# sha256 = "22eee0fbce6274af199421d3192f403da171d90b4193ed36513669f7615ccd0c",
# strip_prefix = "rules_cue-0.15.0",
# url = "https://github.com/seh/rules_cue/releases/download/v0.15.0/vcs-archive-v0.15.0.tar.gz",
# )

local_repository(
name = "rules_cue",
path = "../..",
)

load("@rules_cue//cue:deps.bzl", "cue_register_toolchains")

cue_register_toolchains(version = "v0.15.1")
8 changes: 8 additions & 0 deletions examples/bazel7/tools/cue/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("//tools/cue:cmd.bzl", "cue_binary")

exports_files(glob(["*.bzl"]) + ["cmd.sh.tpl"])

cue_binary(
name = "cue",
visibility = ["//visibility:public"],
)
65 changes: 65 additions & 0 deletions examples/bazel7/tools/cue/cmd.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
This module contains a rule for running cue commands.
"""

def _cue_cmd_impl(ctx):
cue_tool = ctx.toolchains["@rules_cue//tools/cue:toolchain_type"].cueinfo.tool
cmd_sh = ctx.actions.declare_file(ctx.attr.name + ".sh")
substitutions = {
"%{BUILT_IN}": ctx.attr.built_in,
"%{COMMAND}": ctx.attr.command,
"%{CUE}": cue_tool.path,
"%{CWD}": ctx.label.package,
}
ctx.actions.expand_template(
template = ctx.file._cmd_tpl,
output = cmd_sh,
substitutions = substitutions,
)

return DefaultInfo(
executable = cmd_sh,
runfiles = ctx.runfiles(
files = [
cue_tool,
],
),
)

cue_cmd = rule(
attrs = {
# The cue built-in command to run (e.g., "fmt", "vet").
# See https://cuelang.org/docs/reference/command/
"built_in": attr.string(
mandatory = False,
default = "",
),
# User command to run with cue cmd {command}.
# keep name 'command' for backward compatibility
# See https://cuelang.org/docs/reference/command/cue-help-commands/
"command": attr.string(
mandatory = False,
),
"_cmd_tpl": attr.label(
default = Label("//tools/cue:cmd.sh.tpl"),
allow_single_file = True,
),
},
implementation = _cue_cmd_impl,
executable = True,
toolchains = ["@rules_cue//tools/cue:toolchain_type"],
)

def cue_binary(name, **kwargs):
"""
A convenience alias for cue_cmd.

Args:
name: The name of the rule.
**kwargs: Additional arguments to pass to cue_cmd.
"""
cue_cmd(
name = name,
built_in = "",
**kwargs
)
12 changes: 12 additions & 0 deletions examples/bazel7/tools/cue/cmd.sh.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set +ex

CUE=$(readlink -f %{CUE})
cd "${BUILD_WORKSPACE_DIRECTORY}/%{CWD}"

if [ -n "%{COMMAND}" ]; then
CUE_DEBUG=sortfields $CUE cmd %{COMMAND} "$@"
else
CUE_DEBUG=sortfields $CUE %{BUILT_IN} "$@"
fi
18 changes: 18 additions & 0 deletions examples/bazel7/tools/cue/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

pushd "$(dirname "${BASH_SOURCE[0]}")"

bazel run //tools/cue -- version

# Get all items and count them
items=($(bazel query 'kind("cue_cmd rule", //...)'))
total=${#items[@]}
current=1

for i in "${items[@]}" ; do
echo "[$current/$total] $i"
bazel build $i
((current++))
done

popd
Loading