From 0e7b139c7b8883ddd8a327f7df5f2aca5f650207 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Fri, 24 Nov 2023 17:08:47 -0500 Subject: [PATCH] Export ctru version vars via build script `rustc-env` only works for the current crate, but plain keys work for dependent crates via the `DEP_CTRU` keys, which is probably more useful in general. --- ctru-sys/README.md | 15 ++++++++------- ctru-sys/build.rs | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/ctru-sys/README.md b/ctru-sys/README.md index 14febdc..4834895 100644 --- a/ctru-sys/README.md +++ b/ctru-sys/README.md @@ -13,13 +13,14 @@ to use this library. Crate bindings are generated at build time, so the available APIs will depend on the installed version of `libctru` when the crate is built. If you want to check what version of `libctru` is being built, you can examine these environment -variables with [`env!`](https://doc.rust-lang.org/std/macro.env.html): - -* `LIBCTRU_VERSION`: full version string (e.g. `"2.3.1-4"`) -* `LIBCTRU_MAJOR`: major version (e.g. `"2"` for version `2.3.1-4`) -* `LIBCTRU_MINOR`: minor version (e.g. `"3"` for version `2.3.1-4`) -* `LIBCTRU_PATCH`: patch version (e.g. `"1"` for version `2.3.1-4`) -* `LIBCTRU_RELEASE`: release version (e.g. `"4"` for version `2.3.1-4`) +variables from your crate's build script via to its +[`links` variables](https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key): + +* `DEP_CTRU_VERSION`: full version string (e.g. `"2.3.1-4"`) +* `DEP_CTRU_MAJOR_VERSION`: major version (e.g. `"2"` for version `2.3.1-4`) +* `DEP_CTRU_MINOR_VERSION`: minor version (e.g. `"3"` for version `2.3.1-4`) +* `DEP_CTRU_PATCH_VERSION`: patch version (e.g. `"1"` for version `2.3.1-4`) +* `DEP_CTRU_RELEASE`: release version (e.g. `"4"` for version `2.3.1-4`) ## License diff --git a/ctru-sys/build.rs b/ctru-sys/build.rs index a066092..5e71ae0 100644 --- a/ctru-sys/build.rs +++ b/ctru-sys/build.rs @@ -155,15 +155,16 @@ fn detect_and_track_libctru() { match get_libctru_version(&pacman) { Ok((maj, min, patch, rel)) => { - eprintln!("using libctru version {maj}.{min}.{patch}-{rel}"); - - // These are accessible by the crate during build with `env!()`. - // We might consider exporting some public constants or something. - println!("cargo:rustc-env=LIBCTRU_VERSION={maj}.{min}.{patch}-{rel}"); - println!("cargo:rustc-env=LIBCTRU_MAJOR={maj}"); - println!("cargo:rustc-env=LIBCTRU_MINOR={min}"); - println!("cargo:rustc-env=LIBCTRU_PATCH={patch}"); - println!("cargo:rustc-env=LIBCTRU_RELEASE={rel}"); + let version = format!("{maj}.{min}.{patch}-{rel}"); + eprintln!("using libctru version {version}"); + // These are exported as build script output variables, accessible + // via `env::var("DEP_CTRU_")` in other crates' build scripts. + // https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key + println!("cargo:VERSION={version}"); + println!("cargo:MAJOR_VERSION={maj}"); + println!("cargo:MINOR_VERSION={min}"); + println!("cargo:PATCH_VERSION={patch}"); + println!("cargo:RELEASE={rel}"); } Err(err) => println!("cargo:warning=unknown libctru version: {err}"), }