Browse Source

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.
pull/141/head
Ian Chamberlain 1 year ago
parent
commit
0e7b139c7b
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 15
      ctru-sys/README.md
  2. 19
      ctru-sys/build.rs

15
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 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 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 what version of `libctru` is being built, you can examine these environment
variables with [`env!`](https://doc.rust-lang.org/std/macro.env.html): 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):
* `LIBCTRU_VERSION`: full version string (e.g. `"2.3.1-4"`)
* `LIBCTRU_MAJOR`: major version (e.g. `"2"` for version `2.3.1-4`) * `DEP_CTRU_VERSION`: full version string (e.g. `"2.3.1-4"`)
* `LIBCTRU_MINOR`: minor version (e.g. `"3"` for version `2.3.1-4`) * `DEP_CTRU_MAJOR_VERSION`: major version (e.g. `"2"` for version `2.3.1-4`)
* `LIBCTRU_PATCH`: patch version (e.g. `"1"` for version `2.3.1-4`) * `DEP_CTRU_MINOR_VERSION`: minor version (e.g. `"3"` for version `2.3.1-4`)
* `LIBCTRU_RELEASE`: release version (e.g. `"4"` 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 ## License

19
ctru-sys/build.rs

@ -155,15 +155,16 @@ fn detect_and_track_libctru() {
match get_libctru_version(&pacman) { match get_libctru_version(&pacman) {
Ok((maj, min, patch, rel)) => { Ok((maj, min, patch, rel)) => {
eprintln!("using libctru version {maj}.{min}.{patch}-{rel}"); let version = format!("{maj}.{min}.{patch}-{rel}");
eprintln!("using libctru version {version}");
// These are accessible by the crate during build with `env!()`. // These are exported as build script output variables, accessible
// We might consider exporting some public constants or something. // via `env::var("DEP_CTRU_<key>")` in other crates' build scripts.
println!("cargo:rustc-env=LIBCTRU_VERSION={maj}.{min}.{patch}-{rel}"); // https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key
println!("cargo:rustc-env=LIBCTRU_MAJOR={maj}"); println!("cargo:VERSION={version}");
println!("cargo:rustc-env=LIBCTRU_MINOR={min}"); println!("cargo:MAJOR_VERSION={maj}");
println!("cargo:rustc-env=LIBCTRU_PATCH={patch}"); println!("cargo:MINOR_VERSION={min}");
println!("cargo:rustc-env=LIBCTRU_RELEASE={rel}"); println!("cargo:PATCH_VERSION={patch}");
println!("cargo:RELEASE={rel}");
} }
Err(err) => println!("cargo:warning=unknown libctru version: {err}"), Err(err) => println!("cargo:warning=unknown libctru version: {err}"),
} }

Loading…
Cancel
Save