Skip to content

Commit

Permalink
[bazelisk] Use Bazel 7.1.2 (#349)
Browse files Browse the repository at this point in the history
install_prereqs: Use Bazelisk
environ.bzl: Use workaround for attr.string_list() from Anzu

Co-authored-by: Jeremy Nimmer <jeremy.nimmer@tri.global>
  • Loading branch information
EricCousineau-TRI and jwnimmer-tri authored May 13, 2024
1 parent 955245e commit f3c5497
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .lint/.bazeliskrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# When bazelisk in use, this dotfile specifies which version of Bazel should be
# used to build and test.
USE_BAZEL_VERSION=6.4.0
USE_BAZEL_VERSION=7.1.2
2 changes: 2 additions & 0 deletions .lint/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Import base-level build configuration.
import %workspace%/../default.bazelrc
2 changes: 1 addition & 1 deletion bazel_ros2_rules/.bazeliskrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# When bazelisk in use, this dotfile specifies which version of Bazel should be
# used to build and test.
USE_BAZEL_VERSION=6.4.0
USE_BAZEL_VERSION=7.1.2
8 changes: 5 additions & 3 deletions bazel_ros2_rules/setup/install_prereqs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ function dpkg_install_from_curl() {

apt install g++ unzip zlib1g-dev

# TODO(eric.cousineau) Once there's a bazelisk 1.20 that incorporates pr563, we
# should switch to using that here.
dpkg_install_from_curl \
bazel 6.4.0 \
https://github.com/bazelbuild/bazel/releases/download/6.4.0/bazel_6.4.0-linux-x86_64.deb \
9276a1e11f03e9f7492f009803c95bddc307993c9ab3c463721c9f6cdaa2ccc1
bazelisk 1.19.0 \
https://drake-mirror.csail.mit.edu/github/bazelbuild/bazelisk/pr563/bazelisk_1.19.0-9-g58a850f_amd64.deb \
c2bfd15d6c3422ae540cda9facc0ac395005e2701c09dbb15d40447b53e831d4

# Install Python dependencies
apt install python3 python3-toposort python3-dev python-is-python3
3 changes: 3 additions & 0 deletions default.bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Don't use bzlmod (yet); eventually we'll want to enable this.
common --enable_bzlmod=false

# Use C++20.
build --cxxopt=-std=c++20
build --host_cxxopt=-std=c++20
Expand Down
2 changes: 1 addition & 1 deletion drake_ros/.bazeliskrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# When bazelisk in use, this dotfile specifies which version of Bazel should be
# used to build and test.
USE_BAZEL_VERSION=6.4.0
USE_BAZEL_VERSION=7.1.2
2 changes: 1 addition & 1 deletion drake_ros_examples/.bazeliskrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# When bazelisk in use, this dotfile specifies which version of Bazel should be
# used to build and test.
USE_BAZEL_VERSION=6.4.0
USE_BAZEL_VERSION=7.1.2
2 changes: 1 addition & 1 deletion ros2_example_bazel_installed/.bazeliskrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# When bazelisk in use, this dotfile specifies which version of Bazel should be
# used to build and test.
USE_BAZEL_VERSION=6.4.0
USE_BAZEL_VERSION=7.1.2
9 changes: 5 additions & 4 deletions ros2_example_bazel_installed/setup/install_prereqs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ function dpkg_install_from_curl() {

apt install g++ unzip zlib1g-dev

# TODO(sloretz) Make sure the version of bazel is exactly the same as the one used by Drake
# TODO(eric.cousineau) Once there's a bazelisk 1.20 that incorporates pr563, we
# should switch to using that here.
dpkg_install_from_curl \
bazel 6.4.0 \
https://github.com/bazelbuild/bazel/releases/download/6.4.0/bazel_6.4.0-linux-x86_64.deb \
9276a1e11f03e9f7492f009803c95bddc307993c9ab3c463721c9f6cdaa2ccc1
bazelisk 1.19.0 \
https://drake-mirror.csail.mit.edu/github/bazelbuild/bazelisk/pr563/bazelisk_1.19.0-9-g58a850f_amd64.deb \
c2bfd15d6c3422ae540cda9facc0ac395005e2701c09dbb15d40447b53e831d4

# If the user did not explicitly specify their installation prefix, install
# ROS 2 Humble.
Expand Down
51 changes: 33 additions & 18 deletions ros2_example_bazel_installed/tools/environ.bzl
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
# -*- python -*-
# -*- mode: python -*-
# vi: set ft=python :

def _environment_repository_impl(repo_ctx):
environ = {
envvar: repo_ctx.os.environ.get(envvar, "")
for envvar in repo_ctx.attr._envvars
}
repo_ctx.file(
# Write out a repository that contains:
# - An empty BUILD file, to define a package.
# - An environ.bzl file with variable assignments for each ENV_NAMES item.
def _impl(repository_ctx):
envvars = repository_ctx.attr.envvars
bzl_content = []
for key in envvars:
value = repository_ctx.os.environ.get(key, "")
bzl_content.append("{}='{}'\n".format(key, value))
repository_ctx.file(
"BUILD.bazel",
content = "# Empty build file to mark repository root.\n",
content = "\n",
executable = False,
)
repo_ctx.file(
repository_ctx.file(
"environ.bzl",
content = "\n".join([
"{}=\"{}\"".format(name, value)
for name, value in environ.items()
]),
content = "".join(bzl_content),
executable = False,
)

def environment_repository(name, envvars):
_string_list = attr.string_list()

def environment_repository(name = None, envvars = []):
"""Provide specific environment variables for use in a WORKSPACE file.
The `envvars` are the environment variables to provide.
Example:
environ_repository(name = "foo", envvars = ["BAR", "BAZ"])
load("@foo//:environ.bzl", "BAR", "BAZ")
print(BAR)
"""
rule = repository_rule(
implementation = _impl,
attrs = {
"_envvars": attr.string_list(default = envvars),
"envvars": _string_list,
},
implementation = _environment_repository_impl,
environ = envvars,
local = True,
environ = envvars,
)
rule(
name = name,
envvars = envvars,
)
rule(name = name)

0 comments on commit f3c5497

Please sign in to comment.