-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from baoyachi/current_branch
add current branch, semver version const
- Loading branch information
Showing
9 changed files
with
183 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "shadow-rs" | ||
version = "0.5.9" | ||
version = "0.5.10" | ||
authors = ["baoyachi <[email protected]>"] | ||
edition = "2018" | ||
description = "A build script write by Rust" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
[![DepStatus](https://deps.rs/repo/github/baoyachi/shadow-rs/status.svg)](https://deps.rs/repo/github/baoyachi/shadow-rs) | ||
[![Gitter](https://badges.gitter.im/shadow-rs/community.svg)](https://gitter.im/shadow-rs/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) | ||
|
||
|
||
`shadow-rs` allows you to recall properties of the build process and environment at runtime, including: | ||
|
||
* `Cargo.toml` project version | ||
|
@@ -24,11 +23,15 @@ | |
You can use this tool to check in production exactly where a binary came from and how it was built. | ||
|
||
# Full Examples | ||
* Check out the [shadow_example](https://github.com/baoyachi/shadow-rs/tree/master/example_shadow) for a simple demonstration of how `shadow-rs` might be used to provide build-time information at run-time. | ||
|
||
* Check out the [shadow_example](https://github.com/baoyachi/shadow-rs/tree/master/example_shadow) for a simple | ||
demonstration of how `shadow-rs` might be used to provide build-time information at run-time. | ||
* built in method:[examples](https://github.com/baoyachi/shadow-rs/tree/master/examples). | ||
|
||
# Setup Guide | ||
|
||
### 1) Modify `Cargo.toml` fields | ||
|
||
Modify your `Cargo.toml` like so: | ||
|
||
```TOML | ||
|
@@ -63,43 +66,65 @@ extern crate shadow_rs; | |
shadow!(build); | ||
``` | ||
|
||
**Notice that the `shadow!` macro is provided the identifier `build`. You can now use this identifier to access build-time information.** | ||
**Notice that the `shadow!` macro is provided the identifier `build`. You can now use this identifier to access | ||
build-time information.** | ||
|
||
### 4) Done. Use Shadow. | ||
|
||
```rust | ||
fn main() { | ||
println!("{}", shadow_rs::is_debug()); // check if this is a debug build | ||
|
||
println!("{}", build::version()); // the version (description binary detail information) | ||
println!("{}", build::BRANCH); // the branch, e.g. 'master' | ||
println!("{}", build::TAG); // the tag, e.g. 'v1.0.0' | ||
println!("{}", build::SHORT_COMMIT); // short commit hash, e.g. '8405e28e' | ||
println!("{}", build::COMMIT_HASH); // full commit hash, e.g. '8405e28e64080a09525a6cf1b07c22fcaf71a5c5' | ||
println!("{}", build::COMMIT_DATE); // commit date, e.g. '2020-08-16 11:52:47' | ||
println!("{}", build::COMMIT_AUTHOR); // commit author, e.g. 'baoyachi' | ||
println!("{}", build::COMMIT_EMAIL); // commit email, e.g. '[email protected]' | ||
|
||
println!("{}", build::BUILD_OS); // the OS that built the binary, e.g. 'macos-x86_64' | ||
println!("{}", build::RUST_VERSION); // rustc version e.g. 'rustc 1.45.0 (5c1f21c3b 2020-07-13)' | ||
println!("{}", build::RUST_CHANNEL); // rust toolchain e.g. 'stable-x86_64-apple-darwin (default)' | ||
println!("{}", build::CARGO_VERSION); // cargo version e.g. 'cargo 1.45.0 (744bd1fbb 2020-06-15)' | ||
println!("{}", build::PKG_VERSION); // e.g. '0.3.13' | ||
println!("{}", build::CARGO_TREE); // e.g. the output of '$ cargo tree' | ||
|
||
println!("{}", build::PROJECT_NAME); // your project name, e.g. 'shadow-rs' | ||
println!("{}", build::BUILD_TIME); // time when start build occurred, e.g. '2020-08-16 14:50:25' | ||
println!("{}", build::BUILD_RUST_CHANNEL); // e.g. 'debug' | ||
|
||
//shadow-rs built in method | ||
println!("{}", shadow_rs::is_debug()); // check if this is a debug build | ||
println!("{}", shadow_rs::branch()); // get current project git branch. e.g.'master' | ||
|
||
//shadow-rs built in const | ||
println!("{}", build::version()); // the version (description binary detail information) | ||
println!("{}", build::PKG_VERSION); // current package version. e.g. '1.3.15-beta2' | ||
println!("{}", build::PKG_VERSION_MAJOR); //current package major version. e.g. '1' | ||
println!("{}", build::PKG_VERSION_MINOR); //current package minor version. e.g. '3' | ||
println!("{}", build::PKG_VERSION_PATCH); //current package minor version. e.g. '15' | ||
println!("{}", build::PKG_VERSION_PRE); //current package minor version. e.g. 'beta2' | ||
println!("{}", build::BRANCH); // the branch, e.g. 'master' | ||
println!("{}", build::TAG); // the tag, e.g. 'v1.0.0' | ||
println!("{}", build::SHORT_COMMIT); // short commit hash, e.g. '8405e28e' | ||
println!("{}", build::COMMIT_HASH); // full commit hash, e.g. '8405e28e64080a09525a6cf1b07c22fcaf71a5c5' | ||
println!("{}", build::COMMIT_DATE); // commit date, e.g. '2020-08-16 11:52:47' | ||
println!("{}", build::COMMIT_AUTHOR); // commit author, e.g. 'baoyachi' | ||
println!("{}", build::COMMIT_EMAIL); // commit email, e.g. '[email protected]' | ||
|
||
println!("{}", build::BUILD_OS); // the OS that built the binary, e.g. 'macos-x86_64' | ||
println!("{}", build::RUST_VERSION); // rustc version e.g. 'rustc 1.45.0 (5c1f21c3b 2020-07-13)' | ||
println!("{}", build::RUST_CHANNEL); // rust toolchain e.g. 'stable-x86_64-apple-darwin (default)' | ||
println!("{}", build::CARGO_VERSION); // cargo version e.g. 'cargo 1.45.0 (744bd1fbb 2020-06-15)' | ||
println!("{}", build::CARGO_TREE); // e.g. the output of '$ cargo tree' | ||
|
||
println!("{}", build::PROJECT_NAME); // your project name, e.g. 'shadow-rs' | ||
println!("{}", build::BUILD_TIME); // time when start build occurred, e.g. '2020-08-16 14:50:25' | ||
println!("{}", build::BUILD_RUST_CHANNEL); // e.g. 'debug' | ||
} | ||
``` | ||
|
||
## Clap Example | ||
And you can also use `shadow-rs` with [`clap`](https://github.com/baoyachi/shadow-rs/blob/master/example_shadow/src/main.rs). | ||
## Clap Example | ||
|
||
And you can also use `shadow-rs` | ||
with [`clap`](https://github.com/baoyachi/shadow-rs/blob/master/example_shadow/src/main.rs). | ||
|
||
## Support const,method in table | ||
|
||
#### shadow-rs built in method. | ||
* how to use 👉:[examples](https://github.com/baoyachi/shadow-rs/tree/master/examples) | ||
| method | desc | | ||
| ------ | ------ | | ||
| is_debug() | check if this is a debug build.e.g.'true/false' | | ||
| branch() | get current project branch.e.g.'master/develop' | | ||
|
||
#### shadow-rs support build const. | ||
* how to use see 👉:[shadow_example](https://github.com/baoyachi/shadow-rs/tree/master/example_shadow) | ||
|
||
## Support const table | ||
| const | example | | ||
| ------ | ------ | | ||
| version() | master/develop | | ||
| version() | support mini version information.It's use easy. | | ||
| BRANCH | master/develop | | ||
| TAG | v1.0.0 | | ||
| SHORT_COMMIT | 8405e28e | | ||
|
@@ -117,10 +142,13 @@ And you can also use `shadow-rs` with [`clap`](https://github.com/baoyachi/shado | |
| BUILD_TIME | 2020-08-16 14:50:25 | | ||
| BUILD_RUST_CHANNEL | debug/release | | ||
|
||
If you have any questions, please create an [issue](https://github.com/baoyachi/shadow-rs/issues/new) so we may improve the documentation where it may be unclear. | ||
If you have any questions, please create an [issue](https://github.com/baoyachi/shadow-rs/issues/new) so we may improve | ||
the documentation where it may be unclear. | ||
|
||
## People using Shadow | ||
If you are using `shadow-rs`, please tell me! Or instead, consider making a note here: [Shadow Users Collection](https://github.com/baoyachi/shadow-rs/issues/19). | ||
|
||
If you are using `shadow-rs`, please tell me! Or instead, consider making a note | ||
here: [Shadow Users Collection](https://github.com/baoyachi/shadow-rs/issues/19). | ||
|
||
<table> | ||
<tr> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "example_shadow" | ||
version = "0.1.0" | ||
version = "0.1.8-beta3" | ||
authors = ["baoyachi <[email protected]>"] | ||
edition = "2018" | ||
build = "build.rs" | ||
|
@@ -12,4 +12,4 @@ clap = "2.33.3" | |
shadow-rs = "0.5" | ||
|
||
[build-dependencies] | ||
shadow-rs = "0.5" | ||
shadow-rs = "0.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
println!("debug:{}", shadow_rs::is_debug()); // check if this is a debug build. e.g 'true/false' | ||
println!("branch:{}", shadow_rs::branch()); // get current project branch. e.g 'master/develop' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters