Skip to content

Commit

Permalink
添加riscv64的github workflow (DragonOS-Community#499)
Browse files Browse the repository at this point in the history
* 添加riscv64的github workflow
  • Loading branch information
fslongjin authored Jan 21, 2024
1 parent 7a29d4f commit 43ef2a0
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 45 deletions.
34 changes: 34 additions & 0 deletions .github/actions/import-toolchain/action.yml
Original file line number Diff line number Diff line change
@@ -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

16 changes: 16 additions & 0 deletions .github/actions/install-apt-packages/action.yml
Original file line number Diff line number Diff line change
@@ -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') }}

43 changes: 31 additions & 12 deletions .github/workflows/cache-toolchain.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Reusable workflow example
name: Cache toolchain

on: workflow_call

Expand All @@ -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
Expand All @@ -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
Expand Down
94 changes: 65 additions & 29 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build Check

on:
push:
branches: [ "master" ]
branches: [ "master", "patch-add-riscv64-github-workflow" ]
pull_request:
branches: [ "master" ]

Expand All @@ -11,45 +11,81 @@ 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

- 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') }}

- 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]

steps:
- uses: actions/checkout@v3

- 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)"

4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions env.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 43ef2a0

Please sign in to comment.