arceos-hashmap
A standalone ArceOS unikernel exercise (arceos-hashmap): enable collections::HashMap under axstd, with dependencies from crates.io, multi-architecture builds and QEMU runs via cargo xtask.
This repository is the exercise.
Supported Architectures
| Architecture | Rust Target | QEMU Machine | Platform |
|---|---|---|---|
| riscv64 | riscv64gc-unknown-none-elf |
qemu-system-riscv64 -machine virt |
riscv64-qemu-virt |
| aarch64 | aarch64-unknown-none-softfloat |
qemu-system-aarch64 -machine virt |
aarch64-qemu-virt |
| x86_64 | x86_64-unknown-none |
qemu-system-x86_64 -machine q35 |
x86-pc |
| loongarch64 | loongarch64-unknown-none |
qemu-system-loongarch64 -machine virt |
loongarch64-qemu-virt |
Prerequisites
-
Rust nightly toolchain (edition 2024)
-
Bare-metal targets (install the ones you need)
-
QEMU (install the emulators for your target architectures)
# Ubuntu/Debian # macOS (Homebrew) -
rust-objcopy (from
cargo-binutils, required for non-x86_64 targets)
Quick Start
Get Source Code
Method 1: Get source code from crates.io
# install cargo-clone sub-command
# get source code of arceos-hashmap crate from crates.io
# into crate dir
Method 2: Clone the tg-arceos-tutorial repository
Build & Run
# Build and run on RISC-V 64 QEMU (default)
# Build and run on other architectures
# Build only (no QEMU)
Exercise
Requirements
Implement support for collections::HashMap in axstd.
The axstd crate published on crates.io does not yet provide an implementation for collections::HashMap. Therefore, this repository will fail to compile unless you modify axstd locally to add this support.
Expectation
Serial output should include:
test_hashmap() OK!
Memory tests run OK!
Verification
- The serial output must contain
test_hashmap() OK!. - The serial output must contain
Memory tests run OK!.
Run the test script:
Tips
- If compiler errors mention
std, that name refers toaxstd: the application usesextern crate axstd as std;insrc/main.rs. - A random number helper
random()is available inaxhal, which you can use when wiring randomness forHashMap(e.g. default hasher behavior). - To hack on ArceOS crates locally, clone the crate and switch the dependency in
Cargo.tomlfrom a version requirement topath:
[]
= { = "./axstd", = ["defplat", "alloc"], = true }
(Adjust the path to match where you put the sources.)
Project Structure
exercise-hashmap/
├── .cargo/
│ └── config.toml # cargo xtask alias
├── configs/
│ ├── riscv64.toml
│ ├── aarch64.toml
│ ├── x86_64.toml
│ └── loongarch64.toml
├── scripts/
│ └── test.sh # Multi-arch run + expected log line checks
├── src/
│ └── main.rs # Application entry point (HashMap memory test)
├── xtask/
│ └── src/
│ └── main.rs # build/run and QEMU wiring
├── build.rs # Linker script path (arch auto-detect)
├── Cargo.toml # Package arceos-hashmap, axstd, etc.
├── rust-toolchain.toml # Nightly, targets, llvm-tools
└── README.md
Key Components
| Component | Role |
|---|---|
axstd |
ArceOS standard library (replaces Rust's std in no_std environment) |
axhal |
Hardware abstraction layer, generates the linker script at build time |
build.rs |
Locates the linker script generated by axhal and passes it to the linker |
configs/*.toml |
Pre-generated platform configuration for each architecture |
License
GPL-3.0