diff --git a/.github/workflows/cache-toolchain.yml b/.github/workflows/cache-toolchain.yml new file mode 100644 index 000000000..dba46952d --- /dev/null +++ b/.github/workflows/cache-toolchain.yml @@ -0,0 +1,45 @@ +name: Reusable workflow example + +on: workflow_call + +jobs: + build: + + runs-on: ubuntu-latest + + 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') }} + + - 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 + + - 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') }} + + - if: ${{ steps.cache-build-tools.outputs.cache-hit != 'true' }} + name: Install toolchain + continue-on-error: true + run: sudo sh -c "apt update && apt install -y llvm-dev libclang-dev clang gcc-multilib libssl-dev" && cargo install cargo-binutils && rustup toolchain install nightly && 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 && cargo install dadk --version 0.1.2 + diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml index 9073c528a..bc8119af1 100644 --- a/.github/workflows/makefile.yml +++ b/.github/workflows/makefile.yml @@ -7,6 +7,10 @@ on: branches: [ "master" ] jobs: + # ensure the toolchain is cached + ensure-toolchain: + uses: ./.github/workflows/cache-toolchain.yml + build: runs-on: ubuntu-latest @@ -14,38 +18,5 @@ 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') }} - - - 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 - - - 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/makefile.yml') }} - - - if: ${{ steps.cache-build-tools.outputs.cache-hit != 'true' }} - name: Install toolchain - continue-on-error: true - run: sudo sh -c "apt update && apt install -y llvm-dev libclang-dev clang gcc-multilib libssl-dev" && cargo install cargo-binutils && rustup toolchain install nightly && 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 && cargo install dadk --version 0.1.1 - - name: build the DragonOS run: bash -c "source ~/.cargo/env && export DragonOS_GCC=$HOME/opt/dragonos-gcc/gcc-x86_64-unknown-none/bin && make -j $(nproc) " diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml index 63b1dc7b5..6311c0d71 100644 --- a/.github/workflows/rustfmt.yml +++ b/.github/workflows/rustfmt.yml @@ -3,32 +3,24 @@ name: Rust format check on: [push, pull_request] jobs: + # ensure the toolchain is cached + ensure-toolchain: + uses: ./.github/workflows/cache-toolchain.yml + fmt: name: Rustfmt runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v2 - - - name: Cache toolchain - id: cache-toolchain - uses: actions/cache@v3 - env: - cache-name: cache-toolchain - with: - path: | - ~/.cargo - ~/.rustup - ~/.bashrc - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('.github/workflows/rustfmt.yml') }} - - - if: ${{ steps.cache-toolchain.outputs.cache-hit != 'true' }} - name: Install nightly-2023-01-21 - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly-2023-01-21 - override: true - components: rustfmt, clippy + - uses: actions/checkout@v3 + # 准备 bindings.rs + # 由于 bindings.rs 是在 build.rs 中生成的,而这里为了方便,直接 touch 一个空文件 + - name: prepare bindings + run: | + touch kernel/src/include/bindings/bindings.rs + touch user/libs/libc/src/include/internal/bindings/bindings.rs + - name: Check format uses: actions-rs/cargo@v1 with: diff --git a/Cargo.toml b/Cargo.toml index c3af482cc..cc4c4197e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,5 @@ resolver = "2" members = [ "kernel", + "user/libs/libc/", ] \ No newline at end of file diff --git a/kernel/src/Makefile b/kernel/src/Makefile index 7500550a0..1c8f96500 100644 --- a/kernel/src/Makefile +++ b/kernel/src/Makefile @@ -38,7 +38,7 @@ kernel_rust: all: kernel @echo "Linking kernel..." - $(LD) -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T link.lds + $(LD) -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") $(ROOT_PATH)/target/x86_64-unknown-none/release/libdragonos_kernel.a -T link.lds # 生成kallsyms current_dir=$(pwd) @@ -55,7 +55,7 @@ all: kernel # 重新链接 @echo "Re-Linking kernel..." @echo $(shell find . -name "*.o") - $(LD) -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o -T link.lds + $(LD) -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") $(ROOT_PATH)/target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o -T link.lds @echo "Generating kernel ELF file..." # 生成内核文件 $(OBJCOPY) -I elf64-x86-64 -O elf64-x86-64 kernel ../../bin/kernel/kernel.elf diff --git a/user/Makefile b/user/Makefile index 8e19d10f4..da796370b 100644 --- a/user/Makefile +++ b/user/Makefile @@ -95,7 +95,7 @@ sys_api_lib: sys_api_lib_stage_1 mkdir -p $(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp mkdir -p $(OLD_LIBC_INSTALL_PATH)/include mkdir -p $(OLD_LIBC_INSTALL_PATH)/lib - $(AR) x $(ROOT_PATH)/user/libs/libc/target/x86_64-unknown-none/release/liblibc.a --output=$(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp + $(AR) x $(ROOT_PATH)/target/x86_64-unknown-none/release/liblibc.a --output=$(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp $(AR) crvs $(OLD_LIBC_INSTALL_PATH)/lib/libc.a $(shell find ./libs/* -name "*.o") $(shell find $(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp/* -name "*.o") rm -rf $(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp # $(shell find ./libs/* -name "*.o" | xargs -I {} cp {} $(ROOT_PATH)/bin/sysroot/usr/lib/) diff --git a/user/libs/libc/src/Makefile b/user/libs/libc/src/Makefile index 8131f4e28..e2d8ec834 100644 --- a/user/libs/libc/src/Makefile +++ b/user/libs/libc/src/Makefile @@ -36,4 +36,4 @@ libc: $(libc_objs) $(libc_sub_dirs) libc_rust libc_rust: rustup default nightly - cargo +nightly build --release --target ./arch/x86_64/x86_64-unknown-none.json \ No newline at end of file + cargo +nightly build --release --target ./arch/x86_64/x86_64-unknown-none.json