Skip to content

Commit

Permalink
更改构建流程
Browse files Browse the repository at this point in the history
  • Loading branch information
fslongjin committed Aug 24, 2023
1 parent 4f82023 commit 7af4e0b
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 58 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/cache-toolchain.yml
Original file line number Diff line number Diff line change
@@ -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

37 changes: 4 additions & 33 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,16 @@ on:
branches: [ "master" ]

jobs:
# ensure the toolchain is cached
ensure-toolchain:
uses: ./.github/workflows/cache-toolchain.yml

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/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) "
34 changes: 13 additions & 21 deletions .github/workflows/rustfmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ resolver = "2"

members = [
"kernel",
"user/libs/libc/",
]
4 changes: 2 additions & 2 deletions kernel/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion user/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
2 changes: 1 addition & 1 deletion user/libs/libc/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
cargo +nightly build --release --target ./arch/x86_64/x86_64-unknown-none.json

0 comments on commit 7af4e0b

Please sign in to comment.