xref: /DragonOS/docs/userland/appdev/rust-quick-start.md (revision 7401bec5e3c42015399a46e29c370abe7c7388b5)
1# Rust应用开发快速入门
2
3## 编译环境
4
5  DragonOS与Linux具有部分二进制兼容性,因此可以使用Linux的Rust编译器进行编译,但是需要进行一些配置:
6
7您可以参考DragonOS的`tools/bootstrap.sh`中,`initialize_userland_musl_toolchain()`函数的实现,进行配置。
8或者,只要运行一下bootstrap.sh就可以了。
9
10主要是因为DragonOS还不支持动态链接,但是默认的工具链里面,包含了动态链接解释器相关的代码,因此像脚本内那样,进行替换就能运行。
11
12## 配置项目
13
14### 从模板创建
15
16:::{note}
17该功能需要dadk 0.1.4及以上版本方能支持
18:::
19
201. 使用DragonOS的tools目录下的`bootstrap.sh`脚本初始化环境
212. 在终端输入`cargo install cargo-generate`
223. 在终端输入
23
24```shell
25cargo generate --git https://github.com/DragonOS-Community/Rust-App-Template
26```
27即可创建项目。如果您的网络较慢,请使用镜像站
28```shell
29cargo generate --git https://git.mirrors.dragonos.org/DragonOS-Community/Rust-App-Template
30```
31
324. 使用`cargo run`来运行项目
335. 在DragonOS的`user/dadk/config`目录下,使用`dadk new`命令,创建编译配置,安装到DragonOS的`/`目录下。
34(在dadk的编译命令选项处,请使用Makefile里面的`make install`配置进行编译、安装)
356. 编译DragonOS即可安装
36
37### 手动配置
38
39如果您需要移植别的库/程序到DragonOS,请参考模板内的配置。
40
41由于DragonOS目前不支持动态链接,因此目前需要在RUSTFLAGS里面指定`-C target-feature=+crt-static -C link-arg=-no-pie`
42