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}"), }