diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8809905 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,48 @@ +name: CI + +on: [push, pull_request] + +jobs: + clippy: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + rust-toolchain: [nightly] + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@nightly + with: + toolchain: ${{ matrix.rust-toolchain }} + components: rust-src, clippy, rustfmt + - name: Setup ArceOS + run: ./scripts/get_deps.sh + - name: Check rust version + run: rustc --version --verbose + - name: Check code format + run: cargo fmt -- --check + - name: Clippy + run: cargo clippy + - name: Build for rust-std + run: cargo build + + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + 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, 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 }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..88d381e --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/target +/.vscode +/.arceos +/.cargo +.DS_Store +Cargo.lock +*.elf +*.bin diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..606a43c --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "arceos-helloworld" +version = "0.1.0" +edition = "2021" +authors = ["Yuekai Jia "] +homepage = "https://github.com/arceos-org/arceos" +repository = "https://github.com/arceos-org/app-helloworld" + +[dependencies] +axstd = { git = "https://github.com/arceos-org/arceos.git", optional = true } diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d1e6250 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +AX_ROOT ?= $(PWD)/.arceos + +all: build + +ax_root: + @./scripts/set_ax_root.sh $(AX_ROOT) + +build run justrun debug fmt disasm clean: ax_root + @make -C $(AX_ROOT) A=$(PWD) $@ + +.PHONY: all ax_root build run justrun debug fmt disasm clean diff --git a/README.md b/README.md new file mode 100644 index 0000000..01d01c8 --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +# app-helloworld + +[![CI](https://github.com/arceos-org/app-helloworld/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/arceos-org/app-helloworld/actions/workflows/ci.yml) + +A "Hello, world!" application on [ArceOS](https://github.com/arceos-org/arceos). + +## Quick Start + +### 1. Install Build Dependencies + +Install [cargo-binutils](https://github.com/rust-embedded/cargo-binutils) to use `rust-objcopy` and `rust-objdump` tools: + +```bash +cargo install cargo-binutils +``` + +Download ArceOS source code: + +```bash +./scripts/get_deps.sh +``` + +The ArceOS repository will be cloned into `.arceos`. +You can also skip this step by specifying the `AX_ROOT` parameter when running the `make` command. + +### 2. Build & Run + +```bash +make ARCH= LOG= run +``` + +Where `` should be one of `riscv64`, `aarch64`,`x86_64`. + +`` should be one of `off`, `error`, `warn`, `info`, `debug`, `trace`. + +Other arguments are the same as ArceOS's [Makefile](https://github.com/arceos-org/arceos/blob/main/Makefile). + +For example, to run on `qemu-system-aarch64` with 4 cores and log level `info`: + +```bash +make ARCH=aarch64 LOG=info SMP=4 run +``` + +[![Run app-helloworld on ArceOS](img/demo.gif)](https://asciinema.org/a/669147?autoplay=1) diff --git a/img/demo.gif b/img/demo.gif new file mode 100644 index 0000000..64cb207 Binary files /dev/null and b/img/demo.gif differ diff --git a/scripts/config.toml.temp b/scripts/config.toml.temp new file mode 100644 index 0000000..b152826 --- /dev/null +++ b/scripts/config.toml.temp @@ -0,0 +1,2 @@ +[patch.'https://github.com/arceos-org/arceos.git'] +axstd = { path = "%AX_ROOT%/ulib/axstd" } diff --git a/scripts/get_deps.sh b/scripts/get_deps.sh new file mode 100755 index 0000000..4c5a8bd --- /dev/null +++ b/scripts/get_deps.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +AX_ROOT=.arceos + +test ! -d "$AX_ROOT" && echo "Cloning repositories ..." || true +test ! -d "$AX_ROOT" && git clone https://github.com/arceos-org/arceos .arceos || true diff --git a/scripts/set_ax_root.sh b/scripts/set_ax_root.sh new file mode 100755 index 0000000..a9f65db --- /dev/null +++ b/scripts/set_ax_root.sh @@ -0,0 +1,13 @@ +#/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +AX_ROOT=$1 + +mkdir -p .cargo +sed -e "s|%AX_ROOT%|$AX_ROOT|g" scripts/config.toml.temp > .cargo/config.toml + +echo "Set AX_ROOT (ArceOS directory) to $AX_ROOT" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..97161c8 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,10 @@ +#![cfg_attr(feature = "axstd", no_std)] +#![cfg_attr(feature = "axstd", no_main)] + +#[cfg(feature = "axstd")] +use axstd::println; + +#[cfg_attr(feature = "axstd", no_mangle)] +fn main() { + println!("Hello, world!"); +}