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: 0 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import %workspace%/tools/deleted.bazelrc

build --experimental_worker_allow_json_protocol
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.0
6.0.0
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,18 @@ http_archive(
strip_prefix = "rivet-bazel-util-%s" % RIVET_BAZEL_UTIL_VERSION,
url = "https://github.com/rivethealth/rivet-bazel-util/archive/%s.tar.gz" % RIVET_BAZEL_UTIL_VERSION,
)

load("@rivet_bazel_util//ibazel:workspace.bzl", "ibazel_repositories", "ibazel_toolchains")

ibazel_repositories()

ibazel_toolchains()
```

The `@rivet_bazel_util//ibazel:toolchain_type` toolchain will download a
pre-build executable of ibazel, if it exists. Otherwise, it will rely on
`@bazel-watcher` repo to build from source.

</details>

The targets can be invoked:
Expand Down
45 changes: 10 additions & 35 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,19 @@ load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()

# Go
GO_VERSION = "v0.24.5"
GO_VERSION = "v0.38.1"

http_archive(
name = "io_bazel_rules_go",
sha256 = "d1ffd055969c8f8d431e2d439813e42326961d0942bdf734d2c95dc30c369566",
url = "https://github.com/bazelbuild/rules_go/releases/download/%s/rules_go-%s.tar.gz" % (GO_VERSION, GO_VERSION),
sha256 = "dd926a88a564a9246713a9c00b35315f54cbd46b31a26d5d8fb264c07045f05d",
url = "https://github.com/bazelbuild/rules_go/releases/download/%s/rules_go-%s.zip" % (GO_VERSION, GO_VERSION),
)

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

go_rules_dependencies()

go_register_toolchains()

# Gazelle

GAZELLE_VERSION = "v0.24.0"

http_archive(
name = "bazel_gazelle",
sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb",
urls = [
"https://github.com/bazelbuild/bazel-gazelle/releases/download/%s/bazel-gazelle-%s.tar.gz" % (GAZELLE_VERSION, GAZELLE_VERSION),
],
)

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

gazelle_dependencies()
go_register_toolchains(version = "1.19.5")

# Protobuf
http_archive(
Expand Down Expand Up @@ -134,11 +118,11 @@ file_repositories()

# JavaScript

JAVASCRIPT_VERSION = "a278dd6e24fbe28b0dde73a6ec1d267b827fab41"
JAVASCRIPT_VERSION = "0901c7fb3f6205d42e9db372f4ebc575da3e6f6d"

http_archive(
name = "better_rules_javascript",
sha256 = "f4b75ae6f3f1a2c2e0739399a7373cea3ba591a4526b9593ae2f33f5904c6a7e",
sha256 = "44b8b79cbca7b89288a605b45aab57465a840d5cdab1bfe9789d17a640d9b0ec",
strip_prefix = "rules_javascript-%s" % JAVASCRIPT_VERSION,
url = "https://github.com/rivethealth/rules_javascript/archive/%s.tar.gz" % JAVASCRIPT_VERSION,
)
Expand All @@ -147,22 +131,13 @@ load("@better_rules_javascript//rules:workspace.bzl", javascript_repositories =

javascript_repositories()

# Bazel Watcher

BAZEL_WATCHER_VERSION = "f672f1b1c48d48052b57a3d27af118bbc8f9d3e4"

http_archive(
name = "bazel_watcher",
sha256 = "68b2c09af9b5a8debc5dd5ac43c8a4eaf5693bec757481951f2cf5fae8d7b0a3",
strip_prefix = "bazel-watcher-%s" % BAZEL_WATCHER_VERSION,
url = "https://github.com/bazelbuild/bazel-watcher/archive/%s.tar.gz" % BAZEL_WATCHER_VERSION,
)
# Rivet Bazel Util

load("@bazel_watcher//:repositories.bzl", "go_repositories")
load("//ibazel:workspace.bzl", "ibazel_repositories", "ibazel_toolchains")

go_repositories()
ibazel_repositories()

# Rivet Bazel Util
ibazel_toolchains()

load("@rules_file//file:workspace.bzl", "files")

Expand Down
2 changes: 1 addition & 1 deletion bazel/watchrun/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("//package:rules.bzl", "pkg_executable")
py_binary(
name = "bin",
srcs = glob(["src/**/*.py"]),
data = ["@bazel_watcher//ibazel"],
data = ["//ibazel:bin"],
imports = ["src"],
legacy_create_init = False,
main = "src/rivetbazelutil/bazelwatchrun/__main__.py",
Expand Down
8 changes: 6 additions & 2 deletions bazel/watchrun/src/rivetbazelutil/bazelwatchrun/watchrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _ibazel(ibazel_args, bazel_args, targets):

process = subprocess.Popen(
[
r.Rlocation("bazel_watcher/ibazel/ibazel_/ibazel"),
r.Rlocation("rivet_bazel_util/ibazel/bin"),
f"-profile_dev=/dev/fd/{pipe_write}",
]
+ ibazel_args
Expand Down Expand Up @@ -127,7 +127,11 @@ def run(
width: typing.Optional[int],
):
if width is None:
width = max(len(aliases.get(target, target)) for target in targets)
width = (
max(len(aliases.get(target, target)) for target in targets)
if targets
else 80
)

try:
if not targets:
Expand Down
87 changes: 87 additions & 0 deletions ibazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
load(":rules.bzl", "ibazel")

ibazel(
name = "bin",
visibility = ["//visibility:public"]
)

toolchain_type(
name = "toolchain_type",
visibility = ["//visibility:public"]
)

toolchain(
name = "macos_arm64_toolchain",
exec_compatible_with = [
"@platforms//cpu:aarch64",
"@platforms//os:macos",
],
target_compatible_with = [
"@platforms//cpu:aarch64",
"@platforms//os:macos",
],
toolchain = "//ibazel/default:darwin_arm64",
toolchain_type = ":toolchain_type",
)

toolchain(
name = "macos_amd64_toolchain",
exec_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:macos",
],
target_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:macos",
],
toolchain = "//ibazel/default:darwin_amd64",
toolchain_type = ":toolchain_type",
)

toolchain(
name = "linux_arm64_toolchain",
exec_compatible_with = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
],
target_compatible_with = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
],
toolchain = "//ibazel/default:linux_arm64",
toolchain_type = ":toolchain_type",
)

toolchain(
name = "linux_amd64_toolchain",
exec_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
target_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
toolchain = "//ibazel/default:linux_amd64",
toolchain_type = ":toolchain_type",
)

toolchain(
name = "windows_amd64_toolchain",
exec_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
],
target_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
],
toolchain = "//ibazel/default:windows_amd64",
toolchain_type = ":toolchain_type",
)

toolchain(
name = "src_toolchain",
toolchain = "//ibazel/default:src",
toolchain_type = ":toolchain_type",
)
18 changes: 18 additions & 0 deletions ibazel/default/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("//ibazel:ibazel.bzl", "IBAZEL_REPO_NAMES")
load("//ibazel:rules.bzl", "ibazel_toolchain")

[
ibazel_toolchain(
name = name,
ibazel = "@ibazel_%s//file" % name,
visibility = ["//visibility:public"],
)
for name
in IBAZEL_REPO_NAMES
]

ibazel_toolchain(
name = "src",
ibazel = "@bazel-watcher//cmd/ibazel",
visibility = ["//visibility:public"]
)
32 changes: 32 additions & 0 deletions ibazel/ibazel.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
IBAZEL_REPO_NAMES = [
"darwin_amd64",
"darwin_arm64",
"linux_amd64",
"linux_arm64",
"windows_amd64",
]

IBAZEL_REPOS = {
"v0.21.4": {
"darwin_amd64": struct(
path = "ibazel_darwin_amd64",
sha256 = "55254ce8813a7a39505c5804d352a7d0c183994c6ed56b1ed5b18b3753dbbebb",
),
"darwin_arm64": struct(
path = "ibazel_darwin_arm64",
sha256 = "c539b5094e4b48bc10e003ebf5fda7283467e3b96754b0b7a617a2d516a4493f",
),
"linux_amd64": struct(
path = "ibazel_linux_amd64",
sha256 = "149befe61e53c69ededa0aabcd4a305b60e176ba042a712c5e8e19f37f551684"
),
"linux_arm64": struct(
path = "ibazel_linux_arm64",
sha256 = "51cf754b876942c93569e32e99171061cf3db15a5877b22989d4ea36c1b319b7",
),
"windows_amd64": struct(
path = "ibazel_windows_amd64.exe",
sha256 = "92b45ff697a98706f7d26547185d282350dd994e76185705406845e88d624565",
)
}
}
55 changes: 55 additions & 0 deletions ibazel/rules.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
load("@bazel_skylib//lib:shell.bzl", "shell")
load("@rules_file//util:path.bzl", "runfile_path")

def _ibazel_impl(ctx):
actions = ctx.actions
bash_runfiles_default = ctx.attr._bash_runfiles[DefaultInfo]
ibazel = ctx.toolchains[":toolchain_type"]
name = ctx.attr.name
template = ctx.file._template
workspace = ctx.workspace_name

executable = actions.declare_file(name)
actions.expand_template(
is_executable = True,
substitutions = {
"%{exec}": shell.quote(runfile_path(workspace, ibazel.ibazel)),
},
template = template,
output = executable,
)

runfiles = ctx.runfiles(files = [ibazel.ibazel])
runfiles = runfiles.merge(bash_runfiles_default.default_runfiles)
default_info = DefaultInfo(executable = executable, runfiles = runfiles)

return [default_info]

ibazel = rule(
attrs = {
"_bash_runfiles": attr.label(
default = "@bazel_tools//tools/bash/runfiles",
),
"_template": attr.label(allow_single_file = True, default = ":runner.sh.tpl"),
},
executable = True,
implementation = _ibazel_impl,
toolchains = [":toolchain_type"],
)


def _ibazel_toolchain_impl(ctx):
ibazel = ctx.file.ibazel

toolchain_info = platform_common.ToolchainInfo(
ibazel = ibazel
)

return [toolchain_info]

ibazel_toolchain = rule(
implementation = _ibazel_toolchain_impl,
attrs = {
"ibazel": attr.label(allow_single_file = True, mandatory = True),
},
)
14 changes: 14 additions & 0 deletions ibazel/runner.sh.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2.
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v2 ---

exec "$(rlocation %{exec})" "$@"
21 changes: 21 additions & 0 deletions ibazel/workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
load(":ibazel.bzl", "IBAZEL_REPOS")

def ibazel_repositories(version = "v0.21.4"):
for name, info in IBAZEL_REPOS[version].items():
http_file(
name = "ibazel_%s" % name,
executable = True,
sha256 = info.sha256,
url = "https://github.com/bazelbuild/bazel-watcher/releases/download/%s/%s" % (version, info.path),
)

def ibazel_toolchains():
native.register_toolchains(
"@rivet_bazel_util//ibazel:macos_amd64_toolchain",
"@rivet_bazel_util//ibazel:macos_arm64_toolchain",
"@rivet_bazel_util//ibazel:linux_amd64_toolchain",
"@rivet_bazel_util//ibazel:linux_arm64_toolchain",
"@rivet_bazel_util//ibazel:windows_amd64_toolchain",
"@rivet_bazel_util//ibazel:src_toolchain",
)