Crate chksum_build

Crate chksum_build 

Source
Expand description

Tiny library for setting/getting build-time values for your crate.

§Setup

§Create build.rs

Create new file build.rs at the top level of your crate (next to Cargo.toml).

use chksum_build::{BuildScript, Result};

fn main() -> Result<()> {
    BuildScript::default().setup()
}

Optionally you can use along with anyhow.

use anyhow::Result;
use chksum_build::{setup, BuildScript};

fn main() -> Result<()> {
    setup(&BuildScript::default())
}

§Update Cargo.toml

§Modify package section

[package]
# ...
build = "build.rs"

§Modify build-dependencies section

You can update Cargo.toml on your own.

[build-dependencies]
# ...
chksum-build = "0.0.3"

Or use cargo add subcommand.

cargo add --build chksum-build

§Modify dependencies section

As in the example above you can add entry manually.

[dependencies]
# ...
chksum-build = "0.0.3"

Or by using subcommand.

cargo add chksum-build

§Usage

§build_info macro

build_info macro creates BuildInfo.

use chksum_build::build_info;

let build_info = build_info!();

§env or option_env macros

env or option_env macros.

Notice: Type conversion need to be done manually.

use std::str::FromStr;
use chksum_build::cargo::Profile;

// ...

let profile = env!("CHKSUM_BUILD_INFO_CARGO_PROFILE");
let profile = Profile::from_str(profile)?;

// or

let profile = option_env!("CHKSUM_BUILD_INFO_CARGO_PROFILE")
                .map(Profile::from_str)
                .transpose()?;

§cfg or cfg_attr options

Some variables are available as configuration options for cfg or cfg_attr.

§Profile variants

Check Profile for more details.

#[cfg(debug)]
fn debug_function() {
    // ...
}

#[cfg_attr(release, inline)]
fn inline_when_release_function() {
    // ...
}

§Channel variants

Check Channel for more details.

#[cfg(stable)]
fn stable_function() {
    // ...
}

#[cfg(nightly)]
fn nightly_function() {
    // ...
}

#[cfg_attr(nightly, optimize(size))]
fn optimize_when_nightly_function() {
    // ...
}

§Feature flags

  • info: Enables items required by library or application.
  • script: Enables items required by build script.

By default both of them are enabled.

§Alternatives

§License

MIT

Macros§

build_info
Creates a BuildInfo from environment variables.

Structs§

Buildinfo
Contains informations about build.
BuildInfoinfo
Contains values set by build script.
BuildScriptscript
Configuration for build script.
Cargoinfo
Contains informations about Cargo.
Rustinfo
Contains informations about Rust.

Enums§

Channel
A rustup channel.
ChannelVersion
A rustup channel’s version.
Error
A common error type for the current crate.
Profile
A Cargo profile.

Functions§

setupscript
Wraps BuildScript::setup to return anyhow::Result instead of Result.

Type Aliases§

Result
Type alias for Result with an error type of Error.