Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WORKSPACE.bazel to support bazel version <= 7.0 #21

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples/
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/bazel-bin
/bazel-out
/bazel-rules_cue
/bazel-testlogs

*~
bazel-bin
bazel-out
bazel-bzlmod
bazel-rules_cue
bazel-testlogs
*~
.bazelrc.*
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load(
"@gazelle//:def.bzl",
"@bazel_gazelle//:def.bzl",
"gazelle",
)

Expand Down
35 changes: 34 additions & 1 deletion WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
workspace(name = "com_github_seh_rules_cue")
workspace(name = "rules_cue")

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

http_archive(
name = "io_bazel_rules_go",
sha256 = "b2038e2de2cace18f032249cb4bb0048abf583a36369fa98f687af1b3f880b26",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.48.1/rules_go-v0.48.1.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.48.1/rules_go-v0.48.1.zip",
],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.22.4")

http_archive(
name = "bazel_gazelle",
sha256 = "aefbf2fc7c7616c9ed73aa3d51c77100724d5b3ce66cfa16406e8c13e87c8b52",
urls = [
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.41.0/bazel-gazelle-v0.41.0.tar.gz",
],
)

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

gazelle_dependencies(go_repository_default_config = "@//:WORKSPACE.bazel")

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

cue_register_toolchains()
Empty file added WORKSPACE.bzlmod
Empty file.
28 changes: 26 additions & 2 deletions cue/cue.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ load(
"@bazel_skylib//lib:paths.bzl",
"paths",
)
load(
"@bazel_skylib//rules:diff_test.bzl",
"diff_test",
)
load(
"//cue/private:config.bzl",
"CUEConfigInfo",
Expand Down Expand Up @@ -162,7 +166,7 @@ def _add_common_instance_consuming_attrs_to(attrs):
attrs.update({
"instance": attr.label(
doc = """CUE instance to export.

This value must refer either to a target using the cue_instance rule
or another rule that yields a CUEInstanceInfo provider.""",
providers = [CUEInstanceInfo],
Expand Down Expand Up @@ -496,7 +500,7 @@ _cue_instance_runfiles = rule(
attrs = _add_common_source_consuming_attrs_to({
"instance": attr.label(
doc = """CUE instance to export.

This value must refer either to a target using the cue_instance rule
or another rule that yields a CUEInstanceInfo provider.""",
providers = [CUEInstanceInfo],
Expand Down Expand Up @@ -880,3 +884,23 @@ def cue_exported_instance(name, **kwargs):
],
**kwargs
)

def cue_test(name, generated_output_file, golden_file = None):
"""cue_test"""
if not golden_file:
base, extension = paths.split_extension(generated_output_file)
parts = base.rpartition(":")
if parts[1] == ":":
base = parts[0]
golden_basename_prefix = parts[2] + "-"
else:
base = parts[2]
golden_basename_prefix = ""
golden_file = "{}:{}golden{}".format(base, golden_basename_prefix, extension)

diff_test(
name = name + "_test",
file1 = generated_output_file,
file2 = golden_file,
size = "small",
)
27 changes: 27 additions & 0 deletions cue/deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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(version = None, register_toolchains = True):
"""Register the Cue toolchains for the specified version.

Args:
version (str): The version of the Cue toolchain to register.
Defaults to "0.11.0" if not specified.
register_toolchains (boolean): if ture, will register toolchains
"""
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(register_toolchains = register_toolchains)
2 changes: 2 additions & 0 deletions cue/private/tools/cue/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ constraint_setting(
name = "tool_version",
visibility = ["//visibility:public"],
)

exports_files(["toolchain.bzl"])
1 change: 1 addition & 0 deletions cue/private/tools/cue/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def declare_bazel_toolchains(version, toolchain_prefix):
constraint_setting = "{}:tool_version".format(_CONTAINING_PACKAGE_PREFIX),
)
constraint_value_prefix = "@{}//cue/private/tools".format(_MODULE_REPOSITORY_NAME)

for platform in _TOOLS_BY_RELEASE[version].keys():
native.toolchain(
name = "{}_{}_{}_toolchain".format(platform.os, platform.arch, version),
Expand Down
1 change: 1 addition & 0 deletions examples/bzlmod/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.5.0
Loading