Skip to content

Commit

Permalink
[bazel] Switch lowRISC toolchain from CRT to local version
Browse files Browse the repository at this point in the history
This removes the dependency on CRT and registers the new rules-based
toolchain instead.

Since `guards` is now enabled by default and `pedantic` is now disabled
by default, we can remove those configurations from `.bazelrc`. The
configuration to disable `guards` is still present.

Without CRT, we also don't need to manually load the following repos
into the airgapped environment:

* `@python3_toolchains`
* `@ninja_1.11.0_linux`
* `@cmake-3.23.2-linux-x86_64`

We also now need to switch how we access objdump in our disassembly
rule to use the actions-based method. See previous commits.

Signed-off-by: James Wainwright <[email protected]>
  • Loading branch information
jwnrt committed Jan 10, 2025
1 parent b15348e commit 00d1e21
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 52 deletions.
10 changes: 0 additions & 10 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ build --conlyopt='-std=gnu11'
# disassemblies when compilation mode is fastbuild.
build --strip='never'

# Override default enablement of flags from @crt//common to control C compiler
# warnings.
build --features=-pedantic_warnings
build --host_features=-pedantic_warnings

# Enable toolchain hardening features.
# `guards` adds `unimp` guard instructions after unconditional jumps.
build --features=guards
build --host_features=guards

# Use --config=disable_hardening to disable hardening to measure the
# impact of the hardened sequences on code size.
build:disable_hardening --features=-guards --copt=-DOT_DISABLE_HARDENING=1
Expand Down
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,5 @@ use_repo(
)

register_toolchains("//rules/opentitan:localtools")

register_toolchains("//toolchain:cc_toolchain_opentitan")
11 changes: 0 additions & 11 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,3 @@
# //third_party/README.md first.

workspace(name = "lowrisc_opentitan")

# CRT is the Compiler Repository Toolkit. It contains the configuration for
# the windows compiler.
load("//third_party/crt:repos.bzl", "crt_repos")
crt_repos()
load("@crt//:repos.bzl", "crt_repos")
crt_repos()
load("@crt//:deps.bzl", "crt_deps")
crt_deps()
load("@crt//config:registration.bzl", "crt_register_toolchains")
crt_register_toolchains(riscv32 = True)
14 changes: 13 additions & 1 deletion rules/opentitan/transform.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load("@rules_cc//cc:action_names.bzl", "OBJ_COPY_ACTION_NAME")
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@lowrisc_opentitan//rules/opentitan:util.bzl", "get_override")
load("//rules:actions.bzl", "OT_ACTION_OBJDUMP")

def obj_transform(ctx, **kwargs):
"""Transform an object file via objcopy.
Expand Down Expand Up @@ -69,6 +70,17 @@ def obj_disassemble(ctx, **kwargs):
The disassembled File.
"""
cc_toolchain = find_cc_toolchain(ctx)
feature_config = cc_common.configure_features(
ctx = ctx,
cc_toolchain = cc_toolchain,
requested_features = ctx.features,
unsupported_features = ctx.disabled_features,
)
objdump = cc_common.get_tool_for_action(
feature_configuration = feature_config,
action_name = OT_ACTION_OBJDUMP,
)

output = kwargs.get("output")
if not output:
name = get_override(ctx, "attr.name", kwargs)
Expand All @@ -81,7 +93,7 @@ def obj_disassemble(ctx, **kwargs):
outputs = [output],
inputs = [src] + cc_toolchain.all_files.to_list(),
arguments = [
cc_toolchain.objdump_executable,
objdump,
src.path,
output.path,
],
Expand Down
2 changes: 1 addition & 1 deletion rules/rv.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""Helpers for transitioning to the RISC-V target."""

OPENTITAN_CPU = "@platforms//cpu:riscv32"
OPENTITAN_PLATFORM = "@crt//platforms/riscv32:opentitan"
OPENTITAN_PLATFORM = "//toolchain:opentitan_platform"

# This constant holds a dictionary of per-device dependencies which are used to
# generate slightly different binaries for each hardware target, including two
Expand Down
5 changes: 0 additions & 5 deletions third_party/crt/BUILD.bazel

This file was deleted.

21 changes: 0 additions & 21 deletions third_party/crt/repos.bzl

This file was deleted.

3 changes: 0 additions & 3 deletions util/prep-bazel-airgapped-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,8 @@ if [[ ${AIRGAPPED_DIR_CONTENTS} == "ALL" || \
//... \
@lowrisc_rv32imcb_toolchain//... \
@local_config_platform//... \
@python3_toolchains//... \
@riscv-compliance//... \
@rules_foreign_cc//toolchains/... \
@ninja_1.11.0_linux//... \
@cmake-3.23.2-linux-x86_64//... \
# We don't need all bitstreams in the cache, we just need the latest one so
# that the cache is "initialized" and "offline" mode will work correctly.
mkdir -p ${BAZEL_AIRGAPPED_DIR}/${BAZEL_BITSTREAMS_CACHEDIR}
Expand Down

0 comments on commit 00d1e21

Please sign in to comment.