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

[bazel] Enable bzlmod in hybrid mode #24781

Merged
merged 4 commits into from
Nov 29, 2024
Merged
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
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

# Opt-out of bzlmod for now and continue to use `WORKSPACE`.
common --noenable_bzlmod
# Enable bzlmod using both `MODULE.bazel` and `WORKSPACE.bzlmod`.
common --enable_bzlmod

# https://docs.opentitan.org/doc/rm/c_cpp_coding_style/#cxx-version specifies
build --action_env=BAZEL_CXXOPTS="-std=gnu++14"
Expand Down
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ sw/**/*.md doc
sw/**/*.svg doc
sw/**/*.jpg doc
sw/**/*.png doc

# Generated lock files
MODULE.bazel.lock linguist-generated=true
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package(default_visibility = ["//visibility:public"])

exports_files([
"WORKSPACE",
"WORKSPACE.bzlmod",
"python-requirements.txt",
"tool_requirements.py",
])
Expand Down
5 changes: 5 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

module(name = "lowrisc_opentitan")
110 changes: 110 additions & 0 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
4 changes: 3 additions & 1 deletion apt-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ clang-format
cmake
curl
doxygen
file
flex
g++
git
Expand Down Expand Up @@ -48,5 +49,6 @@ python3-wheel
srecord
tree
xsltproc
zlib1g-dev
xz-utils
zip
zlib1g-dev
12 changes: 6 additions & 6 deletions quality/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ licence_test(
Licensed under the Apache License, Version 2.0, see LICENSE for details.
SPDX-License-Identifier: Apache-2.0
""",
workspace = "//:WORKSPACE",
workspace = "//:WORKSPACE.bzlmod",
)

format_exclude = [
Expand All @@ -99,7 +99,7 @@ clang_format_test(
name = "clang_format_check",
exclude_patterns = format_exclude,
mode = "diff",
workspace = "//:WORKSPACE",
workspace = "//:WORKSPACE.bzlmod",
)

clang_format_check(
Expand Down Expand Up @@ -141,7 +141,7 @@ test_suite(
)

buildifier_exclude = [
"./WORKSPACE", # Prevent Buildifier from inserting unnecessary newlines.
"./WORKSPACE.bzlmod", # Prevent Buildifier from inserting unnecessary newlines.
"./**/vendor/**",
"./build/**",
"./third_party/rust/crates/crates.bzl", # Autogenerated by cargo-raze
Expand All @@ -159,7 +159,7 @@ buildifier_test(
mode = "diff",
no_sandbox = True,
verbose = True,
workspace = "//:WORKSPACE",
workspace = "//:WORKSPACE.bzlmod",
)

# TODO(cfrantz): Find a way to keep this list of rust targets synchronized
Expand Down Expand Up @@ -194,7 +194,7 @@ RUST_TARGETS = [
rustfmt_test(
name = "rustfmt_check",
exclude_patterns = format_exclude,
workspace = "//:WORKSPACE",
workspace = "//:WORKSPACE.bzlmod",
)

rustfmt_fix(
Expand All @@ -210,7 +210,7 @@ sh_test(
name = "shellcheck_check",
srcs = ["//util/sh/scripts:run-shellcheck.sh"],
data = [
"//:WORKSPACE",
"//:WORKSPACE.bzlmod",
"@shellcheck",
],
env = {
Expand Down
2 changes: 1 addition & 1 deletion rules/repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bare_repository = repository_rule(
doc = "Script to create symlink trees for the `local` case.",
),
"workspace": attr.label(
default = Label("//:WORKSPACE"),
default = Label("//:WORKSPACE.bzlmod"),
allow_single_file = True,
doc = "Root workspace.",
),
Expand Down
2 changes: 1 addition & 1 deletion rules/scripts/clang_format.template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ elif [[ ! -z "${BUILD_WORKSPACE_DIRECTORY+is_set}" ]]; then
cd ${BUILD_WORKSPACE_DIRECTORY} || exit 1
else
echo "Neither WORKSPACE nor BUILD_WORKSPACE_DIRECTORY were set."
echo "If this is a test rule, add 'workspace = \"//:WORKSPACE\"' to your rule."
echo "If this is a test rule, add 'workspace = \"//:WORKSPACE.bzlmod\"' to your rule."
exit 1
fi

Expand Down
2 changes: 1 addition & 1 deletion rules/scripts/rustfmt.template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ elif [[ -n "${BUILD_WORKSPACE_DIRECTORY+is_set}" ]]; then
cd "${BUILD_WORKSPACE_DIRECTORY}" || exit 1
else
echo "Neither WORKSPACE nor BUILD_WORKSPACE_DIRECTORY were set."
echo "If this is a test rule, add 'workspace = \"//:WORKSPACE\"' to your rule."
echo "If this is a test rule, add 'workspace = \"//:WORKSPACE.bzlmod\"' to your rule."
exit 1
fi

Expand Down
6 changes: 3 additions & 3 deletions third_party/python/repos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
def python_repos():
http_archive(
name = "rules_python",
sha256 = "ca77768989a7f311186a29747e3e95c936a41dffac779aff6b443db22290d913",
strip_prefix = "rules_python-0.36.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.36.0/rules_python-0.36.0.tar.gz",
sha256 = "62ddebb766b4d6ddf1712f753dac5740bea072646f630eb9982caa09ad8a7687",
strip_prefix = "rules_python-0.39.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.39.0/rules_python-0.39.0.tar.gz",
)
5 changes: 0 additions & 5 deletions util/prep-bazel-airgapped-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,12 @@ if [[ ${AIRGAPPED_DIR_CONTENTS} == "ALL" || \
${BAZELISK} fetch \
--repository_cache=${BAZEL_AIRGAPPED_DIR}/${BAZEL_CACHEDIR} \
//... \
@remote_java_tools//... \
@remote_java_tools_linux//... \
@bindgen_clang_linux//... \
@rules_rust_bindgen__bindgen-0.69.1//... \
@go_sdk//... \
@lowrisc_rv32imcb_files//... \
@local_config_cc_toolchains//... \
@local_config_platform//... \
@local_config_sh//... \
@python3_toolchains//... \
@remotejdk11_linux//... \
@riscv-compliance//... \
@rules_foreign_cc//toolchains/... \
@ninja_1.11.0_linux//... \
Expand Down
8 changes: 4 additions & 4 deletions util/sh/scripts/run-shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
set -e

# Escape the sandbox when running under `bazel test`. This script assumes that
# when it's invoked by Bazel, the Bazel target will depend on `//:WORKSPACE`.
# when it's invoked by Bazel, the Bazel target will depend on `//:WORKSPACE.bzlmod`.
# This assumption enables us to infer that we're running in the sandbox when we
# see a symlink named "WORKSPACE".
if [[ -L WORKSPACE ]]; then
# see a symlink named "WORKSPACE.bzlmod".
if [[ -L WORKSPACE.bzlmod ]]; then
SHELLCHECK="$(realpath "${SHELLCHECK}")"
REPO_TOP="$(dirname "$(realpath WORKSPACE)")"
REPO_TOP="$(dirname "$(realpath WORKSPACE.bzlmod)")"
cd "${REPO_TOP}"
else
REPO_TOP="$(git rev-parse --show-toplevel)"
Expand Down
Loading