工作空间 workspace 试水

更新 README.md
This commit is contained in:
shikong 2024-05-25 17:46:51 +08:00
parent 949d1dff49
commit 33a2ae3d16
Signed by: Shikong
GPG Key ID: BD85FF18B373C341
5 changed files with 84 additions and 0 deletions

5
.gitignore vendored
View File

@ -92,3 +92,8 @@ fabric.properties
.idea/caches/build_file_checksums.ser .idea/caches/build_file_checksums.ser
!/.idea/git_toolbox_prj.xml !/.idea/git_toolbox_prj.xml
# Added by cargo
/target

7
5.function/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "function"
# 继承 workspace 的版本号
version.workspace = true
edition = "2021"
[dependencies]

3
5.function/src/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

24
Cargo.toml Normal file
View File

@ -0,0 +1,24 @@
# 没有 [package] 为虚拟清单类型的 工作空间
[workspace.package]
# 为工作空间下的子包 定义版本号
# 子包 可以 通过 version.workspace 继承 工作空间的版本号
version = "0.1.0"
[workspace]
resolver = "2"
exclude = [
".git",
".idea",
".vscode",
"1.hello_world"
]
members = [
"2.hello_cargo",
"3.guessing_game",
"4.variables",
"5.function",
"x.bubble_sort"
]

45
README.MD Normal file
View File

@ -0,0 +1,45 @@
# Rust Study
## 自学 Rust 仓库
### 参考资料
- [Rust 语言中文社区](https://rustcc.cn/)
- [Rust 官方文档](https://doc.rust-lang.org/book/)
- [Rustlings](https://github.com/rust-lang/rustlings)
- [Rust by Example](https://doc.rust-lang.org/rust-by-example/)
- [Rustlings](https://github.com/rust-lang/rustlings)
- [Rust 程序设计语言](https://kaisery.github.io/trpl-zh-cn/)
## 子包创建
例子:
```shell
cargo new 5.function --name function
```
### 编译某个子包
```shell
cargo build --manifest-path 5.function/Cargo.toml
```
### 运行某个子包
```shell
cargo run --manifest-path 5.function/Cargo.toml
```
### 工作空间 workspace
参考文档
- https://course.rs/cargo/reference/workspaces.html
#### 编译所有子包
```shell
cargo build --workspace
```
#### 编译工作空间下 某个子包
```shell
cargo build -p variables
```
#### 运行工作空间下 某个子包
```shell
cargo run -p function
```