60
60
61
61
# This represents the version of the rust-vmm-container used
62
62
# for running the tests.
63
- CONTAINER_VERSION = "v38"
63
+ CONTAINER_VERSION = "v44"
64
+ # The suffix suggests that the dev image with `v{N}-riscv` tag is not to be
65
+ # confused with real `riscv64` image (it's actually a `x86_64` image with
66
+ # `qemu-system-riscv64` installed), since AWS yet has `riscv64` machines
67
+ # available.
68
+ CONTAINER_VERSION_RISCV = CONTAINER_VERSION + "-riscv"
64
69
# This represents the version of the Buildkite Docker plugin.
65
70
DOCKER_PLUGIN_VERSION = "v5.3.0"
66
71
78
83
# More details here: https://github.com/rust-vmm/community/issues/137
79
84
DEFAULT_AGENT_TAG_HYPERVISOR = os .getenv ("DEFAULT_AGENT_TAG_HYPERVISOR" , "kvm" )
80
85
81
- PARENT_DIR = pathlib .Path (__file__ ).parent .resolve ()
82
-
86
+ BUILDKITE_PATH = pathlib .Path (__file__ ).parent .resolve ()
83
87
84
88
class BuildkiteStep :
85
89
"""
@@ -237,6 +241,17 @@ def build(self, input):
237
241
if "{target_platform}" in command :
238
242
assert platform , "Command requires platform, but platform is missing."
239
243
command = command .replace ("{target_platform}" , platform )
244
+ # Modify command and tag name for `riscv64` CI
245
+ if platform == "riscv64" :
246
+ # Wrap command with '' to avoid escaping early by `ENTRYPOINT`
247
+ command = json .dumps (command )
248
+ # Overwrite image tag for riscv64 platform CI
249
+ self .step_config ["plugins" ][0 ][f"docker#{ DOCKER_PLUGIN_VERSION } " ]["image" ] = f"rustvmm/dev:{ CONTAINER_VERSION_RISCV } "
250
+ # Since we are using qemu-system inside a x86_64 container, we
251
+ # should set `platform` field to x86_64 and unset the hypervisor to
252
+ # be passed
253
+ platform = "x86_64"
254
+ hypervisor = ""
240
255
self .step_config ["command" ] = command
241
256
242
257
# Optional keys.
@@ -287,7 +302,7 @@ class BuildkiteConfig:
287
302
def __init__ (self ):
288
303
self .bk_config = None
289
304
290
- def build (self , input ):
305
+ def build (self , input , platform_allowlist ):
291
306
"""Build the final Buildkite configuration fron the json input."""
292
307
293
308
self .bk_config = {"steps" : []}
@@ -309,6 +324,11 @@ def build(self, input):
309
324
platforms = [None ]
310
325
311
326
for platform in platforms :
327
+ # Filter test enabled in platform_allowlist
328
+ if platform not in platform_allowlist :
329
+ # Skip disabled platform
330
+ continue
331
+
312
332
step_input = copy .deepcopy (test )
313
333
step_input ["platform" ] = platform
314
334
if not step_input .get ("hypervisor" ):
@@ -322,15 +342,26 @@ def build(self, input):
322
342
return self .bk_config
323
343
324
344
325
- def generate_pipeline (config_file ):
345
+ def determine_allowlist (config_file ):
346
+ """Determine the what platforms should be enabled for this crate"""
347
+
348
+ try :
349
+ with open (config_file , 'r' ) as file :
350
+ platforms = [line .strip () for line in file .readlines ()]
351
+ return platforms
352
+ except Exception as e :
353
+ # Fall back to default platform if anything goes wrong
354
+ return ["x86_64" , "aarch64" ]
355
+
356
+ def generate_pipeline (config_file , platform_allowlist ):
326
357
"""Generate the pipeline yaml file from a json configuration file."""
327
358
328
359
with open (config_file ) as json_file :
329
360
json_cfg = json .load (json_file )
330
361
json_file .close ()
331
362
332
363
config = BuildkiteConfig ()
333
- output = config .build (json_cfg )
364
+ output = config .build (json_cfg , platform_allowlist )
334
365
yaml .dump (output , sys .stdout , sort_keys = False )
335
366
336
367
@@ -361,7 +392,20 @@ def generate_pipeline(config_file):
361
392
"--test-description" ,
362
393
metavar = "JSON_FILE" ,
363
394
help = "The path to the JSON file containing the test" " description for the CI." ,
364
- default = f"{ PARENT_DIR } /test_description.json" ,
395
+ default = f"{ BUILDKITE_PATH } /test_description.json" ,
396
+ )
397
+ parser .add_argument (
398
+ "-p" ,
399
+ "--platform-allowlist" ,
400
+ metavar = "PLATFORM_DOT_FILE" ,
401
+ help = (
402
+ "The path to the dotfile containing platforms the crate's CI should run on.\n "
403
+ "If the file does not exist, falls back to default `platform_allowlist` (x86_64 and arm64).\n "
404
+ "The dotfile contains strings of architectures to be enabled separated by\n "
405
+ "newlines."
406
+ ),
407
+ default = f"{ os .getcwd ()} /.platform" ,
365
408
)
366
409
args = parser .parse_args ()
367
- generate_pipeline (args .test_description )
410
+ platform_allowlist = determine_allowlist (args .platform_allowlist )
411
+ generate_pipeline (args .test_description , platform_allowlist )
0 commit comments