-
clone该项目到本地
-
本地新建项目demo文件夹 mkdir demo cd demo
-
新建项目文件 touch Cargo.toml touch README.md
-
从模板项目copy文件 cp -r ../rust-project-template/deny.toml . cp -r ../rust-project-template/.github . cp -r ../rust-project-template/.pre-commit-config.yaml . cp -r ../rust-project-template/.pre-commit-config.yaml . cp -r ../rust-project-template/_typos.toml .
-
初始化项目,版本控制 git init
-
设置git提交用户信息,多账户隔离 cd ./.git git config user.name "your name" git config user.email "your email address"
-
项目根目录执行命令安装pre-commit cd .. 》pre-commit install pre-commit installed at .git/hooks/pre-commit
-
提交代码 》git status On branch master
No commits yet
Untracked files: (use "git add ..." to include in what will be committed)
.github/
.pre-commit-config.yaml
Cargo.toml
README.md
_typos.toml
deny.toml
nothing added to commit but untracked files present (use "git add" to track)
- 构建项目目录 cargo new abi --lib 所有protocol buffer和gRPC自动生成的代码都放到一个crate中,然后为其中的代码生成trait,然后再在别的项目中使用
cargo new my-project-name --lib
新建可执行的项目 cargo new my-project-service
-
修改my-project-name项目文件中Cargo.toml中name,方便提交到crate.io,避免冲突
-
配置workspace demo目录下Cargo.toml,添加 [workspace] members = [ "abi", "my-project-name", "my-project-service", ]
-
构建项目 cargo build
Compiling my-project-service v0.1.0 (/Users/uh/Documents/sourcecode/github/rust-project-template/my-project-service) Compiling my-project-name v0.1.0 (/Users/uh/Documents/sourcecode/github/rust-project-template/my-project-name) Compiling abi v0.1.0 (/Users/uh/Documents/sourcecode/github/rust-project-template/abi) Finished dev [unoptimized + debuginfo] target(s) in 1.54s
-
github新建参考 登录github.com, new repository
-
推荐本地代码至github上 git remote add origin https://github.com/humyna/rust-project-template.git git branch -M main git push -u origin main