2 个版本
使用旧的 Rust 2015
0.5.2 | 2018年10月22日 |
---|---|
0.5.1 | 2018年9月21日 |
#1597 in 开发工具
22KB
306 行
libsel4-sys
概述
根据 feL4 清单配置,构建 sel4 内核并生成其周围的 Rust 绑定。
此库为seL4 代码库提供薄型 Rust 绑定;其他 crate 将提供更符合 Rust 习惯的封装。
适用于由 cargo-fel4 管理的项目,有关入门材料请参阅该仓库。
入门
依赖关系
libsel4-sys 使用 git 子模块来使 seL4 相关代码本地化可用。构建 seL4 代码需要安装几个系统依赖项。少数 Rust 依赖项由 Cargo.toml 管理,因此需要 Cargo 以及用于交叉编译的 Xargo。Rustup 是推荐的 Rust 工具链管理器。
- rust (nightly)
- xargo (用于交叉编译)
- gcc/g++ 交叉编译器 (用于 ARM 目标)
- cmake (用于 seL4 的构建)
- ninja-build (用于 seL4 的构建)
- python (用于 seL4 的构建)
- xmlint (用于 seL4 的构建)
构建
此项目旨在使用 cargo fel4
命令构建,该命令管理相关环境变量的管道,这些环境变量对下游项目很重要。
-
安装 Rust Nightly
# Download the rustup install script wget https://static.rust-lang.org/rustup/rustup-init.sh # Install rustup chmod +x rustup-init.sh sh rustup-init.sh rustup install nightly
-
安装 xargo
# Xargo requires rust-src component rustup component add --toolchain nightly rust-src # Install Xargo cargo +nightly install xargo
-
安装 GNU交叉编译器
# Used by the armv7-sel4-fel4 target sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf # Used by the aarch64-sel4-fel4 target sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
-
安装Python、pip以及特定的pip软件包。
# Install python and pip, if you don't have them already sudo apt-get install python-pip pip install sel4-deps
-
安装 cmake
需要CMake版本
3.7.2
或更高版本。可以从 cmake.org 获取二进制发行版。Ubuntu上最近二进制安装的示例工作流程可以在StackExchange的askUbuntu上找到 这里。
或者,您可以使用Python的
pip
工具安装最新的cmake。sudo pip install --upgrade cmake
-
由于seL4构建系统的要求,需要安装 ninja-build。需要
1.7.1
或更高版本。可以从 github 获取二进制发行版。Ubuntu用户通常可以使用apt-get安装ninja。
sudo apt-get install ninja-build
-
底层的seL4构建系统需要
xmlint
。sudo apt-get install libxml2-utils
-
按照该仓库的说明使用 cargo-fel4 进行安装。
-
使用
cargo-fel4
创建一个新的feL4项目,它将自动将libsel4-sys
作为依赖项来构建。cargo fel4 new demo_project cd demo_project cargo fel4 build
-
除了使用
cargo-fel4
之外,还可以进行手动构建,尽管不建议一般使用。 -
克隆libsel4-sys仓库
git clone https://github.com/maindotrs/libsel4-sys.git cd libsel4-sys
-
将seL4相关依赖项拉入本地文件系统
git submodule update --init
-
手动构建需要设置环境变量
FEL4_MANIFEST_PATH
,它包含指向fel4.toml文件的路径,该文件由fel4-config
crate指定。此外,必须提供RUST_TARGET_PATH
,它指向包含相关Rust目标规范JSON文件的目录,这些文件对于所需的构建目标是相关的。RUST_TARGET_PATH=$PWD/test_configs FEL4_MANIFEST_PATH=$PWD/test_configs/fel4.toml xargo rustc --target x86_64-sel4-fel4 -vv
安装
可以通过在Cargo.toml中包含它来将libsel4-sys包含在您的Rust项目中。
- 在相关的
[dependencies]
部分中libsel4-sys = "0.5"
使用
生成的绑定应该被视为相对短暂和动态的,与大多数Rust库相比。输出是针对特定目标(例如 "armv7-sel4-fel4")以及从输入feL4清单文件派生的配置标志的上下文特定的。
有关暴露的原始API的概述,请参阅Rust文档。
RUST_TARGET_PATH=$PWD/test_configs FEL4_MANIFEST_PATH=$PWD/test_configs/fel4.toml xargo doc --target x86_64-sel4-fel4 -vv
示例
- 创建一个seL4_CapRights_t实例
extern crate libsel4_sys; use libsel4_sys::{seL4_Word, seL4_CapRights_new}; let cap_rights = unsafe { seL4_CapRights_new(0 as seL4_Word, 1 as seL4_Word, 0 as seL4_Word); };
测试
目前,所有测试都在 cargo-fel4
仓库中执行,该仓库具有自动生成适当的测试运行器代码并练习结果工件的能力。
构建
有关构建和安装,请参阅 cargo-fel4仓库。
运行
安装 cargo-fel4
和 libsel4-sys
依赖项后,您应该能够运行
cargo fel4 new tests
cd tests
cargo fel4 test build
cargo fel4 test simulate
许可证
请参阅 LICENSE 文件以获取更多详细信息
依赖关系
~0–2.2MB
~44K SLoC