Skip to content

Commit

Permalink
fix issue:
Browse files Browse the repository at this point in the history
  • Loading branch information
baoyachi committed Dec 14, 2020
1 parent cb8184b commit 94c7a9d
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shadow-rs"
version = "0.3.21"
version = "0.4.0"
authors = ["baoyachi <liaoymxsdl@gmail.com>"]
edition = "2018"
description = "A build script write by Rust"
Expand Down
58 changes: 33 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,52 +34,60 @@ This project can do this things that can help you quick get above information. l
You can also see [shadow_example](https://github.com/baoyachi/shadow-rs/tree/master/example_shadow) how to configuration.

## step 1
in your `cargo.toml` `packgae` with package add with below config
In your `cargo.toml` `packgae` with package add with below config
```toml
[package]
build = "build.rs"

[dependencies]
shadow-rs = "0.4"

[build-dependencies]
shadow-rs = "0.3"
shadow-rs = "0.4"
```

## step 2
in your project add file `build.rs`,then add with below config
In your project add file `build.rs`,then add with below config
```rust
fn main() -> shadow_rs::SdResult<()> {
shadow_rs::Shadow::new()
}
```

## step 3
in your project find `bin` rust file.It's usually `main.rs`, you can find `[bin]` file with `Cargo.toml`,then add with below config
In your project find `bin` rust file.It's usually `main.rs`, you can find `[bin]` file with `Cargo.toml`,then add with below config
The `shadow!(build)` with `build` config,add Rust build mod in your project. Also you also use other name that you want configuration.

```rust
pub mod shadow{
include!(concat!(env!("OUT_DIR"), "/shadow.rs"));
}
#[macro_use]
extern crate shadow_rs;

shadow!(build);
```

## step 4
then you can use const that's shadow build it(main.rs).
Then you can use const that's shadow build it(main.rs).
The `build` mod just we use `shadow!(build)` generated.

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

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

println!("{}",shadow::PROJECT_NAME);//shadow-rs
println!("{}",shadow::BUILD_TIME);//2020-08-16 14:50:25
println!("{}",shadow::BUILD_RUST_CHANNEL);//debug
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
}
```

Expand Down
3 changes: 2 additions & 1 deletion example_shadow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ build = "build.rs"

[dependencies]
clap = "2.33.3"
shadow-rs = "0.4.0"

[build-dependencies]
shadow-rs = {path="./../../shadow-rs"}
shadow-rs = "0.4.0"
47 changes: 24 additions & 23 deletions example_shadow/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use clap::App;

pub mod shadow {
include!(concat!(env!("OUT_DIR"), "/shadow.rs"));
}
#[macro_use]
extern crate shadow_rs;

shadow!(build);

pub fn version() -> String {
format!(
Expand All @@ -12,11 +13,11 @@ commit-hash:{}
build_time:{}
build_env:{},{}
"#,
shadow::BRANCH,
shadow::SHORT_COMMIT,
shadow::BUILD_TIME,
shadow::RUST_VERSION,
shadow::RUST_CHANNEL,
build::BRANCH,
build::SHORT_COMMIT,
build::BUILD_TIME,
build::RUST_VERSION,
build::RUST_CHANNEL,
)
}

Expand All @@ -25,21 +26,21 @@ fn main() {
.version(version().as_str())
.get_matches(); //USAGE: ./example_shadow -V

println!("branch:{}", shadow::BRANCH);
println!("commit_id:{}", shadow::COMMIT_HASH);
println!("short_commit:{}", shadow::SHORT_COMMIT);
println!("commit_date:{}", shadow::COMMIT_DATE);
println!("commit_author:{}", shadow::COMMIT_AUTHOR);
println!("commit_email:{}", shadow::COMMIT_EMAIL);
println!("branch:{}", build::BRANCH);
println!("commit_id:{}", build::COMMIT_HASH);
println!("short_commit:{}", build::SHORT_COMMIT);
println!("commit_date:{}", build::COMMIT_DATE);
println!("commit_author:{}", build::COMMIT_AUTHOR);
println!("commit_email:{}", build::COMMIT_EMAIL);

println!("build_os:{}", shadow::BUILD_OS);
println!("rust_version:{}", shadow::RUST_VERSION);
println!("rust_channel:{}", shadow::RUST_CHANNEL);
println!("cargo_version:{}", shadow::CARGO_VERSION);
println!("pkg_version:{}", shadow::PKG_VERSION);
println!("cargo_lock:{}", shadow::CARGO_TREE);
println!("build_os:{}", build::BUILD_OS);
println!("rust_version:{}", build::RUST_VERSION);
println!("rust_channel:{}", build::RUST_CHANNEL);
println!("cargo_version:{}", build::CARGO_VERSION);
println!("pkg_version:{}", build::PKG_VERSION);
println!("cargo_lock:{}", build::CARGO_TREE);

println!("project_name:{}", shadow::PROJECT_NAME);
println!("build_time:{}", shadow::BUILD_TIME);
println!("build_rust_channel:{}", shadow::BUILD_RUST_CHANNEL);
println!("project_name:{}", build::PROJECT_NAME);
println!("build_time:{}", build::BUILD_TIME);
println!("build_rust_channel:{}", build::BUILD_RUST_CHANNEL);
}
71 changes: 46 additions & 25 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,21 @@
//! # Quick Start
//!
//! ## step 1
//! in your `cargo.toml` `packgae` with package add with below config
//! In your `cargo.toml` `packgae` with package add with below config
//!
//! ```toml
//! [package]
//! build = "build.rs"
//!
//! [dependencies]
//! shadow-rs = "0.4"
//!
//! [build-dependencies]
//! shadow-rs = "0.3"
//! shadow-rs = "0.4"
//! ```
//!
//! ## step 2
//! in your project add file `build.rs`,then add with below config
//! In your project add file `build.rs`,then add with below config
//!
//! ```ignore
//! use shadow_rs;
Expand All @@ -63,42 +66,45 @@
//! ```
//!
//! ## step 3
//! in your project find `bin` rust file.
//! It's usually `main.rs`, you can find `[bin]` file with `Cargo.toml`,then add with below config
//! In your project find `bin` rust file.It's usually `main.rs`, you can find `[bin]` file with `Cargo.toml`,then add with below config
//! The `shadow!(build)` with `build` config,add Rust build mod in your project. Also you also use other name that you want configuration.
//!
//! ```ignore
//! pub mod shadow{
//! include!(concat!(env!("OUT_DIR"), "/shadow.rs"));
//! }
//! #[macro_use]
//! extern crate shadow_rs;
//!
//! shadow!(build);
//! ```
//!
//! ## step 4
//! then you can use const that's shadow build it(main.rs).
//! Then you can use const that's shadow build it(main.rs).
//!
//! The `build` mod just we use `shadow!(build)` generated.
//!
//! ```ignore
//! fn main(){
//! println!("{}",shadow::BRANCH); //master
//! println!("{}",shadow::SHORT_COMMIT);//8405e28e
//! println!("{}",shadow::COMMIT_HASH);//8405e28e64080a09525a6cf1b07c22fcaf71a5c5
//! println!("{}",shadow::COMMIT_DATE);//2020-08-16T06:22:24+00:00
//! println!("{}",shadow::COMMIT_AUTHOR);//baoyachi
//! println!("{}",shadow::COMMIT_EMAIL);//xxx@gmail.com
//! 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!("{}",shadow::BUILD_OS);//macos-x86_64
//! println!("{}",shadow::RUST_VERSION);//rustc 1.45.0 (5c1f21c3b 2020-07-13)
//! println!("{}",shadow::RUST_CHANNEL);//stable-x86_64-apple-darwin (default)
//! println!("{}",shadow::CARGO_VERSION);//cargo 1.45.0 (744bd1fbb 2020-06-15)
//! println!("{}",shadow::PKG_VERSION);//0.3.13
//! println!("{}",shadow::CARGO_TREE); //like command:cargo tree
//! 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!("{}",shadow::PROJECT_NAME);//shadow-rs
//! println!("{}",shadow::BUILD_TIME);//2020-08-16 14:50:25
//! println!("{}",shadow::BUILD_RUST_CHANNEL);//debug
//! 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](https://github.com/baoyachi/shadow-rs/blob/master/example_shadow/src/main.rs#L24_L26).
//! And you can also use const with [clap](https://github.com/baoyachi/shadow-rs/blob/master/example_shadow/src/main.rs#L25_L27).
//!
//! For the user guide and futher documentation, please read
//! [The shadow-rs document](https://github.com/baoyachi/shadow-rs).
Expand Down Expand Up @@ -129,6 +135,21 @@ pub use err::{SdResult, ShadowError};

const SHADOW_RS: &str = "shadow.rs";

/// Add a mod in project with `$build_mod`.
///
/// You can use `shadow!(build_shadow)`. Then shadow-rs can help you add a mod with name `build_shadow`.
/// Next, use mod with name `build_shadow`,and also use const like:`build_shadow::BRANCH`.
///
/// Normally, you just config `shadow!(build)`.It looks more concise.
#[macro_export]
macro_rules! shadow {
($build_mod:ident) => {
pub mod $build_mod {
include!(concat!(env!("OUT_DIR"), "/shadow.rs"));
}
};
}

#[derive(Debug)]
pub struct Shadow {
f: File,
Expand Down

0 comments on commit 94c7a9d

Please sign in to comment.