Skip to content

Commit

Permalink
[feat] Support complie and test musl app on rv64 and aarch64
Browse files Browse the repository at this point in the history
  • Loading branch information
Azure-stars committed Oct 22, 2024
1 parent ade3b4c commit 3d8cef4
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 23 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,54 @@ jobs:
fail-fast: false
matrix:
rust-toolchain: [nightly]
targets: [x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none-softfloat]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust-toolchain }}
components: rust-src, clippy, rustfmt
targets: ${{ matrix.targets }}
- name: Setup ArceOS
run: ./scripts/get_deps.sh
- name: Check rust version
run: rustc --version --verbose
- name: Check code format
continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }}
run: cargo fmt -- --check
run: cargo fmt --all -- --check
- name: Clippy
continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }}
run: cargo clippy
run: cargo clippy --target ${{ matrix.targets }} --all-features -- -D warnings -A clippy::new_without_default

build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
arch: [x86_64]
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
targets: x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none, aarch64-unknown-none-softfloat
- uses: Swatinem/rust-cache@v2
- run: cargo install cargo-binutils
- run: ./scripts/get_deps.sh
- name: Build for ${{ matrix.arch }}
run: make ARCH=${{ matrix.arch }}

test-musl:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
arch: [x86_64, riscv64, aarch64]
rust-toolchain: [nightly]
arch: [x86_64]
env:
qemu-version: 8.2.0
steps:
Expand Down
21 changes: 13 additions & 8 deletions apps/libc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ ifeq ($(TARGET),musl)
CFLAGS := -static
ifeq ($(ARCH),x86_64)
RUST_TARGET := x86_64-unknown-linux-musl
RUSTFLAGS := ""
else ifeq ($(ARCH),aarch64)
RUST_TARGET := aarch64-unknown-linux-musl
RUSTFLAGS := "-C linker=aarch64-linux-musl-gcc"
else ifeq ($(ARCH),riscv64)
$(warning "Warn: Rust musl target not supported for riscv64")
RUST_TARGET :=
RUST_TARGET := ""
RUSTFLAGS := ""
else
$(error "Unknown ARCH")
endif
Expand Down Expand Up @@ -51,15 +54,17 @@ build_c:
done

build_rust:
@for app in $(shell find rust -name Cargo.toml); do \
echo "Building $$(dirname $${app})"; \
app_name=$$(basename $$(dirname $${app})); \
cargo build --release --target $(RUST_TARGET) --manifest-path $${app} ; \
cp $$(dirname $${app})/target/$(RUST_TARGET)/release/$${app_name} build/$(ARCH)/$${app_name}_rust ; \
done
if [ -n $(RUST_TARGET) ]; then \
for app in $(shell find rust -name Cargo.toml); do \
echo "Building $$(dirname $${app})"; \
app_name=$$(basename $$(dirname $${app})); \
RUSTFLAGS=$(RUSTFLAGS) cargo build --release --target $(RUST_TARGET) --manifest-path $${app} ; \
cp $$(dirname $${app})/target/$(RUST_TARGET)/release/$${app_name} build/$(ARCH)/$${app_name}_rust ; \
done \
fi

clean:
@rm -rf build/$(ARCH)
@rm -rf build
@for app in $(shell find rust -name Cargo.toml); do \
app_name=$$(basename $$(dirname $${app})); \
cargo clean --manifest-path $${app} ; \
Expand Down
25 changes: 25 additions & 0 deletions apps/nimbos/actual.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
make[1]: Entering directory '/home/yoimiya/OS/arceos-org/starry-next'
Set AX_ROOT (ArceOS directory) to /home/yoimiya/OS/arceos-org/starry-next/.arceos
make[2]: Entering directory '/home/yoimiya/OS/arceos-org/starry-next/.arceos'
Running on qemu...
qemu-system-aarch64 -m 128M -smp 1 -cpu cortex-a72 -machine virt -kernel /home/yoimiya/OS/arceos-org/starry-next/starry-next_aarch64-qemu-virt.bin -nographic

d8888 .d88888b. .d8888b.
d88888 d88P" "Y88b d88P Y88b
d88P888 888 888 Y88b.
d88P 888 888d888 .d8888b .d88b. 888 888 "Y888b.
d88P 888 888P" d88P" d8P Y8b 888 888 "Y88b.
d88P 888 888 888 88888888 888 888 "888
d8888888888 888 Y88b. Y8b. Y88b. .d88P Y88b d88P
d88P 888 888 "Y8888P "Y8888 "Y88888P" "Y8888P"

arch = aarch64
platform = aarch64-qemu-virt
target = aarch64-unknown-none-softfloat
smp = 1
build_mode = release
log_level = off

Hello, world!
make[2]: Leaving directory '/home/yoimiya/OS/arceos-org/starry-next/.arceos'
make[1]: Leaving directory '/home/yoimiya/OS/arceos-org/starry-next'
22 changes: 16 additions & 6 deletions apps/nimbos/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,19 @@ foreach(PATH ${SRCS})
)
endforeach()

add_custom_command(
OUTPUT syscall_ids.h
COMMAND sed ARGS -n -e s/__NR_/SYS_/p
< ${CMAKE_SOURCE_DIR}/lib/syscall_ids.h.in
> ${CMAKE_SOURCE_DIR}/lib/syscall_ids.h
)
# If arch is not x86_64, we need to use different syscall ids
if (NOT ${ARCH} STREQUAL x86_64)
add_custom_command(
OUTPUT syscall_ids.h
COMMAND sed ARGS -n -e s/__NR_/SYS_/p
< ${CMAKE_SOURCE_DIR}/lib/syscall_ids.h.no_x86.in
> ${CMAKE_SOURCE_DIR}/lib/syscall_ids.h
)
else()
add_custom_command(
OUTPUT syscall_ids.h
COMMAND sed ARGS -n -e s/__NR_/SYS_/p
< ${CMAKE_SOURCE_DIR}/lib/syscall_ids.h.in
> ${CMAKE_SOURCE_DIR}/lib/syscall_ids.h
)
endif()
11 changes: 11 additions & 0 deletions apps/nimbos/c/lib/syscall_ids.h.no_x86.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#define __NR_read 63
#define __NR_write 64
#define __NR_exit 93
#define __NR_yield 124
#define __NR_getpid 172
#define __NR_clone 220
#define __NR_fork 220
#define __NR_exec 221
#define __NR_waitpid 260
#define __NR_clock_gettime 403
#define __NR_clock_nanosleep 407
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ fn gen_kernel_config(arch: &str) -> Result<()> {
let key_name = key.to_uppercase().replace('-', "_");
match value {
toml_edit::Value::Integer(i) => {
writeln!(f, "pub(crate) const {}: usize = {};", key_name, i)?;
writeln!(f, "pub const {}: usize = {};", key_name, i)?;
}
toml_edit::Value::String(s) => {
writeln!(f, "pub(crate) const {}: &str = \"{}\";", key_name, s)?;
writeln!(f, "pub const {}: &str = \"{}\";", key_name, s)?;
}
_ => {
panic!("Unsupported value type");
Expand Down
5 changes: 4 additions & 1 deletion src/mm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ use crate::{config, loader};
/// - The second return value is the top of the user stack.
/// - The third return value is the address space of the user app.
pub fn load_user_app(app_name: &str) -> AxResult<(VirtAddr, VirtAddr, AddrSpace)> {
let mut uspace = axmm::new_user_aspace()?;
let mut uspace = axmm::new_user_aspace(
VirtAddr::from_usize(config::USER_SPACE_BASE),
config::USER_SPACE_SIZE,
)?;
let elf_info = loader::load_elf(app_name, uspace.base());
for segement in elf_info.segments {
debug!(
Expand Down

0 comments on commit 3d8cef4

Please sign in to comment.