From 4b10302ec238410854256a1a48fa4ad45c910f7e Mon Sep 17 00:00:00 2001 From: Lukas Lueg Date: Sun, 9 Feb 2025 17:07:58 +0100 Subject: [PATCH] Add semver_check internal crate --- .github/workflows/check.yml | 8 +++++ example_project/Cargo.toml | 1 + semver_check/.gitignore | 2 ++ semver_check/Cargo.toml | 10 ++++++ semver_check/build.rs | 3 ++ semver_check/src/lib.rs | 66 +++++++++++++++++++++++++++++++++++++ 6 files changed, 90 insertions(+) create mode 100644 semver_check/.gitignore create mode 100644 semver_check/Cargo.toml create mode 100644 semver_check/build.rs create mode 100644 semver_check/src/lib.rs diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 5bb4018029..e94e206d26 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -29,6 +29,14 @@ jobs: - run: cargo check --all-features - run: cargo check --manifest-path=example_project/Cargo.toml + semver_crate: + name: cargo check of internal crate + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - run: cargo check --manifest-path=semver_check/Cargo.toml + clippy: name: cargo clippy runs-on: ubuntu-latest diff --git a/example_project/Cargo.toml b/example_project/Cargo.toml index 5363f3b0ca..0c4c389bc7 100644 --- a/example_project/Cargo.toml +++ b/example_project/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Lukas Lueg "] build = "build.rs" edition = "2021" +publish = false [dependencies] built = { version = "0.7", path="../", features = ["chrono", "semver"] } diff --git a/semver_check/.gitignore b/semver_check/.gitignore new file mode 100644 index 0000000000..4fffb2f89c --- /dev/null +++ b/semver_check/.gitignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/semver_check/Cargo.toml b/semver_check/Cargo.toml new file mode 100644 index 0000000000..45217cca07 --- /dev/null +++ b/semver_check/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "semver_check" +version = "0.1.0" +authors = ["Lukas Lueg "] +build = "build.rs" +edition = "2021" +publish = false + +[build-dependencies] +built = { version = "0.7", path="../", features = ["cargo-lock", "dependency-tree", "git2", "chrono", "semver"] } diff --git a/semver_check/build.rs b/semver_check/build.rs new file mode 100644 index 0000000000..d8f91cb913 --- /dev/null +++ b/semver_check/build.rs @@ -0,0 +1,3 @@ +fn main() { + built::write_built_file().expect("Failed to acquire build-time information"); +} diff --git a/semver_check/src/lib.rs b/semver_check/src/lib.rs new file mode 100644 index 0000000000..7a6a992551 --- /dev/null +++ b/semver_check/src/lib.rs @@ -0,0 +1,66 @@ +//! Internal crate to provide semver-checks on generated code. +//! +//! This ensures that the code *generated* by `built` does not semver-break +//! downstream crates. +//! All we do here is to assign/use items generated by `built` in a way that +//! was documented on the last semver-compatible version. +//! If `built` breaks this crate, it always breaks downstream crates. If updating +//! this crate is required, and this crate semver-breaks, `built` breaks downstream +//! crates as well. Both cases require a semver-bump of `built`. + +mod built_info { + include!(concat!(env!("OUT_DIR"), "/built.rs")); +} + +pub const CI_PLATFORM: Option<&str> = built_info::CI_PLATFORM; +pub const PKG_VERSION: &str = built_info::PKG_VERSION; +pub const PKG_VERSION_MAJOR: &str = built_info::PKG_VERSION_MAJOR; +pub const PKG_VERSION_MINOR: &str = built_info::PKG_VERSION_MINOR; +pub const PKG_VERSION_PATCH: &str = built_info::PKG_VERSION_PATCH; +pub const PKG_VERSION_PRE: &str = built_info::PKG_VERSION_PRE; +pub const PKG_AUTHORS: &str = built_info::PKG_AUTHORS; +pub const PKG_NAME: &str = built_info::PKG_NAME; +pub const PKG_DESCRIPTION: &str = built_info::PKG_DESCRIPTION; +pub const PKG_HOMEPAGE: &str = built_info::PKG_HOMEPAGE; +pub const PKG_LICENSE: &str = built_info::PKG_LICENSE; +pub const PKG_REPOSITORY: &str = built_info::PKG_REPOSITORY; +pub const TARGET: &str = built_info::TARGET; +pub const HOST: &str = built_info::HOST; +pub const PROFILE: &str = built_info::PROFILE; +pub const RUSTC: &str = built_info::RUSTC; +pub const RUSTDOC: &str = built_info::RUSTDOC; +pub const RUSTC_VERSION: &str = built_info::RUSTC_VERSION; +pub const RUSTDOC_VERSION: &str = built_info::RUSTDOC_VERSION; +pub const OPT_LEVEL: &str = built_info::OPT_LEVEL; +pub const NUM_JOBS: u32 = built_info::NUM_JOBS; +pub const DEBUG: bool = built_info::DEBUG; +pub const FEATURES: &[&str] = &built_info::FEATURES; +pub const FEATURES_STR: &str = built_info::FEATURES_STR; +pub const FEATURES_LOWERCASE: &[&str] = &built_info::FEATURES_LOWERCASE; +pub const FEATURES_LOWERCASE_STR: &str = built_info::FEATURES_LOWERCASE_STR; +pub const CFG_TARGET_ARCH: &str = built_info::CFG_TARGET_ARCH; +pub const CFG_ENDIAN: &str = built_info::CFG_ENDIAN; +pub const CFG_ENV: &str = built_info::CFG_ENV; +pub const CFG_FAMILY: &str = built_info::CFG_FAMILY; +pub const CFG_OS: &str = built_info::CFG_OS; +pub const CFG_POINTER_WIDTH: &str = built_info::CFG_POINTER_WIDTH; + +// cargo-lock +pub const DEPENDENCIES: &[(&str, &str)] = &built_info::DEPENDENCIES; +pub const DEPENDENCIES_STR: &str = built_info::DEPENDENCIES_STR; + +// dependency-tree +pub const DIRECT_DEPENDENCIES: &[(&str, &str)] = &built_info::DIRECT_DEPENDENCIES; +pub const DIRECT_DEPENDENCIES_STR: &str = built_info::DIRECT_DEPENDENCIES_STR; +pub const INDIRECT_DEPENDENCIES: &[(&str, &str)] = &built_info::INDIRECT_DEPENDENCIES; +pub const INDIRECT_DEPENDENCIES_STR: &str = built_info::INDIRECT_DEPENDENCIES_STR; + +// git2 +pub const GIT_VERSION: Option<&str> = built_info::GIT_VERSION; +pub const GIT_DIRTY: Option = built_info::GIT_DIRTY; +pub const GIT_HEAD_REF: Option<&str> = built_info::GIT_HEAD_REF; +pub const GIT_COMMIT_HASH: Option<&str> = built_info::GIT_COMMIT_HASH; +pub const GIT_COMMIT_HASH_SHORT: Option<&str> = built_info::GIT_COMMIT_HASH_SHORT; + +// chrono +pub const BUILT_TIME_UTC: &str = built_info::BUILT_TIME_UTC;