[][src]Crate shadow_rs

shadow-rs is a build script write by Rust

It's can record compiled project much information. Like version info,dependence info.Like shadow,if compiled,never change.forever follow your project.

Generated rust const by exec:cargo build

Example

pub const RUST_VERSION :&str = "rustc 1.45.0 (5c1f21c3b 2020-07-13)";
pub const BUILD_RUST_CHANNEL :&str = "debug";
pub const COMMIT_AUTHOR :&str = "baoyachi";
pub const BUILD_TIME :&str = "2020-08-16 13:48:52";
pub const COMMIT_DATE :&str = "2020-08-16 13:12:52";
pub const COMMIT_EMAIL :&str = "xxx@gmail.com";
pub const PROJECT_NAME :&str = "shadow-rs";
pub const RUST_CHANNEL :&str = "stable-x86_64-apple-darwin (default)";
pub const BRANCH :&str = "master";
pub const CARGO_LOCK :&str = r#"
├── chrono v0.4.19
│   ├── libc v0.2.80
│   ├── num-integer v0.1.44
│   │   └── num-traits v0.2.14
│   │       [build-dependencies]
│   │       └── autocfg v1.0.1
│   ├── num-traits v0.2.14 (*)
│   └── time v0.1.44
│       └── libc v0.2.80
└── git2 v0.13.12
├── log v0.4.11
│   └── cfg-if v0.1.10
└── url v2.2.0
├── form_urlencoded v1.0.0
│   └── percent-encoding v2.1.0
└── percent-encoding v2.1.0"#;
pub const CARGO_VERSION :&str = "cargo 1.45.0 (744bd1fbb 2020-06-15)";
pub const BUILD_OS :&str = "macos-x86_64";
pub const COMMIT_HASH :&str = "386741540d73c194a3028b96b92fdeb53ca2788a";
pub const PKG_VERSION :&str = "0.3.13";

Quick Start

step 1

In your cargo.toml packgae with package add with below config

[package]
build = "build.rs"

[dependencies]
shadow-rs = "0.5"

[build-dependencies]
shadow-rs = "0.5"

step 2

In your project add file build.rs,then add with below config

fn main() -> shadow_rs::SdResult<()> {
   shadow_rs::new()
}

step 3

In your project find bin rust file.It's usually main.rs, you can find file with Cargo.toml,then add with below config The shadow!(build) with build config,add Rust build mod in your project. You can also replace it(build) with other name.

#[macro_use]
extern crate shadow_rs;

shadow!(build);

step 4

Then you can use const that's shadow build it(main.rs).

The build mod just we use shadow!(build) generated.

fn main(){
   println!("{}",shadow_rs::is_debug());//get build mode. cargo build --release return false.normally return true.

   println!("{}",build::version()); //print version() method
   println!("{}",build::BRANCH); //master
   println!("{}",build::SHORT_COMMIT);//8405e28e
   println!("{}",build::COMMIT_HASH);//8405e28e64080a09525a6cf1b07c22fcaf71a5c5
   println!("{}",build::COMMIT_DATE);//2020-08-16T06:22:24+00:00
   println!("{}",build::COMMIT_AUTHOR);//baoyachi
   println!("{}",build::COMMIT_EMAIL);//xxx@gmail.com

   println!("{}",build::BUILD_OS);//macos-x86_64
   println!("{}",build::RUST_VERSION);//rustc 1.45.0 (5c1f21c3b 2020-07-13)
   println!("{}",build::RUST_CHANNEL);//stable-x86_64-apple-darwin (default)
   println!("{}",build::CARGO_VERSION);//cargo 1.45.0 (744bd1fbb 2020-06-15)
   println!("{}",build::PKG_VERSION);//0.3.13
   println!("{}",build::CARGO_TREE); //like command:cargo tree

   println!("{}",build::PROJECT_NAME);//shadow-rs
   println!("{}",build::BUILD_TIME);//2020-08-16 14:50:25
   println!("{}",build::BUILD_RUST_CHANNEL);//debug
}

Clap example

And you can also use const with clap.

For the user guide and futher documentation, please read The shadow-rs document.

Macros

shadow

Add a mod in project with $build_mod.

Enums

BuildRustChannel

Functions

is_debug

Get current project build mode.

new

It's shadow-rs Initialization entry.

Type Definitions

SdResult