From 952b35d11de45c4e611af34fed6f0eedf783044f Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Mon, 21 Jul 2025 09:21:01 +0800 Subject: [PATCH] Add CI on Zephyr (#4336) to run product-mini/platforms/zephyr/simple and product-mini/platforms/zephyr/user-mode Construct a T2 (star topology) for the current smoke test. This is not the final topology, and we may modify it once we determine the optimal configuration. --- .github/scripts/run_qemu_arc.sh | 46 +++++++ .github/workflows/compilation_on_zephyr.yml | 129 ++++++++++++++++++ .../platforms/zephyr/simple/Dockerfile | 50 +++---- .../platforms/zephyr/simple/west_lite.yml | 4 +- 4 files changed, 203 insertions(+), 26 deletions(-) create mode 100755 .github/scripts/run_qemu_arc.sh create mode 100644 .github/workflows/compilation_on_zephyr.yml diff --git a/.github/scripts/run_qemu_arc.sh b/.github/scripts/run_qemu_arc.sh new file mode 100755 index 00000000..ab226521 --- /dev/null +++ b/.github/scripts/run_qemu_arc.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# THIS SCRIPT IS USED TO RUN QEMU ARC EMULATOR DIRECTLY ON CI ONLY. +# USUALLY, you SHOULD NOT RUN IT ON YOUR LOCAL MACHINE. +# INSTEAD, YOU SHOULD USE `west build -t run` COMMAND. + +# Two arguments. first is the path to the zephyr-sdk, second is the path to the zephyr elf. +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +ZEPHYR_SDK_PATH=$1 +ZEPHYR_ELF_PATH=$2 + +if [ ! -d "$ZEPHYR_SDK_PATH" ]; then + echo "Error: Zephyr SDK path does not exist: $ZEPHYR_SDK_PATH" + exit 1 +fi +if [ ! -f "$ZEPHYR_ELF_PATH" ]; then + echo "Error: Zephyr ELF file does not exist: $ZEPHYR_ELF_PATH" + exit 1 +fi + +# this command is copied from the content of build.ninja which is generated by west build. +# please do not modify it unless synchronizing with the build.ninja file. +$ZEPHYR_SDK_PATH/sysroots/x86_64-pokysdk-linux/usr/bin/qemu-system-arc \ + -cpu arcem -m 8M \ + -nographic -no-reboot -monitor none \ + -global cpu.firq=false \ + -global cpu.num-irqlevels=15 \ + -global cpu.num-irq=25 \ + -global cpu.ext-irq=20 \ + -global cpu.freq_hz=10000000 \ + -global cpu.timer0=true \ + -global cpu.timer1=true \ + -global cpu.has-mpu=true \ + -global cpu.mpu-numreg=16 \ + -net none \ + -pidfile qemu.pid \ + -chardev stdio,id=con,mux=on \ + -serial chardev:con \ + -mon chardev=con,mode=readline \ + -icount shift=6,align=off,sleep=off \ + -rtc clock=vm \ + -kernel $ZEPHYR_ELF_PATH diff --git a/.github/workflows/compilation_on_zephyr.yml b/.github/workflows/compilation_on_zephyr.yml new file mode 100644 index 00000000..274fc374 --- /dev/null +++ b/.github/workflows/compilation_on_zephyr.yml @@ -0,0 +1,129 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +name: compilation on zephyr + +on: + # will be triggered on PR events + pull_request: + types: + - opened + - synchronize + paths: + - ".github/**" + - "build-scripts/**" + - "core/**" + - "!core/deps/**" + - "product-mini/platforms/common/**" + - "product-mini/platforms/zephyr/**" + - "samples/**" + - "!samples/workload/**" + - "tests/wamr-test-suites/**" + - "wamr-compiler/**" + # will be triggered on push events + push: + branches: + - main + - "dev/**" + paths: + - ".github/**" + - "build-scripts/**" + - "core/**" + - "!core/deps/**" + - "product-mini/platforms/common/**" + - "product-mini/platforms/zephyr/**" + - "samples/**" + - "!samples/workload/**" + - "tests/wamr-test-suites/**" + - "wamr-compiler/**" + # allow to be triggered manually + workflow_dispatch: + +# Cancel any in-flight jobs for the same PR/branch so there's only one active +# at a time +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + # FOR SETUP + ZEPHYR_SDK_VERSION: "0.16.9" + ZEPHYR_VERSION: "v3.7.0" + # FOR BUILD + +permissions: + contents: read + +jobs: + smoke_test: + runs-on: ubuntu-22.04 + container: + # For Zephyr 3.7 LTS, use the v0.26-branch or the latest v0.26.x release Docker image. + # ci require a larger runner to avoid "no space left on device" + image: ghcr.io/zephyrproject-rtos/ci-base:v0.26-branch + options: --user root + + steps: + # https://docs.zephyrproject.org/latest/develop/application/index.html#zephyr-workspace-application + # zephyrproject/ --> CI ROOT + # ├─── .west/ + # │ └─── config + # ├─── bootloader/ + # ├─── zephyr/ --> Zephyr source code + # ├─── zephyr-sdk/ + # ├─── modules/ + # │ |─── wasm-micro-runtime --> WAMR source code + # ├─── tools/ + # ├─── vendor/ + # └─── application/ --> DUMMY. keep west_lite.yml here + + - name: Checkout code + uses: actions/checkout@v3 + with: + path: modules/wasm-micro-runtime + + - name: Prepare Zephyr environment + shell: bash + run: | + mkdir -p application + cp modules/wasm-micro-runtime/product-mini/platforms/zephyr/simple/west_lite.yml application/west_lite.yml + + - name: Setup Zephyr project + uses: zephyrproject-rtos/action-zephyr-setup@v1 + with: + app-path: application + manifest-file-name: west_lite.yml + sdk-version: ${{ env.ZEPHYR_SDK_VERSION }} + toolchains: arc-zephyr-elf:arc64-zephyr-elf + + - name: Build a sample application(simple) + shell: bash + run: | + pushd product-mini/platforms/zephyr/simple + west build . -b qemu_arc/qemu_arc_hs -p always -- -DWAMR_BUILD_TARGET=ARC + popd + + # west build -t run will fork several processes, which will cause the job to hang. + # run in the background and kill it after 5 seconds + .github/scripts/run_qemu_arc.sh \ + ../../zephyr-sdk \ + product-mini/platforms/zephyr/simple/build/zephyr/zephyr.elf & + sleep 5 + pkill qemu-system-arc + working-directory: modules/wasm-micro-runtime + + - name: Build a sample application(user-mode) + shell: bash + run: | + pushd product-mini/platforms/zephyr/user-mode + west build . -b qemu_arc/qemu_arc_hs -p always -- -DWAMR_BUILD_TARGET=ARC + popd + + # west build -t run will fork several processes, which will cause the job to hang. + # run in the background and kill it after 5 seconds + .github/scripts/run_qemu_arc.sh \ + ../../zephyr-sdk \ + product-mini/platforms/zephyr/user-mode/build/zephyr/zephyr.elf & + sleep 5 + pkill qemu-system-arc + working-directory: modules/wasm-micro-runtime diff --git a/product-mini/platforms/zephyr/simple/Dockerfile b/product-mini/platforms/zephyr/simple/Dockerfile index c3fb1325..6449c986 100644 --- a/product-mini/platforms/zephyr/simple/Dockerfile +++ b/product-mini/platforms/zephyr/simple/Dockerfile @@ -3,7 +3,23 @@ # Refer to https://docs.zephyrproject.org/3.7.0/develop/getting_started/index.html # for more information on how to set up the Zephyr development environment. -FROM ubuntu:22.04 + +# https://docs.zephyrproject.org/latest/develop/application/index.html#zephyr-workspace-application +# zephyrproject/ --> CI ROOT +# ├─── .west/ +# │ └─── config +# ├─── bootloader/ +# ├─── zephyr/ --> Zephyr source code +# ├─── zephyr-sdk/ +# ├─── modules/ +# │ |─── wasm-micro-runtime --> WAMR source code +# ├─── tools/ +# ├─── vendor/ +# └─── application/ --> DUMMY. keep west_lite.yml here + +# If you modify this file, you may need to sync the modifications to the +# .github/actions/setup-zephyr/action.yml +FROM ghcr.io/zephyrproject-rtos/ci-base:v0.26-branch ARG DEBIAN_FRONTEND=noninteractive ENV TZ=Asian/Shanghai @@ -11,44 +27,30 @@ ARG ZEPHYR_SDK_VERSION=0.16.9 # In west_lite.yml, the Zephyr version is set to v3.7.0 #ARG ZEPHYR_VERSION=3.7.0 -# Install dependencies for Zephyr -# hadolint ignore=DL3008 -RUN apt-get update && apt-get install -y --no-install-recommends git cmake ninja-build gperf \ - ccache dfu-util device-tree-compiler wget \ - python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ - make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 \ - && apt-get clean -y && rm -rf /var/lib/apt/lists/* - # Install the Zephyr Software Development Kit (SDK) -WORKDIR /opt +WORKDIR /root/zephyrproject/zephyr-sdk # hadolint ignore=DL4006 RUN wget --progress=dot:giga https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${ZEPHYR_SDK_VERSION}/zephyr-sdk-${ZEPHYR_SDK_VERSION}_linux-x86_64.tar.xz \ && wget --progress=dot:giga -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${ZEPHYR_SDK_VERSION}/sha256.sum | shasum --check --ignore-missing \ - && tar xf zephyr-sdk-${ZEPHYR_SDK_VERSION}_linux-x86_64.tar.xz && rm zephyr-sdk-${ZEPHYR_SDK_VERSION}_linux-x86_64.tar.xz - -WORKDIR /opt/zephyr-sdk-${ZEPHYR_SDK_VERSION} + && tar --strip-components=1 -xf zephyr-sdk-${ZEPHYR_SDK_VERSION}_linux-x86_64.tar.xz && rm zephyr-sdk-${ZEPHYR_SDK_VERSION}_linux-x86_64.tar.xz # hadolint ignore=DL4006 # Install host tools and Register Zephyr SDK CMake package RUN ./setup.sh -h -c -# Get Zephyr -WORKDIR /root/zephyrproject/smoke-test - -# hadolint ignore=DL3013 +# Install west +# hadolint ignore=DL3013,DL3059 RUN pip3 install --no-cache-dir west -COPY ./west_lite.yml ./west.yml + +# Setup a T2(Star topology) workspace +WORKDIR /root/zephyrproject/application +COPY ./west_lite.yml ./west_lite.yml # init the west workspace with a minimal manifest -RUN west init -l +RUN west init -l --mf west_lite.yml . WORKDIR /root/zephyrproject RUN west update --stats -WORKDIR /root/zephyrproject/modules/zephyr -RUN west zephyr-export && pip install --no-cache-dir -r ./scripts/requirements.txt - -ENV ZEPHYR_BASE="/root/zephyrproject/modules/zephyr" - # Git clone wamr WORKDIR /root/zephyrproject/modules/ RUN git clone https://github.com/bytecodealliance/wasm-micro-runtime.git wasm-micro-runtime diff --git a/product-mini/platforms/zephyr/simple/west_lite.yml b/product-mini/platforms/zephyr/simple/west_lite.yml index 447affdb..7c05d736 100644 --- a/product-mini/platforms/zephyr/simple/west_lite.yml +++ b/product-mini/platforms/zephyr/simple/west_lite.yml @@ -8,8 +8,8 @@ manifest: url: https://github.com/zephyrproject-rtos/zephyr revision: v3.7.0 clone-depth: 1 - path: modules/zephyr + path: zephyr west-commands: scripts/west-commands.yml self: - path: smoke-test + path: application