From 9a13787575c7007d7122efafbde4a9b38fbe6c67 Mon Sep 17 00:00:00 2001 From: Yuekai Jia Date: Mon, 22 Jul 2024 15:38:29 +0800 Subject: [PATCH] Initial commit --- .github/workflows/ci.yml | 48 ++++++++++++++++++++++++++++++++++++++++ .gitignore | 8 +++++++ Cargo.toml | 10 +++++++++ Makefile | 11 +++++++++ README.md | 43 +++++++++++++++++++++++++++++++++++ scripts/config.toml.temp | 2 ++ scripts/get_deps.sh | 6 +++++ scripts/set_ax_root.sh | 13 +++++++++++ src/main.rs | 10 +++++++++ 9 files changed, 151 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 Makefile create mode 100644 README.md create mode 100644 scripts/config.toml.temp create mode 100755 scripts/get_deps.sh create mode 100755 scripts/set_ax_root.sh create mode 100644 src/main.rs 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..7cfe87a --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# app-helloworld + +[![CI](https://github.com/arceos-org/app-helloworld/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/arceos-org/app-helloworld/actions/workflows/build.yml) +[![CI](https://github.com/arceos-org/app-helloworld/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/arceos-org/app-helloworld/actions/workflows/test.yml) + +A "Hello, world!" application on [ArceOS](https://github.com/arceos-org/arceos). + +## Install build dependencies + +1. Install [cargo-binutils](https://github.com/rust-embedded/cargo-binutils) to use `rust-objcopy` and `rust-objdump` tools: + + ```bash + cargo install cargo-binutils + ``` + +3. 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. + +## Build & Run + +```bash +make ARCH= LOG= run +``` + +Where `path/to/app` is the relative path to the application. + +`` 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 +``` 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!"); +}