Skip to content

Commit cd62deb

Browse files
committed
[bazel] Switch lowRISC toolchain from CRT to local version
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 <james.wainwright@lowrisc.org>
1 parent af8209d commit cd62deb

File tree

6 files changed

+16
-26
lines changed

6 files changed

+16
-26
lines changed

.bazelrc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ build --conlyopt='-std=gnu11'
1414
# disassemblies when compilation mode is fastbuild.
1515
build --strip='never'
1616

17-
# Override default enablement of flags from @crt//common to control C compiler
18-
# warnings.
19-
build --features=-pedantic_warnings
20-
build --host_features=-pedantic_warnings
21-
22-
# Enable toolchain hardening features.
23-
# `guards` adds `unimp` guard instructions after unconditional jumps.
24-
build --features=guards
25-
build --host_features=guards
26-
2717
# Use --config=disable_hardening to disable hardening to measure the
2818
# impact of the hardened sequences on code size.
2919
build:disable_hardening --features=-guards --copt=-DOT_DISABLE_HARDENING=1

MODULE.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,5 @@ use_repo(
143143
)
144144

145145
register_toolchains("//rules/opentitan:localtools")
146+
147+
register_toolchains("//toolchain:cc_toolchain_opentitan")

WORKSPACE.bzlmod

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,3 @@
66
# //third_party/README.md first.
77

88
workspace(name = "lowrisc_opentitan")
9-
10-
# CRT is the Compiler Repository Toolkit. It contains the configuration for
11-
# the windows compiler.
12-
load("//third_party/crt:repos.bzl", "crt_repos")
13-
crt_repos()
14-
load("@crt//:repos.bzl", "crt_repos")
15-
crt_repos()
16-
load("@crt//:deps.bzl", "crt_deps")
17-
crt_deps()
18-
load("@crt//config:registration.bzl", "crt_register_toolchains")
19-
crt_register_toolchains(riscv32 = True)

rules/opentitan/transform.bzl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ load("@rules_cc//cc:action_names.bzl", "OBJ_COPY_ACTION_NAME")
77
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
88
load("@bazel_skylib//lib:paths.bzl", "paths")
99
load("@lowrisc_opentitan//rules/opentitan:util.bzl", "get_override")
10+
load("//rules:actions.bzl", "OT_ACTION_OBJDUMP")
1011

1112
def obj_transform(ctx, **kwargs):
1213
"""Transform an object file via objcopy.
@@ -69,6 +70,17 @@ def obj_disassemble(ctx, **kwargs):
6970
The disassembled File.
7071
"""
7172
cc_toolchain = find_cc_toolchain(ctx)
73+
feature_config = cc_common.configure_features(
74+
ctx = ctx,
75+
cc_toolchain = cc_toolchain,
76+
requested_features = ctx.features,
77+
unsupported_features = ctx.disabled_features,
78+
)
79+
objdump = cc_common.get_tool_for_action(
80+
feature_configuration = feature_config,
81+
action_name = OT_ACTION_OBJDUMP,
82+
)
83+
7284
output = kwargs.get("output")
7385
if not output:
7486
name = get_override(ctx, "attr.name", kwargs)
@@ -81,7 +93,7 @@ def obj_disassemble(ctx, **kwargs):
8193
outputs = [output],
8294
inputs = [src] + cc_toolchain.all_files.to_list(),
8395
arguments = [
84-
cc_toolchain.objdump_executable,
96+
objdump,
8597
src.path,
8698
output.path,
8799
],

rules/rv.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""Helpers for transitioning to the RISC-V target."""
66

77
OPENTITAN_CPU = "@platforms//cpu:riscv32"
8-
OPENTITAN_PLATFORM = "@crt//platforms/riscv32:opentitan"
8+
OPENTITAN_PLATFORM = "//toolchain:opentitan_platform"
99

1010
# This constant holds a dictionary of per-device dependencies which are used to
1111
# generate slightly different binaries for each hardware target, including two

util/prep-bazel-airgapped-build.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,8 @@ if [[ ${AIRGAPPED_DIR_CONTENTS} == "ALL" || \
143143
//... \
144144
@lowrisc_rv32imcb_toolchain//... \
145145
@local_config_platform//... \
146-
@python3_toolchains//... \
147146
@riscv-compliance//... \
148147
@rules_foreign_cc//toolchains/... \
149-
@ninja_1.11.0_linux//... \
150-
@cmake-3.23.2-linux-x86_64//... \
151148
# We don't need all bitstreams in the cache, we just need the latest one so
152149
# that the cache is "initialized" and "offline" mode will work correctly.
153150
mkdir -p ${BAZEL_AIRGAPPED_DIR}/${BAZEL_BITSTREAMS_CACHEDIR}

0 commit comments

Comments
 (0)