添加github workflow,检查代码是否已经格式化 (#342)

* 添加github workflow,检查代码是否已经格式化
This commit is contained in:
LoGin 2023-08-24 18:50:52 +08:00 committed by GitHub
parent f09a98329c
commit 9a367aa7eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 122 additions and 23 deletions

55
.github/workflows/cache-toolchain.yml vendored Normal file
View File

@ -0,0 +1,55 @@
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 pkg-config"
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
rustup component add rustfmt
cargo install dadk --version 0.1.2

View File

@ -7,13 +7,18 @@ on:
branches: [ "master" ]
jobs:
# ensure the toolchain is cached
ensure-toolchain:
uses: ./.github/workflows/cache-toolchain.yml
build:
runs-on: ubuntu-latest
needs: [ensure-toolchain]
steps:
- uses: actions/checkout@v3
- name: Cache DragonOS GCC
id: cache-dragonos-gcc
uses: actions/cache@v3
@ -24,28 +29,19 @@ jobs:
~/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.1
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
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.dadk_version }}-${{ hashFiles('.github/workflows/cache-toolchain.yml') }}
- 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) "

40
.github/workflows/rustfmt.yml vendored Normal file
View File

@ -0,0 +1,40 @@
name: Rust format check
on: [push, pull_request]
jobs:
# ensure the toolchain is cached
ensure-toolchain:
uses: ./.github/workflows/cache-toolchain.yml
fmt:
name: check
runs-on: ubuntu-latest
needs: [ensure-toolchain]
steps:
- uses: actions/checkout@v3
- 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') }}
# 准备 bindings.rs
# 由于 bindings.rs 是在 build.rs 中生成的,而这里为了方便,直接 touch 一个空文件
- name: prepare bindings
run: |
printf "\n" >> kernel/src/include/bindings/bindings.rs
printf "\n" >> user/libs/libc/src/include/internal/bindings/bindings.rs
- name: Check format
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

2
.gitignore vendored
View File

@ -15,3 +15,5 @@ user/sys_api_lib
docs/_build
draft
cppcheck.xml
/target/
Cargo.lock

7
Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[workspace]
resolver = "2"
members = [
"kernel",
"user/libs/libc/",
]

View File

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

View File

@ -664,7 +664,6 @@ impl Syscall {
Ok(pipefd) => Self::pipe(pipefd),
},
}
}
SYS_UNLINK_AT => {

View File

@ -327,7 +327,7 @@ impl<'a> UserBufferWriter<'a> {
};
return Ok(chunks);
}
fn convert_one_with_offset<T>(src: &mut [u8], offset: usize) -> Result<&mut T, SystemError> {
if offset + core::mem::size_of::<T>() > src.len() {
return Err(SystemError::EINVAL);

View File

@ -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/)

View File

@ -42,4 +42,4 @@ fn main() {
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
}
}

View File

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

View File

@ -1 +1 @@
pub mod bindings;
pub mod bindings;

View File

@ -1 +1 @@
pub mod bindings;
pub mod bindings;

View File

@ -1 +1 @@
pub mod internal;
pub mod internal;