Skip to content

Commit

Permalink
[CI] Update CI for unit-test and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Azure-stars committed Oct 20, 2024
1 parent 9094bde commit 1ef010e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 64 deletions.
49 changes: 13 additions & 36 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,30 @@
name: CI
name: Build & Check CI

on: [push]
on: [push, pull_request]

jobs:
clippy:
ci:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust-toolchain: [nightly]
targets: [x86_64-unknown-linux-gnu, x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none-softfloat]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@nightly
with:
toolchain: ${{ matrix.rust-toolchain }}
components: rust-src, clippy, rustfmt
targets: x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none
targets: ${{ matrix.targets }}
- name: Check rust version
run: rustc --version --verbose
- name: Clippy for the default target
continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }}
run: make clippy
- name: Clippy for x86_64
continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }}
run: make clippy ARCH=x86_64
- name: Clippy for riscv64
continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }}
run: make clippy ARCH=riscv64
- name: Clippy for aarch64
continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }}
run: make clippy ARCH=aarch64
- name: Check code format
continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }}
run: cargo fmt --all -- --check

build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch: [x86_64, riscv64, aarch64]
rust-toolchain: [nightly]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust-toolchain }}
components: rust-src, llvm-tools
targets: x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none
- uses: Swatinem/rust-cache@v2
- name: Build for ${{ matrix.arch }}
run: make build ARCH=${{ matrix.arch }}
- name: Clippy
run: cargo clippy --target ${{ matrix.targets }} --all-features -- -A clippy::new_without_default
- name: Build
run: cargo build --target ${{ matrix.targets }} --all-features
- name: Unit test
if: ${{ matrix.targets == 'x86_64-unknown-linux-gnu' }}
run: cargo test --target ${{ matrix.targets }} -- --nocapture
17 changes: 8 additions & 9 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
name: Build & Deploy docs

on: [push]
on: [push, pull_request]

jobs:
doc:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust-toolchain: [nightly]
permissions:
contents: write
env:
default-branch: ${{ format('refs/heads/{0}', github.event.repository.default_branch) }}
RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links -D missing-docs
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust-toolchain }}
- uses: dtolnay/rust-toolchain@nightly
- name: Build docs
continue-on-error: ${{ github.ref != env.default-branch }}
run: make doc
continue-on-error: ${{ github.ref != env.default-branch && github.event_name != 'pull_request' }}
run: |
cargo doc --no-deps --all-features
printf '<meta http-equiv="refresh" content="0;url=%s/index.html">' $(cargo tree | head -1 | cut -d' ' -f1) > target/doc/index.html
- name: Deploy to Github Pages
if: ${{ github.ref == env.default-branch }}
uses: JamesIves/github-pages-deploy-action@v4
with:
single-commit: true
branch: gh-pages
folder: target/doc
folder: target/doc
36 changes: 17 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,36 @@ A lightweight ELF parser written in Rust, providing assistance for loading appli

It reads the data of the ELF file, and generates Sections, Relocations, Segments and so on.

It also generate a layout of the user stack according to the given user parameters and environment variables. It will be
used for loading a given application into the physical memory in the kernel.
It also generate a layout of the user stack according to the given user parameters and environment variables,which will be
used for loading a given application into the physical memory of the kernel.

## Examples

```rust
let args: Vec<String> = vec![1, 2, 3];
let envs: Vec<String> = vec!["LOG=file"];
let auxv: BTreeMap<u8, usize> = BTreeMap::new();
```rust,ignore
let args: Vec<String> = vec!["arg1".to_string(), "arg2".to_string(), "arg3".to_string()];
let envs: Vec<String> = vec!["LOG=file".to_string()];
// The top of the user stack
let stack_top = uspace.end() - stack_size;
// The highest address of the user stack.
let ustack_end = 0x4000_0000;
let ustack_size = 0x2_0000;
let ustack_bottom = ustack_end - ustack_size;
let (stack_data, stack_bottom) = elf_parser::get_app_stack_region(
args,
&envs,
auxv,
stack_top,
stack_size,
);
let stack_data =
kernel_elf_parser::app_stack_region(&args, &envs, &auxv, ustack_bottom.into(), ustack_size);
assert_eq!(stack_data[0..8], [3, 0, 0, 0, 0, 0, 0, 0]);
uspace.map_alloc(stack_top, stack_size, MappingFlags::READ | MappingFlags::WRITE | MappingFlags::USER)?;
uspace.map_alloc(ustack_bottom, ustack_size, MappingFlags::READ | MappingFlags::WRITE | MappingFlags::USER)?;
// Copy the stack data to the user stack.
// After initialization, the stack layout is as follows: <https://articles.manugarg.com/aboutelfauxiliaryvectors.html>
unsafe {
core::ptr::copy_nonoverlapping(
stack_data.as_ptr(),
phys_to_virt(stack_top).as_mut_ptr(),
phys_to_virt(ustack_size).as_mut_ptr(),
stack_data.len(),
);
}
// The stack_bottom is the real stack pointer after inserting some auxiliary data on the user stack.
ucontext.sp = stack_bottom;
ucontext.sp = ustack_end - stack_data.len();
```

0 comments on commit 1ef010e

Please sign in to comment.