From 43ef2a0d2b6ec427f6775cd4593c56897dd5bf6d Mon Sep 17 00:00:00 2001 From: LoGin Date: Sun, 21 Jan 2024 18:45:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0riscv64=E7=9A=84github=20work?= =?UTF-8?q?flow=20(#499)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加riscv64的github workflow --- .github/actions/import-toolchain/action.yml | 34 ++++++ .../actions/install-apt-packages/action.yml | 16 +++ .github/workflows/cache-toolchain.yml | 43 +++++--- .github/workflows/makefile.yml | 102 ++++++++++++------ Makefile | 4 +- env.mk | 3 + kernel/Makefile | 1 - 7 files changed, 154 insertions(+), 49 deletions(-) create mode 100644 .github/actions/import-toolchain/action.yml create mode 100644 .github/actions/install-apt-packages/action.yml diff --git a/.github/actions/import-toolchain/action.yml b/.github/actions/import-toolchain/action.yml new file mode 100644 index 00000000..fc1eff0b --- /dev/null +++ b/.github/actions/import-toolchain/action.yml @@ -0,0 +1,34 @@ +name: import-toolchain + +runs: + using: composite + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + + - name: Cache DragonOS GCC + id: cache-dragonos-gcc + uses: actions/cache@v3 + env: + cache-name: cache-dragonos-gcc + with: + path: | + ~/opt + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('tools/build_gcc_toolchain.sh') }}-${{ hashFiles('tools/install_musl_gcc.sh') }} + + - name: Cache build tools + id: cache-build-tools + uses: actions/cache@v3 + env: + cache-name: cache-build-tools + dadk_version: 0.1.6 + with: + path: | + ~/.cargo + ~/.rustup + ~/.bashrc + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.dadk_version }}-${{ hashFiles('.github/workflows/cache-toolchain.yml') }} + + - uses: ./.github/actions/install-apt-packages + diff --git a/.github/actions/install-apt-packages/action.yml b/.github/actions/install-apt-packages/action.yml new file mode 100644 index 00000000..de85fe83 --- /dev/null +++ b/.github/actions/install-apt-packages/action.yml @@ -0,0 +1,16 @@ +name: install-apt-packages + +runs: + using: composite + steps: + + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: llvm-dev libclang-dev clang gcc-multilib libssl-dev pkg-config + version: ${{ hashFiles('.github/actions/install-apt-packages/action.yml') }} + + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: gcc-riscv64-unknown-elf gcc-riscv64-linux-gnu gdb-multiarch + version: ${{ hashFiles('.github/actions/install-apt-packages/action.yml') }} + \ No newline at end of file diff --git a/.github/workflows/cache-toolchain.yml b/.github/workflows/cache-toolchain.yml index 8109c033..f5245918 100644 --- a/.github/workflows/cache-toolchain.yml +++ b/.github/workflows/cache-toolchain.yml @@ -1,4 +1,4 @@ -name: Reusable workflow example +name: Cache toolchain on: workflow_call @@ -18,19 +18,23 @@ jobs: with: path: | ~/opt - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('tools/build_gcc_toolchain.sh') }} + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('tools/build_gcc_toolchain.sh') }}-${{ hashFiles('tools/install_musl_gcc.sh') }} - if: ${{ steps.cache-dragonos-gcc.outputs.cache-hit != 'true' }} name: build dragonos-gcc continue-on-error: true - run: bash tools/build_gcc_toolchain.sh -f + run: | + bash tools/build_gcc_toolchain.sh -f + bash tools/install_musl_gcc.sh + - uses: ./.github/actions/install-apt-packages + - name: Cache build tools id: cache-build-tools uses: actions/cache@v3 env: cache-name: cache-build-tools - dadk_version: 0.1.2 + dadk_version: 0.1.6 with: path: | ~/.cargo @@ -40,23 +44,38 @@ jobs: - if: ${{ steps.cache-build-tools.outputs.cache-hit != 'true' }} name: Install toolchain - continue-on-error: true + continue-on-error: false run: | - sudo sh -c "apt update && apt install -y llvm-dev libclang-dev clang gcc-multilib libssl-dev pkg-config" + cargo install cargo-binutils - rustup toolchain install nightly + rustup toolchain install nightly-x86_64-unknown-linux-gnu rustup toolchain install nightly-2023-01-21-x86_64-unknown-linux-gnu rustup toolchain install nightly-2023-08-15-x86_64-unknown-linux-gnu - rustup default nightly - rustup component add rust-src - rustup component add llvm-tools-preview - rustup target add x86_64-unknown-none - rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu rustup component add rust-src --toolchain nightly-2023-01-21-x86_64-unknown-linux-gnu rustup component add rust-src --toolchain nightly-2023-08-15-x86_64-unknown-linux-gnu + rustup target add x86_64-unknown-none --toolchain nightly-2023-01-21-x86_64-unknown-linux-gnu + rustup target add x86_64-unknown-none --toolchain nightly-2023-08-15-x86_64-unknown-linux-gnu + + rustup toolchain install nightly-2023-01-21-riscv64gc-unknown-linux-gnu --force-non-host + rustup toolchain install nightly-2023-08-15-riscv64gc-unknown-linux-gnu --force-non-host + rustup target add riscv64gc-unknown-none-elf --toolchain nightly-2023-01-21-riscv64gc-unknown-linux-gnu + rustup target add riscv64imac-unknown-none-elf --toolchain nightly-2023-01-21-riscv64gc-unknown-linux-gnu + rustup target add riscv64gc-unknown-none-elf --toolchain nightly-2023-08-15-riscv64gc-unknown-linux-gnu + rustup target add riscv64imac-unknown-none-elf --toolchain nightly-2023-08-15-riscv64gc-unknown-linux-gnu + + rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu + rustup component add rust-src + rustup component add llvm-tools-preview + rustup component add rustfmt + rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu rustup component add rustfmt --toolchain nightly-2023-01-21-x86_64-unknown-linux-gnu rustup component add rustfmt --toolchain nightly-2023-08-15-x86_64-unknown-linux-gnu + rustup component add rustfmt --toolchain nightly-2023-01-21-riscv64gc-unknown-linux-gnu + rustup component add rustfmt --toolchain nightly-2023-08-15-riscv64gc-unknown-linux-gnu + + rustup default nightly + cargo install dadk --version 0.1.6 diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml index d5d95b7d..523b5e91 100644 --- a/.github/workflows/makefile.yml +++ b/.github/workflows/makefile.yml @@ -2,7 +2,7 @@ name: Build Check on: push: - branches: [ "master" ] + branches: [ "master", "patch-add-riscv64-github-workflow" ] pull_request: branches: [ "master" ] @@ -11,7 +11,50 @@ jobs: ensure-toolchain: uses: ./.github/workflows/cache-toolchain.yml - build: + format-check: + name: Format check ${{ matrix.arch }} + runs-on: ubuntu-latest + needs: [ensure-toolchain] + continue-on-error: true + + strategy: + matrix: + arch: [x86_64, riscv64] + + steps: + - uses: actions/checkout@v3 + + - uses: ./.github/actions/import-toolchain + + - name: Format check + env: + ARCH: ${{ matrix.arch }} + run: | + printf "\n" >> kernel/src/include/bindings/bindings.rs + printf "\n" >> user/libs/libc/src/include/internal/bindings/bindings.rs + FMT_CHECK=1 make fmt + + kernel-static-test: + name: Kernel static test ${{ matrix.arch }} + runs-on: ubuntu-latest + needs: [ensure-toolchain] + continue-on-error: true + + strategy: + matrix: + arch: [x86_64, riscv64] + + steps: + - uses: actions/checkout@v3 + + - uses: ./.github/actions/import-toolchain + + - name: Run kernel static test + env: + ARCH: ${{ matrix.arch }} + run: bash -c "source ~/.cargo/env && cd kernel && make test" + + build-x86_64: runs-on: ubuntu-latest needs: [ensure-toolchain] @@ -19,37 +62,30 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Cache DragonOS GCC - id: cache-dragonos-gcc - uses: actions/cache@v3 - env: - cache-name: cache-dragonos-gcc - with: - path: | - ~/opt - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('tools/build_gcc_toolchain.sh') }} - - - name: Cache build tools - id: cache-build-tools - uses: actions/cache@v3 - env: - cache-name: cache-build-tools - dadk_version: 0.1.2 - with: - path: | - ~/.cargo - ~/.rustup - ~/.bashrc - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.dadk_version }}-${{ hashFiles('.github/workflows/cache-toolchain.yml') }} - - - name: Format check - run: | - printf "\n" >> kernel/src/include/bindings/bindings.rs - printf "\n" >> user/libs/libc/src/include/internal/bindings/bindings.rs - FMT_CHECK=1 make fmt + - uses: ./.github/actions/import-toolchain + - name: build the DragonOS + env: + ARCH: x86_64 run: bash -c "source ~/.cargo/env && export DragonOS_GCC=$HOME/opt/dragonos-gcc/gcc-x86_64-unknown-none/bin && make -j $(nproc) " - - - name: Run kernel static test - run: bash -c "source ~/.cargo/env && cd kernel && make test" + + + build-riscv64: + + runs-on: ubuntu-latest + needs: [ensure-toolchain] + + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + + - uses: ./.github/actions/import-toolchain + + - name: build the DragonOS + env: + ARCH: riscv64 + + run: bash -c "source ~/.cargo/env && make kernel -j $(nproc)" + diff --git a/Makefile b/Makefile index 965fdf0a..015f17e4 100644 --- a/Makefile +++ b/Makefile @@ -42,13 +42,11 @@ all: kernel user .PHONY: kernel kernel: mkdir -p bin/kernel/ - @if [ -z $$DragonOS_GCC ]; then echo "\033[31m [错误]尚未安装DragonOS交叉编译器, 请使用tools文件夹下的build_gcc_toolchain.sh脚本安装 \033[0m"; exit 1; fi + $(MAKE) -C ./kernel all ARCH=$(ARCH) || (sh -c "echo 内核编译失败" && exit 1) .PHONY: user user: - - @if [ -z $$DragonOS_GCC ]; then echo "\033[31m [错误]尚未安装DragonOS交叉编译器, 请使用tools文件夹下的build_gcc_toolchain.sh脚本安装 \033[0m"; exit 1; fi $(MAKE) -C ./user all ARCH=$(ARCH) || (sh -c "echo 用户程序编译失败" && exit 1) .PHONY: clean diff --git a/env.mk b/env.mk index f18ab138..6315d868 100644 --- a/env.mk +++ b/env.mk @@ -12,6 +12,9 @@ endif # 设置编译器 ifeq ($(ARCH), x86_64) +# 如果 x86_64时,DragonOS_GCC 为空,那么设置为默认值 +export DragonOS_GCC?=$(HOME)/opt/dragonos-gcc/gcc-x86_64-unknown-none/bin + export CC=$(DragonOS_GCC)/x86_64-elf-gcc export LD=ld export AS=$(DragonOS_GCC)/x86_64-elf-as diff --git a/kernel/Makefile b/kernel/Makefile index 9982a8e8..cdb1751f 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -16,7 +16,6 @@ ECHO: @echo "$@" all: - @if [ -z $$DragonOS_GCC ]; then echo "\033[31m [错误]尚未安装DragonOS交叉编译器, 请使用tools文件夹下的build_gcc_toolchain.sh脚本安装 \033[0m"; exit 1; fi $(MAKE) -C src all ARCH=$(ARCH) || (sh -c "echo 内核编译失败" && exit 1)