5 个版本
0.2.3 | 2024年7月9日 |
---|---|
0.2.2 | 2024年7月9日 |
0.2.1 | 2024年3月3日 |
0.2.0 | 2024年1月13日 |
0.1.0 | 2023年12月25日 |
10 in #irox
229 每月下载量
在 3 个包(2 直接) 中使用
55KB
1K SLoC
IROX-BUILD-RS
受 shadow-rs 启发的编译时构建元数据注入
快速入门
第1部分:在构建过程中生成元数据
在你的模块中创建一个 build.rs
文件,并包含默认设置
pub fn main() -> Result<(), irox_build_rs::Error> {
println!("cargo:rerun-if-changed=build.rs");
irox_build_rs::generate_module()?;
Ok(())
}
确保你的 Cargo.toml
包含
[build-dependencies]
irox-build-rs = "{latest-version}"
要包含来自 Git 的变量,包含 'git' 功能
[build-dependencies]
irox-build-rs = { version = "{latest-version}", features = ["git"] }
第2部分:包含构建元数据
在你的模块中某个位置,通常是在你的顶级 lib.rs
/main.rs
pub mod build {
include!(concat!(env!("OUT_DIR"), "/builders.rs"));
}
第3部分:使用它们!
fn main() {
println!("{}", build::CARGO_PKG_NAME);
for (name, value) in build::get_ALL_ITEMS() {
println!("{name} => {value}");
}
}
以下生成的常量集合都可在 BTreeMap<&str, &str>
' 中使用
use std::collections::BTreeMap;
fn main() {
let cargo_items: &BTreeMap<&str, &str> = build::get_CARGO_ITEMS();
let rustc_items: &BTreeMap<&str, &str> = build::get_RUSTC_ITEMS();
let git_items: &BTreeMap<&str, &str> = build::get_GIT_ITEMS();
// all_items is the union of all the sets
let all_items: &BTreeMap<&str, &str> = build::get_ALL_ITEMS();
}
生成常量
来自 Cargo
有关详细信息,请参阅Cargo 书籍
pub const CARGO_CFG_TARGET_ARCH: &str = "x86_64";
pub const CARGO_CFG_TARGET_ENDIAN: &str = "little";
pub const CARGO_CFG_TARGET_ENV: &str = "gnu";
pub const CARGO_CFG_TARGET_FAMILY: &str = "windows";
pub const CARGO_CFG_TARGET_FEATURE: &str = "fxsr,sse,sse2";
pub const CARGO_CFG_TARGET_HAS_ATOMIC: &str = "16,32,64,8,ptr";
pub const CARGO_CFG_TARGET_OS: &str = "windows";
pub const CARGO_CFG_TARGET_POINTER_WIDTH: &str = "64";
pub const CARGO_CFG_TARGET_VENDOR: &str = "pc";
pub const CARGO_PKG_AUTHORS: &str = "Sean P. Madden <[email protected]>";
pub const CARGO_PKG_BIN_NAME: &str = "";
pub const CARGO_PKG_CRATE_NAME: &str = "";
pub const CARGO_PKG_DESCRIPTION: &str = "Extras & tweaks for the egui framework";
pub const CARGO_PKG_HOMEPAGE: &str = "https://github.com/spmadden/irox";
pub const CARGO_PKG_LICENSE: &str = "MIT OR Apache-2.0";
pub const CARGO_PKG_LICENSE_FILE: &str = "";
pub const CARGO_PKG_NAME: &str = "irox-egui-extras";
pub const CARGO_PKG_README: &str = "README.md";
pub const CARGO_PKG_REPOSITORY: &str = "https://github.com/spmadden/irox";
pub const CARGO_PKG_RUST_VERSION: &str = "";
pub const CARGO_PKG_VERSION: &str = "0.3.5";
pub const CARGO_PKG_VERSION_MAJOR: &str = "0";
pub const CARGO_PKG_VERSION_MINOR: &str = "3";
pub const CARGO_PKG_VERSION_PATCH: &str = "5";
pub const CARGO_PKG_VERSION_PRE: &str = "";
pub const CARGO_PRIMARY_PACKAGE: &str = "";
来自 Cargo,针对 Rustc
有关详细信息,请参阅Cargo 书籍
pub const DEBUG: &str = "true"; // "true"
pub const HOST: &str = "x86_64-pc-windows-gnu";
pub const OPT_LEVEL: &str = "0";
pub const PROCESSOR_ARCHITECTURE: &str = "AMD64";
pub const PROCESSOR_IDENTIFIER: &str = "AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD";
pub const PROCESSOR_LEVEL: &str = "23";
pub const PROCESSOR_REVISION: &str = "7100";
pub const PROFILE: &str = "debug";
pub const RUSTUP_TOOLCHAIN: &str = "1.74-x86_64-pc-windows-gnu";
pub const TARGET: &str = "x86_64-pc-windows-gnu";
来自 Git,具有 'git' 功能
pub const GIT_COMMIT_AUTHOR: &str = "user.name <user.email>";
pub const GIT_COMMIT_DATETIME: &str = "2023-11-09T04:07:06Z"; // ISO8601 UTC date-time from the commit timestamp
pub const GIT_COMMIT_FULLHASH: &str = "6a22a45109c9f8ab27971c8919d693bd995f0a16"; // Full hash of the current HEAD
pub const GIT_COMMIT_SHORTHASH: &str = "6a22a45"; // Short hash of the current HEAD
pub const GIT_COMMIT_TIMESTAMP_SECS: i64 = 1699502826; // Unix timestamp in UTC of the HEAD commit
pub const GIT_COMMIT_TZ_OFFSET_SECS: i64 = -18000; // Timezone Offset (seconds) from UTC of the HEAD commit
pub const GIT_DESCRIBE: &str = "irox-build-rs-g2c9c199-dirty"; // <module-name>-g<module-short-hash><-dirty>
pub const GIT_IS_CLEAN: bool = false; // true if `git status` reports clean
依赖关系
~0–2MB
~53K SLoC