Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
equation314 committed Jul 22, 2024
0 parents commit 029bc45
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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 }}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/target
/.vscode
/.arceos
/.cargo
.DS_Store
Cargo.lock
*.elf
*.bin
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "arceos-helloworld"
version = "0.1.0"
edition = "2021"
authors = ["Yuekai Jia <[email protected]>"]
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 }
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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=<arch> LOG=<log> run
```

Where `<arch>` should be one of `riscv64`, `aarch64``x86_64`.

`<log>` 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)
Binary file added img/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions scripts/config.toml.temp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[patch.'https://github.com/arceos-org/arceos.git']
axstd = { path = "%AX_ROOT%/ulib/axstd" }
6 changes: 6 additions & 0 deletions scripts/get_deps.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions scripts/set_ax_root.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#/bin/bash

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <AX_ROOT>"
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"
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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!");
}

0 comments on commit 029bc45

Please sign in to comment.