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] Migrate rules_python and dependents to bzlmod #25650

Merged
merged 7 commits into from
Dec 17, 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
12 changes: 12 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@

module(name = "lowrisc_opentitan")

bazel_dep(name = "bazel_skylib", version = "1.5.0")

include("//third_party/rust:rust.MODULE.bazel")

include("//third_party/python:python.MODULE.bazel")

include("//third_party/lint:lint.MODULE.bazel")

include("//third_party/google:google.MODULE.bazel")

bitstreams_repo = use_repo_rule("//rules:bitstreams.bzl", "bitstreams_repo")

bitstreams_repo(name = "bitstreams")
178 changes: 158 additions & 20 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

31 changes: 0 additions & 31 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,6 @@

workspace(name = "lowrisc_opentitan")

# Bazel skylib library
load("//third_party/skylib:repos.bzl", "bazel_skylib_repos")
bazel_skylib_repos()
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()

# Python Toolchain + PIP Dependencies
load("//third_party/python:repos.bzl", "python_repos")
python_repos()
load("//third_party/python:deps.bzl", "python_deps")
python_deps()
load("//third_party/python:pip.bzl", "pip_deps")
pip_deps()
load("@ot_python_deps//:requirements.bzl", install_ot_python_deps="install_deps")
install_ot_python_deps()

# Google/Bazel dependencies. This needs to be after Python initialization
# so that our preferred python configuration takes precedence.
load("//third_party/google:repos.bzl", "google_repos")
Expand Down Expand Up @@ -54,22 +38,11 @@ go_deps()
# Various linters
load("//third_party/lint:repos.bzl", "lint_repos")
lint_repos()
load("//third_party/lint:deps.bzl", "lint_deps")
lint_deps()
load("@lowrisc_misc_linters_pip//:requirements.bzl", install_lowrisc_lint_python_deps="install_deps")
install_lowrisc_lint_python_deps()

# Lychee link checker.
load("//third_party/lychee:repos.bzl", "lychee_repos")
lychee_repos()

load("//third_party/google:repos.bzl", "fuzzing_repos")
fuzzing_repos()
load("//third_party/google:fuzzing_deps.bzl", "fuzzing_deps")
fuzzing_deps()
load("@fuzzing_py_deps//:requirements.bzl", install_fuzzing_python_deps="install_deps")
install_fuzzing_python_deps()

# Rust Toolchain + crates.io Dependencies
load("//third_party/rust:repos.bzl", "rust_repos")
rust_repos()
Expand Down Expand Up @@ -133,10 +106,6 @@ wycheproof_repos()
load("//third_party/sphincsplus:repos.bzl", "sphincsplus_repos")
sphincsplus_repos()

# Bitstreams from https://storage.googleapis.com/opentitan-bitstreams/
load("//rules:bitstreams.bzl", "bitstreams_repo")
bitstreams_repo(name = "bitstreams")

# CBOR reader & writer from open-dice
load("//third_party/open-dice:repos.bzl", "open_dice_repos")
open_dice_repos()
Expand Down
2 changes: 1 addition & 1 deletion quality/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0

load("@bazelbuild_buildtools//buildifier:def.bzl", "buildifier", "buildifier_test")
load("@lowrisc_lint//rules:rules.bzl", "licence_test")
load("@lowrisc_misc_linters//rules:rules.bzl", "licence_test")
load("//rules:quality.bzl", "clang_format_check", "clang_format_test", "clang_tidy_rv_test", "clang_tidy_test", "html_coverage_report", "rustfmt_fix", "rustfmt_test")

package(default_visibility = ["//visibility:public"])
Expand Down
4 changes: 1 addition & 3 deletions rules/bitstreams.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ particular bitstream or use cached version for the next cache entry, for each
design (i.e. mix-and-match).
"""

load("@python3//:defs.bzl", "interpreter")

def _bitstreams_repo_impl(rctx):
# First, check if an existing pre-built bitstream cache repo exists, and if
# so, use it instead of building one.
Expand Down Expand Up @@ -112,7 +110,7 @@ bitstreams_repo = repository_rule(
default = 18 * 3600, # Refresh every 18h
),
"python_interpreter": attr.label(
default = interpreter,
default = "@python3_host//:python",
allow_single_file = True,
doc = "Python interpreter to use.",
),
Expand Down
9 changes: 8 additions & 1 deletion rules/linker.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""Rules for declaring linker scripts and linker script fragments."""

def _ld_library_impl(ctx):
files = [] + ctx.files.includes
files = []
user_link_flags = []

# Disable non-volatile scratch region and counters if building for english
Expand All @@ -20,6 +20,13 @@ def _ld_library_impl(ctx):
"-Wl,-nmagic",
]

if ctx.files.includes:
files += ctx.files.includes
user_link_flags += [
"-Wl,-L,{}".format(include.dirname)
for include in ctx.files.includes
]

if ctx.file.script:
files += ctx.files.script
user_link_flags += [
Expand Down
36 changes: 8 additions & 28 deletions rules/repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

load("@python3//:defs.bzl", "interpreter")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_skylib//lib:paths.bzl", "paths")

Expand All @@ -29,18 +28,14 @@ def http_archive_or_local(local = None, **kwargs):

def _bare_repository_impl(rctx):
if rctx.attr.local:
workspace_root = str(rctx.path(rctx.attr.workspace).dirname.realpath)
result = rctx.execute(
[
rctx.path(rctx.attr.python_interpreter),
rctx.attr._symlink_tree,
paths.join(workspace_root, rctx.attr.local),
".",
],
quiet = False,
)
if result.return_code != 0:
fail("Error initializing repo for {}".format(rctx.attr.local))
# Although not particularly well documented, the `get_child` function will only add
# the workspace for relative paths, and simply ignore it if given an absolute path.
path = rctx.workspace_root.get_child(rctx.attr.local)

# NOTE By default, Bazel will automatically watch those directories and refetch
# the repository if they change.
for child in path.readdir():
rctx.symlink(child, child.basename)
elif rctx.attr.url:
rctx.download_and_extract(
url = rctx.attr.url,
Expand Down Expand Up @@ -68,21 +63,6 @@ bare_repository = repository_rule(
"additional_files_content": attr.string_dict(
doc = "Additional files to place in the repository (mapping repo filename to strings).",
),
"python_interpreter": attr.label(
default = interpreter,
allow_single_file = True,
doc = "Python interpreter to use.",
),
"_symlink_tree": attr.label(
default = Label("//rules/scripts:symlink_tree.py"),
allow_files = True,
doc = "Script to create symlink trees for the `local` case.",
),
"workspace": attr.label(
default = Label("//:WORKSPACE.bzlmod"),
allow_single_file = True,
doc = "Root workspace.",
),
},
doc = """
A bare_repository is a repo that needs additional files (such as a BUILD hierarchy)
Expand Down
82 changes: 0 additions & 82 deletions rules/scripts/symlink_tree.py

This file was deleted.

11 changes: 1 addition & 10 deletions sw/device/silicon_owner/tock/apps/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@ load("//rules:linker.bzl", "ld_library")

package(default_visibility = ["//visibility:public"])

ld_library(
name = "libtock_layout",
includes = [
"@libtock//build_scripts:layout",
],
)

ld_library(
name = "single_app_layout",
includes = ["@libtock//build_scripts:layout"],
script = "single_app_layout.ld",
deps = [
":libtock_layout",
],
)
4 changes: 1 addition & 3 deletions sw/device/silicon_owner/tock/apps/single_app_layout.ld
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ FLASH_LENGTH = 32M;
RAM_START = 0x10005000;
RAM_LENGTH = 512K;

/* TODO(cfrantz): Fix the ld_library rule to allow include paths and avoid */
/* having to specify an `external` path here */
INCLUDE external/libtock/build_scripts/libtock_layout.ld
INCLUDE libtock_layout.ld
11 changes: 1 addition & 10 deletions sw/device/silicon_owner/tock/kernel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,10 @@ load("//rules/opentitan:defs.bzl", "OPENTITAN_CPU")

package(default_visibility = ["//visibility:public"])

ld_library(
name = "kernel_layout",
includes = [
"@tock//boards:kernel_layout",
],
)

ld_library(
name = "layout",
includes = ["@tock//boards:kernel_layout"],
script = "layout.ld",
deps = [
":kernel_layout",
],
)

cc_library(
Expand Down
4 changes: 1 addition & 3 deletions sw/device/silicon_owner/tock/kernel/layout.ld
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,4 @@ SECTIONS {
}

ASSERT (((_etext - _manifest) > 0), "Error: PMP and Flash protection setup assumes _etext follows _manifest");
/* TODO(cfrantz): Fix the ld_library rule to allow include paths and avoid */
/* having to specify an `external` path here */
INCLUDE external/tock/boards/kernel_layout.ld
INCLUDE kernel_layout.ld
11 changes: 1 addition & 10 deletions sw/device/silicon_owner/tock/upstream_kernel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,10 @@ load("//rules/opentitan:legacy.bzl", "obj_transform")

package(default_visibility = ["//visibility:public"])

ld_library(
name = "kernel_layout",
includes = [
"@tock//boards:kernel_layout",
],
)

ld_library(
name = "layout",
includes = ["@tock//boards:kernel_layout"],
script = "layout.ld",
deps = [
":kernel_layout",
],
)

cc_library(
Expand Down
4 changes: 1 addition & 3 deletions sw/device/silicon_owner/tock/upstream_kernel/layout.ld
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,4 @@ SECTIONS {
}

ASSERT (((_etext - _manifest) > 0), "Error: PMP and Flash protection setup assumes _etext follows _manifest");
/* TODO(cfrantz): Fix the ld_library rule to allow include paths and avoid */
/* having to specify an `external` path here */
INCLUDE external/tock/boards/kernel_layout.ld
INCLUDE kernel_layout.ld
10 changes: 0 additions & 10 deletions third_party/google/fuzzing_deps.bzl

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

package(default_visibility = ["//visibility:public"])
bazel_dep(name = "rules_fuzzing", version = "0.5.2")
8 changes: 0 additions & 8 deletions third_party/google/repos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,3 @@ def google_repos(
sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz",
)

def fuzzing_repos():
http_archive_or_local(
name = "rules_fuzzing",
sha256 = "e6bc219bfac9e1f83b327dd090f728a9f973ee99b9b5d8e5a184a2732ef08623",
strip_prefix = "rules_fuzzing-0.5.2",
urls = ["https://github.com/bazelbuild/rules_fuzzing/releases/download/v0.5.2/rules_fuzzing-0.5.2.zip"],
)
10 changes: 0 additions & 10 deletions third_party/lint/deps.bzl

This file was deleted.

Loading
Loading