Skip to content

Commit acf6b42

Browse files
committed
[#71185] Support choosing a portable and locally built Renode
1 parent 69605fe commit acf6b42

File tree

10 files changed

+201
-46
lines changed

10 files changed

+201
-46
lines changed

.ci.yml

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,52 @@ variables:
1515
wget -nv "$BAZELISK_URL" -O /usr/local/bin/bazelisk && \
1616
chmod +x /usr/local/bin/bazelisk
1717

18+
.examples_artifacts: &examples_artifacts
19+
after_script:
20+
- mkdir artifacts
21+
- cp -LR examples/*/bazel-testlogs/* artifacts
22+
artifacts:
23+
when:
24+
always
25+
paths:
26+
- artifacts
27+
1828
.default_bazel_version: &default_bazel_version
19-
USE_BAZEL_VERSION: 7.4.1
29+
variables:
30+
USE_BAZEL_VERSION: 7.4.1
2031

2132
test_examples:
2233
image: debian:12-slim
2334
stage: test
2435
<<: *common_triggers
25-
variables:
26-
<<: *default_bazel_version
36+
<<: *default_bazel_version
2737
before_script:
2838
- *install_bazelisk
2939
script:
30-
- useradd -m non_root
31-
- chmod a+w -R .
3240
- pushd examples/cortex-r52
33-
# rules_python doesn't support a hermetic toolchain run by root
34-
- su non_root -c "bazelisk test //:all"
35-
- ls bazel-testlogs/*/test.outputs/outputs.zip
41+
- bazelisk test //:all
3642
- popd
3743
- pushd examples/failing-test
38-
- su non_root -c "! bazelisk test //:all > test.log || exit 1"
39-
- ls bazel-testlogs/*/test.outputs/outputs.zip
44+
- "! bazelisk test //:all > test.log || exit 1"
4045
- grep -E "//:success-test +PASSED" test.log
4146
- grep -E "//:failing-test +FAILED" test.log
4247
- popd
43-
after_script:
44-
- mkdir artifacts
45-
- cp -LR examples/*/bazel-testlogs/* artifacts
46-
artifacts:
47-
when:
48-
always
49-
paths:
50-
- artifacts
48+
<<: *examples_artifacts
49+
50+
test_local_renode:
51+
image: mcr.microsoft.com/dotnet/sdk:8.0
52+
stage: test
53+
<<: *common_triggers
54+
<<: *default_bazel_version
55+
before_script:
56+
- *install_bazelisk
57+
script:
58+
- apt -y install git automake cmake autoconf libtool g++ coreutils policykit-1
59+
- pushd examples/local-renode
60+
- git clone --no-progress https://github.com/renode/renode.git
61+
- pushd renode
62+
- ./build.sh --net
63+
- popd
64+
- bazelisk test //:all
65+
- popd
66+
<<: *examples_artifacts

.github/workflows/bazel_test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ jobs:
2626
grep -E "//:success-test +PASSED" test.log
2727
grep -E "//:failing-test +FAILED" test.log
2828
popd
29+
pushd examples/local-renode
30+
git clone --no-progress https://github.com/renode/renode.git
31+
pushd renode
32+
./build.sh --net
33+
popd
34+
bazelisk test //:all
35+
popd
2936
3037
- name: Upload Bazel artifacts
3138
uses: actions/upload-artifact@v4

MODULE.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ pip.parse(
1919
)
2020
use_repo(pip, "renode_test_python_deps")
2121

22-
renode = use_extension("@rules_renode//renode:extensions.bzl", "renode")
22+
renode = use_extension("@rules_renode//renode:extensions.bzl", "renode",
23+
dev_dependency = True
24+
)
2325
use_repo(renode, "renode_default_toolchain")

examples/cortex-r52/MODULE.bazel

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ module(
33
version = "0.0.0",
44
)
55

6+
# Override Python to set ignore_root
7+
bazel_dep(name = "rules_python", version = "0.36.0")
8+
9+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
10+
python.toolchain(
11+
ignore_root_user_error = True, # It allows usage in containers with the root user
12+
python_version = "3.11",
13+
)
14+
use_repo(python)
15+
616
bazel_dep(name = "rules_renode", version = "0.0.0")
717
local_path_override(
818
module_name = "rules_renode",
@@ -12,6 +22,13 @@ local_path_override(
1222
renode = use_extension("@rules_renode//renode:extensions.bzl", "renode")
1323
use_repo(renode, "renode_toolchains")
1424

25+
# Use non-default version of Renode
26+
renode.download_portable(
27+
name = "renode_toolchain",
28+
sha256 = "73fe07a8fd0849a9f30c02bd7ce7c7dd67d11070365f41ddd6145a477ebdea65",
29+
url = "https://builds.renode.io/renode-1.15.3+20250128git85f0aac72.linux-portable-dotnet.tar.gz",
30+
)
31+
1532
register_toolchains("@renode_toolchains//:all")
1633

1734
http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")

examples/failing-test/MODULE.bazel

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ module(
33
version = "0.0.0",
44
)
55

6+
# Override Python to set ignore_root
7+
bazel_dep(name = "rules_python", version = "0.36.0")
8+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
9+
python.toolchain(
10+
ignore_root_user_error = True, # It allows usage in containers with the root user
11+
python_version = "3.11",
12+
)
13+
use_repo(python)
14+
15+
616
bazel_dep(name = "rules_renode", version = "0.0.0")
717
local_path_override(
818
module_name = "rules_renode",
@@ -15,9 +25,3 @@ use_repo(renode, "renode_toolchains")
1525
register_toolchains("@renode_toolchains//:all")
1626

1727
http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
18-
19-
http_file(
20-
name = "cortex-r52-hirtos-hello",
21-
sha256 = "73d6dea92d5bcff9c29b4e5c76aba5a691797cd68d458c243855055756f8093c",
22-
url = "https://dl.antmicro.com/projects/renode/cortex-r52--hirtos-hello.elf-s_140356-d44a0b48e22a17fa8cb83ef08243ec23942812c0",
23-
)

examples/local-renode/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
load("@rules_renode//renode:defs.bzl", "renode_test")
2+
3+
renode_test(
4+
name = "success-test",
5+
timeout = "short",
6+
robot_test = "test.robot",
7+
tags = [
8+
# Local build of Renode requires CLR to be available
9+
"local",
10+
],
11+
)

examples/local-renode/MODULE.bazel

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module(
2+
name = "renode_bazel_examples",
3+
version = "0.0.0",
4+
)
5+
6+
# Override Python to set ignore_root
7+
bazel_dep(name = "rules_python", version = "0.36.0")
8+
9+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
10+
python.toolchain(
11+
ignore_root_user_error = True, # It allows usage in containers with the root user
12+
python_version = "3.11",
13+
)
14+
use_repo(python)
15+
16+
bazel_dep(name = "rules_renode", version = "0.0.0")
17+
local_path_override(
18+
module_name = "rules_renode",
19+
path = "../..",
20+
)
21+
22+
renode = use_extension("@rules_renode//renode:extensions.bzl", "renode")
23+
renode.local_build(
24+
name = "renode_toolchain",
25+
path = "./renode",
26+
)
27+
use_repo(renode, "renode_toolchains")
28+
29+
register_toolchains("@renode_toolchains//:all")
30+
31+
http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")

examples/local-renode/test.robot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*** Test Cases ***
2+
Should Succeed
3+
Execute Command mach create

renode/extensions.bzl

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,68 @@
1+
load("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")
2+
3+
_DEFAULT_PORTABLE_RENODE = {
4+
"name": "renode_default_toolchain",
5+
"url": "https://builds.renode.io/renode-1.15.3+20250113gite77cf1237.linux-portable-dotnet.tar.gz",
6+
"sha256": "a6242b628b49b8a254358fe399ad49f0838c708abe44c551321c9555b7bff873",
7+
}
8+
19
def _portable_renode_toolchain_repository_impl(repository_ctx):
210
"""Creates a repository with a single Renode runtime"""
311
repository_ctx.report_progress("Downloading Renode...")
412
repository_ctx.download_and_extract(
513
repository_ctx.attr.url,
614
sha256 = repository_ctx.attr.sha256,
715
)
8-
repository_ctx.template("BUILD.bazel", Label("//renode:renode.BUILD.bazel"))
16+
repository_ctx.file("BUILD.bazel",
17+
content = repository_ctx.attr.build_file_content)
18+
19+
def _renode_build_file_variables(renode_dir, cosimulation_dir):
20+
return """\
21+
_RENODE_DIRECTORY = "%s"
22+
_COSIMULATION_DIRECTORY = "%s"
23+
""" % (renode_dir, cosimulation_dir)
924

1025
def _renode_impl(module_ctx):
11-
default_toolchain = "renode_default_toolchain"
12-
portable_renode_repository(
13-
name = default_toolchain,
14-
url = "https://builds.renode.io/renode-1.15.3+20250113gite77cf1237.linux-portable-dotnet.tar.gz",
15-
sha256 = "a6242b628b49b8a254358fe399ad49f0838c708abe44c551321c9555b7bff873",
16-
)
26+
toolchains = []
27+
build_file = module_ctx.read(Label("//renode:renode.BUILD.bazel"))
28+
29+
build_file_portable = _renode_build_file_variables(
30+
"renode_*/",
31+
"renode_*/plugins/**/IntegrationLibrary/"
32+
) + build_file
33+
for mod in module_ctx.modules:
34+
for tag in mod.tags.download_portable:
35+
toolchains.append(tag.name)
36+
portable_renode_repository(
37+
name = tag.name,
38+
url = tag.url,
39+
sha256 = tag.sha256,
40+
build_file_content = build_file_portable,
41+
)
42+
43+
build_file_local_build = _renode_build_file_variables(
44+
"",
45+
"src/Plugins/**/IntegrationLibrary/"
46+
) + build_file
47+
for mod in module_ctx.modules:
48+
for tag in mod.tags.local_build:
49+
toolchains.append(tag.name)
50+
new_local_repository(
51+
name = tag.name,
52+
path = tag.path,
53+
build_file_content = build_file_local_build,
54+
)
55+
56+
if len(toolchains) == 0:
57+
toolchains.append(_DEFAULT_PORTABLE_RENODE["name"])
58+
portable_renode_repository(
59+
build_file_content = build_file_portable,
60+
**_DEFAULT_PORTABLE_RENODE,
61+
)
1762

1863
renode_toolchains_repository(
1964
name = "renode_toolchains",
20-
toolchains = [default_toolchain],
65+
toolchains = toolchains,
2166
)
2267

2368
_RENODE_TOOLCHAIN_TEMPLATE = """\
@@ -38,7 +83,7 @@ def _renode_toolchains_repository(repository_ctx):
3883
for toolchain_repo in repository_ctx.attr.toolchains:
3984
build_file.append(_RENODE_TOOLCHAIN_TEMPLATE.format(
4085
name = toolchain_repo,
41-
impl = Label("@%s//:toolchain_impl" % toolchain_repo),
86+
impl = "@%s//:toolchain_impl" % toolchain_repo,
4287
))
4388

4489
repository_ctx.file("BUILD.bazel", "\n".join(build_file))
@@ -50,6 +95,7 @@ portable_renode_repository = repository_rule(
5095
mandatory = True,
5196
),
5297
"sha256": attr.string(),
98+
"build_file_content": attr.string(),
5399
},
54100
)
55101

@@ -62,7 +108,28 @@ renode_toolchains_repository = repository_rule(
62108
},
63109
)
64110

111+
_download_portable = tag_class(
112+
doc = "Downloads a portable Renode to a repository of the passed name",
113+
attrs = {
114+
"name": attr.string(),
115+
"url": attr.string(),
116+
"sha256": attr.string(),
117+
}
118+
)
119+
120+
_local_build = tag_class(
121+
doc = "Copies a localy built Renode to a repository of the passed name, it isn't hermetic",
122+
attrs = {
123+
"name": attr.string(),
124+
"path": attr.string(),
125+
}
126+
)
127+
65128
renode = module_extension(
66129
implementation = _renode_impl,
67130
doc = "Extension used to manage Renode runtimes available as toolchains",
131+
tag_classes = {
132+
"download_portable": _download_portable,
133+
"local_build": _local_build,
134+
}
68135
)

renode/renode.BUILD.bazel

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ load("@rules_renode//renode:toolchain.bzl", "renode_toolchain")
22

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

5-
_RENODE_DIRECTORY = "renode_*/"
6-
_COSIMULATION_DIRECTORY = _RENODE_DIRECTORY + "**/plugins/**/IntegrationLibrary/"
7-
85
filegroup(
96
name = "runtime",
10-
srcs = glob([_RENODE_DIRECTORY + "*"]),
7+
srcs = glob([_RENODE_DIRECTORY + "*"], allow_empty=False),
118
)
129
renode_toolchain(
1310
name = "toolchain_impl",
@@ -16,11 +13,11 @@ renode_toolchain(
1613

1714
filegroup(
1815
name = "python_requirements",
19-
srcs = glob([_RENODE_DIRECTORY + "tests/requirements.txt"]),
16+
srcs = glob([_RENODE_DIRECTORY + "tests/requirements.txt"], allow_empty=False),
2017
)
2118
filegroup(
2219
name = "python_requirements_dependencies",
23-
srcs = glob([_RENODE_DIRECTORY + "tools/**/requirements.txt"]),
20+
srcs = glob([_RENODE_DIRECTORY + "tools/**/requirements.txt"], allow_empty=False),
2421
)
2522

2623
filegroup(
@@ -36,7 +33,7 @@ filegroup(
3633
"src/communication/*.h",
3734
"src/*.h",
3835
]
39-
]),
36+
], allow_empty=False),
4037
)
4138
filegroup(
4239
name = "renode_dpi_cc_library_hdrs",
@@ -47,18 +44,18 @@ filegroup(
4744
"src/renode_dpi.h",
4845
"hdl/includes/*",
4946
]
50-
]),
47+
], allow_empty=False),
5148
)
5249

5350
# There are no Verilog rules that supports bzlmod.
5451
# These filegroups below can be used to create a relevant target in your project.
5552
filegroup(
5653
name = "renode_dpi_verilog_library_srcs",
57-
srcs = glob([_COSIMULATION_DIRECTORY + "hdl/renode_pkg.sv"]) +
58-
glob([_COSIMULATION_DIRECTORY + "hdl/imports/*.sv"]) +
59-
glob([_COSIMULATION_DIRECTORY + "hdl/modules/**/*.sv"]),
54+
srcs = glob([_COSIMULATION_DIRECTORY + "hdl/renode_pkg.sv"], allow_empty=False) +
55+
glob([_COSIMULATION_DIRECTORY + "hdl/imports/*.sv"], allow_empty=False) +
56+
glob([_COSIMULATION_DIRECTORY + "hdl/modules/**/*.sv"], allow_empty=False),
6057
)
6158
filegroup(
6259
name = "renode_dpi_verilog_library_hdrs",
63-
srcs = glob([_COSIMULATION_DIRECTORY + "hdl/includes/*.svh"]),
60+
srcs = glob([_COSIMULATION_DIRECTORY + "hdl/includes/*.svh"], allow_empty=False),
6461
)

0 commit comments

Comments
 (0)