#build-script #build #static #const #compile-time #no-std

no-std build build_const

从 build.rs 或脚本中创建可导入常量的库

5 个版本

使用旧的 Rust 2015

0.2.2 2021 年 4 月 20 日
0.2.1 2018 年 4 月 13 日
0.2.0 2017 年 5 月 31 日
0.1.1 2017 年 5 月 30 日
0.1.0 2017 年 5 月 29 日

#100 in 构建工具

Download history 48825/week @ 2024-03-14 54682/week @ 2024-03-21 48017/week @ 2024-03-28 46402/week @ 2024-04-04 46788/week @ 2024-04-11 54258/week @ 2024-04-18 53443/week @ 2024-04-25 48534/week @ 2024-05-02 46195/week @ 2024-05-09 58320/week @ 2024-05-16 55405/week @ 2024-05-23 64048/week @ 2024-05-30 50182/week @ 2024-06-06 51452/week @ 2024-06-13 52302/week @ 2024-06-20 41059/week @ 2024-06-27

208,397 个月下载量
用于 261 个 crate(2 个直接使用)

MIT 许可证

12KB
139

build_const:创建构建脚本中的常量的 crate

Rust 库,用于从 build.rs 或脚本中创建可导入的常量

请参阅 crate 文档crates.io 上的 crate


lib.rs:

build_const:创建构建脚本中的常量的 crate

build_const crate 的存在是为了帮助在编译时或在生成脚本中创建 rust 常量文件。它非常简单轻量,使得常量创建变得简单。

推荐用法:在开发过程中,在 build.rs 中创建您的常量。一旦您的常量相当稳定,请创建一个脚本,并将常量文件生成在一个单独的文件中,或是一个外部 crate,您可以将它作为依赖项引入。

示例

在您的 Cargo.toml 文件中包含 build_const = VERSION。对于 no_std 支持(仅宏)使用 default-features = false

请参阅 ConstWriter 了解如何在 build.rs 或脚本中使用。要导入在 build.rs 中创建的 "constants.rs" 文件,请使用

#[macro_use]
extern crate build_const;

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

对于在脚本中写入常量,还提供了宏 src_file!

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

无运行时依赖

功能