Skip to content

Commit 752ad13

Browse files
RuoqingHestefano-garzarella
authored andcommitted
Introduce riscv64 CI
Introduce logic necessary for generating YAML needed by BuildKite, which are designed to work with image introduced in rust-vmm/rust-vmm-container#106. The container version is updated to v44 to enable CI on RISC-V platform. Signed-off-by: Ruoqing He <[email protected]>
1 parent 5e818dc commit 752ad13

File tree

4 files changed

+81
-13
lines changed

4 files changed

+81
-13
lines changed

.buildkite/autogenerate_pipeline.py

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@
6060

6161
# This represents the version of the rust-vmm-container used
6262
# 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"
6469
# This represents the version of the Buildkite Docker plugin.
6570
DOCKER_PLUGIN_VERSION = "v5.3.0"
6671

@@ -78,8 +83,7 @@
7883
# More details here: https://github.com/rust-vmm/community/issues/137
7984
DEFAULT_AGENT_TAG_HYPERVISOR = os.getenv("DEFAULT_AGENT_TAG_HYPERVISOR", "kvm")
8085

81-
PARENT_DIR = pathlib.Path(__file__).parent.resolve()
82-
86+
BUILDKITE_PATH = pathlib.Path(__file__).parent.resolve()
8387

8488
class BuildkiteStep:
8589
"""
@@ -237,6 +241,17 @@ def build(self, input):
237241
if "{target_platform}" in command:
238242
assert platform, "Command requires platform, but platform is missing."
239243
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 = ""
240255
self.step_config["command"] = command
241256

242257
# Optional keys.
@@ -287,7 +302,7 @@ class BuildkiteConfig:
287302
def __init__(self):
288303
self.bk_config = None
289304

290-
def build(self, input):
305+
def build(self, input, platform_allowlist):
291306
"""Build the final Buildkite configuration fron the json input."""
292307

293308
self.bk_config = {"steps": []}
@@ -309,6 +324,11 @@ def build(self, input):
309324
platforms = [None]
310325

311326
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+
312332
step_input = copy.deepcopy(test)
313333
step_input["platform"] = platform
314334
if not step_input.get("hypervisor"):
@@ -322,15 +342,26 @@ def build(self, input):
322342
return self.bk_config
323343

324344

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):
326357
"""Generate the pipeline yaml file from a json configuration file."""
327358

328359
with open(config_file) as json_file:
329360
json_cfg = json.load(json_file)
330361
json_file.close()
331362

332363
config = BuildkiteConfig()
333-
output = config.build(json_cfg)
364+
output = config.build(json_cfg, platform_allowlist)
334365
yaml.dump(output, sys.stdout, sort_keys=False)
335366

336367

@@ -361,7 +392,20 @@ def generate_pipeline(config_file):
361392
"--test-description",
362393
metavar="JSON_FILE",
363394
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",
365408
)
366409
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)

.buildkite/test_description.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"command": "RUSTFLAGS=\"-D warnings\" cargo build --release",
66
"platform": [
77
"x86_64",
8-
"aarch64"
8+
"aarch64",
9+
"riscv64"
910
]
1011
},
1112
{
@@ -25,7 +26,8 @@
2526
"command": "cargo test --all-features --workspace",
2627
"platform": [
2728
"x86_64",
28-
"aarch64"
29+
"aarch64",
30+
"riscv64"
2931
]
3032
},
3133
{
@@ -41,15 +43,17 @@
4143
"command": "cargo clippy --workspace --bins --examples --benches --all-features --all-targets -- -D warnings -D clippy::undocumented_unsafe_blocks",
4244
"platform": [
4345
"x86_64",
44-
"aarch64"
46+
"aarch64",
47+
"riscv64"
4548
]
4649
},
4750
{
4851
"test_name": "check-warnings",
4952
"command": "RUSTFLAGS=\"-D warnings\" cargo check --all-targets --all-features --workspace",
5053
"platform": [
5154
"x86_64",
52-
"aarch64"
55+
"aarch64",
56+
"riscv64"
5357
]
5458
},
5559
{

.platform

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x86_64
2+
aarch64
3+
riscv64

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,24 @@ For most use cases, overriding or extending the configuration is not necessary.
116116
want to do so if, for example, the platform needs a custom device that is not available
117117
on the existing test instances or if we need a specialized hypervisor.
118118

119-
6. The code owners of the repository will have to setup a WebHook for
119+
6. Tests will be running on `x86_64` and `aarch64` platforms by default. To change
120+
this, e.g. to enable other experimental platforms like `riscv64`, a `.platform`
121+
file can be included in the repository root. This file documents what platforms
122+
are to be enabled for the repository.
123+
124+
If `.platform` file is provided, it will be strictly observed. In `.platform`
125+
file, each platform are separated by newline character. Currently, we support
126+
`x86_64`, `aarch64` and `riscv64` platforms.
127+
128+
For example, we can enable tests to be run on `riscv64` platform in addition to
129+
`x86_64` and `aarch64` by:
130+
```
131+
x86_64
132+
aarch64
133+
riscv64
134+
```
135+
136+
7. The code owners of the repository will have to setup a WebHook for
120137
triggering the CI on
121138
[pull request](https://developer.github.com/v3/activity/events/types/#pullrequestevent)
122139
and [push](https://developer.github.com/v3/activity/events/types/#pushevent)

0 commit comments

Comments
 (0)