#build-script #const #build #static #build-time #compile-time #embedded

no-std build build_const

library for creating importable constants from build.rs or a script

5 releases

Uses old Rust 2015

0.2.2 Apr 20, 2021
0.2.1 Apr 13, 2018
0.2.0 May 31, 2017
0.1.1 May 30, 2017
0.1.0 May 29, 2017

#134 in Build Utils

Download history 49947/week @ 2024-06-15 54603/week @ 2024-06-22 45410/week @ 2024-06-29 46964/week @ 2024-07-06 56621/week @ 2024-07-13 58107/week @ 2024-07-20 50935/week @ 2024-07-27 48765/week @ 2024-08-03 46516/week @ 2024-08-10 46029/week @ 2024-08-17 46552/week @ 2024-08-24 46337/week @ 2024-08-31 44692/week @ 2024-09-07 44135/week @ 2024-09-14 50056/week @ 2024-09-21 35461/week @ 2024-09-28

184,491 downloads per month
Used in 260 crates (2 directly)

MIT license

12KB
139 lines

build_const: crate for creating constants in your build script

Rust library for creating importable constants from build.rs or a script

See the crate documentation and the crate on crates.io


lib.rs:

build_const: crate for creating constants in your build script

The build_const crate exists to help create rust constant files at compile time or in a generating script. It is ultra simple and lightweight, making constant creation a simple matter.

Recommended use: when developing make your constants in build.rs. Once your constants are fairly stable create a script instead and have your constants file be generated in either a single file or an external crate that you can bring in as a dependency.

Example

Include build_const = VERSION in your Cargo.toml file. For no_std support (macros only) use default-features = false.

See ConstWriter for how to use in a build.rs or script. To then import a "constants.rs" file created in build.rs use:

#[macro_use]
extern crate build_const;

build_const!("constants");
println!("VALUE: {}", VALUE);
println!("VALUE: {}", ARRAY);

For writing constants in a script, the macro src_file! is also provided.

// will write files to `/src/constants.rs`
let mut consts = ConstWriter::from_path(&Path::from(src_file!("constants.rs"))).unwrap();
// ... use consts

No runtime deps

Features