Skip to content

Commit

Permalink
Introduce riscv64 CI
Browse files Browse the repository at this point in the history
Introduce logic necessary for generating YAML needed by BuildKite, which
are designed to work with image introduced in
rust-vmm/rust-vmm-container#106.

Signed-off-by: Ruoqing He <heruoqing@iscas.ac.cn>
  • Loading branch information
RuoqingHe committed Aug 2, 2024
1 parent 9f641f2 commit 841936d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
45 changes: 41 additions & 4 deletions .buildkite/autogenerate_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
# This represents the version of the rust-vmm-container used
# for running the tests.
CONTAINER_VERSION = "v35"
CONTAINER_VERSION_RISCV = CONTAINER_VERSION + "-riscv"
# This represents the version of the Buildkite Docker plugin.
DOCKER_PLUGIN_VERSION = "v5.3.0"

Expand All @@ -79,6 +80,7 @@
DEFAULT_AGENT_TAG_HYPERVISOR = os.getenv("DEFAULT_AGENT_TAG_HYPERVISOR", "kvm")

PARENT_DIR = pathlib.Path(__file__).parent.resolve()
REPO_ROOT_DIR = PARENT_DIR.parent


class BuildkiteStep:
Expand Down Expand Up @@ -237,6 +239,17 @@ def build(self, input):
if "{target_platform}" in command:
assert platform, "Command requires platform, but platform is missing."
command = command.replace("{target_platform}", platform)
# Modify command and tag name for `riscv64` CI
if platform == "riscv64":
# Wrap command with '' to avoid escaping early by `ENTRYPOINT`
command = json.dumps(command)
# Overwrite image tag for riscv64
self.step_config["plugins"][0][f"docker#{DOCKER_PLUGIN_VERSION}"]["image"] = f"rustvmm/dev:{CONTAINER_VERSION_RISCV}"
# Set platform to x86_64 for riscv64
platform = "x86_64"
# Since we are using qemu-system inside the container, we don't need
# hypervisor to be passed here
hypervisor = ""
self.step_config["command"] = command

# Optional keys.
Expand Down Expand Up @@ -287,7 +300,7 @@ class BuildkiteConfig:
def __init__(self):
self.bk_config = None

def build(self, input):
def build(self, input, platform_allowlist):
"""Build the final Buildkite configuration fron the json input."""

self.bk_config = {"steps": []}
Expand All @@ -309,6 +322,11 @@ def build(self, input):
platforms = [None]

for platform in platforms:
# Filter test enabled in platform_allowlist
if platform not in platform_allowlist:
# Skip disabled platform
continue

step_input = copy.deepcopy(test)
step_input["platform"] = platform
if not step_input.get("hypervisor"):
Expand All @@ -322,15 +340,26 @@ def build(self, input):
return self.bk_config


def generate_pipeline(config_file):
def determine_allowlist(config_file):
"""Determine the what platforms should be enabled for this crate"""

try:
with open(config_file, 'r') as file:
platforms = [line.strip() for line in file.readlines()]
return platforms
except Exception as e:
# Fall back to default platform if anything goes wrong
return ["x86_64", "aarch64"]

def generate_pipeline(config_file, platform_allowlist):
"""Generate the pipeline yaml file from a json configuration file."""

with open(config_file) as json_file:
json_cfg = json.load(json_file)
json_file.close()

config = BuildkiteConfig()
output = config.build(json_cfg)
output = config.build(json_cfg, platform_allowlist)
yaml.dump(output, sys.stdout, sort_keys=False)


Expand Down Expand Up @@ -363,5 +392,13 @@ def generate_pipeline(config_file):
help="The path to the JSON file containing the test" " description for the CI.",
default=f"{PARENT_DIR}/test_description.json",
)
parser.add_argument(
"-p",
"--platform-allowlist",
metavar="PLATFORM_DOT_FILE",
help="The path to the dot file containing the allowed platforms for the CI.",
default=f"{REPO_ROOT_DIR}/.platform",
)
args = parser.parse_args()
generate_pipeline(args.test_description)
platform_allowlist = determine_allowlist(args.platform_allowlist)
generate_pipeline(args.test_description, platform_allowlist)
12 changes: 8 additions & 4 deletions .buildkite/test_description.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"command": "RUSTFLAGS=\"-D warnings\" cargo build --release",
"platform": [
"x86_64",
"aarch64"
"aarch64",
"riscv64"
]
},
{
Expand All @@ -25,7 +26,8 @@
"command": "cargo test --all-features --workspace",
"platform": [
"x86_64",
"aarch64"
"aarch64",
"riscv64"
]
},
{
Expand All @@ -41,15 +43,17 @@
"command": "cargo clippy --workspace --bins --examples --benches --all-features --all-targets -- -D warnings -D clippy::undocumented_unsafe_blocks",
"platform": [
"x86_64",
"aarch64"
"aarch64",
"riscv64"
]
},
{
"test_name": "check-warnings",
"command": "RUSTFLAGS=\"-D warnings\" cargo check --all-targets --all-features --workspace",
"platform": [
"x86_64",
"aarch64"
"aarch64",
"riscv64"
]
},
{
Expand Down

0 comments on commit 841936d

Please sign in to comment.