From cc0cdf548c497d19ebf79795b8e24d40caa5c458 Mon Sep 17 00:00:00 2001 From: elliott10 Date: Fri, 19 Apr 2024 09:52:58 +0800 Subject: [PATCH] Added github CI test --- .../workflows/actions/setup-musl/action.yml | 38 +++++++++++++++ .../workflows/actions/setup-qemu/action.yml | 46 +++++++++++++++++++ .github/workflows/build.yml | 34 ++++++++++++++ .github/workflows/test.yml | 39 ++++++++++++++++ 4 files changed, 157 insertions(+) create mode 100644 .github/workflows/actions/setup-musl/action.yml create mode 100644 .github/workflows/actions/setup-qemu/action.yml create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/actions/setup-musl/action.yml b/.github/workflows/actions/setup-musl/action.yml new file mode 100644 index 0000000..b8aee36 --- /dev/null +++ b/.github/workflows/actions/setup-musl/action.yml @@ -0,0 +1,38 @@ +name: Download musl toolchain + +inputs: + arch: + description: 'Architecture' + required: true + type: string + +runs: + using: "composite" + steps: + - name: Cache musl + id: cache-musl + uses: actions/cache/restore@v3 + with: + path: ${{ inputs.arch }}-linux-musl-cross + key: ${{ inputs.arch }}-linux-musl-cross + - name: Download musl toolchain + if: steps.cache-musl.outputs.cache-hit != 'true' + shell: bash + run: | + MUSL_PATH=${{ inputs.arch }}-linux-musl-cross + wget https://musl.cc/${MUSL_PATH}.tgz + tar -xf ${MUSL_PATH}.tgz + - uses: actions/cache/save@v3 + if: steps.cache-musl.outputs.cache-hit != 'true' + with: + path: ${{ inputs.arch }}-linux-musl-cross + key: ${{ inputs.arch }}-linux-musl-cross + + - name: Add to PATH environment variable + shell: bash + run: | + echo "$PWD/${{ inputs.arch }}-linux-musl-cross/bin" >> $GITHUB_PATH + - name: Verify installation + shell: bash + run: | + ${{ inputs.arch }}-linux-musl-gcc --version diff --git a/.github/workflows/actions/setup-qemu/action.yml b/.github/workflows/actions/setup-qemu/action.yml new file mode 100644 index 0000000..0f8bc4d --- /dev/null +++ b/.github/workflows/actions/setup-qemu/action.yml @@ -0,0 +1,46 @@ +name: Download and build QEMU + +inputs: + qemu-version: + description: 'QEMU version' + required: true + type: string + +runs: + using: "composite" + steps: + - name: Cache QEMU + id: cache-qemu + uses: actions/cache/restore@v3 + with: + path: qemu_build + key: qemu-${{ inputs.qemu-version }}-slirp-1 + - name: Download and build QEMU + if: steps.cache-qemu.outputs.cache-hit != 'true' + env: + QEMU_PATH: qemu-${{ inputs.qemu-version }} + PREFIX: ${{ github.workspace }}/qemu_build + shell: bash + run: | + sudo apt-get update && sudo apt-get install -y ninja-build libslirp-dev + wget https://download.qemu.org/$QEMU_PATH.tar.xz && tar -xJf $QEMU_PATH.tar.xz + cd $QEMU_PATH \ + && ./configure --prefix=$PREFIX --target-list=x86_64-softmmu,riscv64-softmmu,aarch64-softmmu --enable-slirp \ + && make -j > /dev/null 2>&1 \ + && make install + - uses: actions/cache/save@v3 + if: steps.cache-qemu.outputs.cache-hit != 'true' + with: + path: qemu_build + key: qemu-${{ inputs.qemu-version }}-slirp-1 + + - name: Install QEMU + shell: bash + run: | + echo "$PWD/qemu_build/bin" >> $GITHUB_PATH + - name: Verify installation + shell: bash + run: | + qemu-system-x86_64 --version + qemu-system-aarch64 --version + qemu-system-riscv64 --version diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..de5da2c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,34 @@ +name: Build CI + +on: [push, pull_request] + +jobs: + + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + arch: [riscv64] + rust-toolchain: [nightly] + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust-toolchain }} + components: rust-src + - uses: actions-rs/install@v0.1 + with: + crate: cargo-binutils + version: latest + use-tool-cache: true + + - uses: ./.github/workflows/actions/setup-musl + with: + arch: ${{ matrix.arch }} + - name: Build ${{ github.repository }} + run: | + rustup target add riscv64gc-unknown-none-elf + cargo build -vv --target riscv64gc-unknown-none-elf diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..f677212 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,39 @@ +name: Test CI + +on: [push, pull_request] + +env: + qemu-version: 8.2.0 + rust-toolchain: nightly-2024-01-31 + +jobs: + + examples-test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + arch: [riscv64] + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ env.rust-toolchain }} + components: rust-src + - uses: actions-rs/install@v0.1 + with: + crate: cargo-binutils + version: latest + use-tool-cache: true + - uses: ./.github/workflows/actions/setup-qemu + with: + qemu-version: ${{ env.qemu-version }} + - uses: ./.github/workflows/actions/setup-musl + with: + arch: ${{ matrix.arch }} + - name: Run examples + run: | + cd examples + make run \ No newline at end of file