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+
19def _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
1025def _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+
65128renode = 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)
0 commit comments