Skip to content

Commit

Permalink
Document version related variables
Browse files Browse the repository at this point in the history
Conditionally enabling some code depending on the rust version is pretty
 common, so it makes sense to document these variables.

Signed-off-by: Jonathan Schwender <[email protected]>
  • Loading branch information
jschwe committed Jan 7, 2022
1 parent 28730cc commit 81213a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@ The pairs can also be generator expressions, as they will be evaluated using $<G
For example this may be useful if the build scripts of crates look for environment variables.
This feature requires CMake >= 3.19.0.

#### Information provided by Corrosion

For your convenience, Corrosion sets a number of variables which contain information about the version of the rust
toolchain. You can use the CMake version comparison operators
(e.g. [`VERSION_GREATER_EQUAL`](https://cmake.org/cmake/help/latest/command/if.html#version-comparisons)) on the main
variable (e.g. `if(Rust_VERSION VERSION_GREATER_EQUAL "1.57.0")`), or you can inspect the major, minor and patch
versions individually.
- `Rust_VERSION<_MAJOR|_MINOR|_PATCH>` - The version of rustc.
- `Rust_CARGO_VERSION<_MAJOR|_MINOR|_PATCH>` - The cargo version.
- `Rust_LLVM_VERSION<_MAJOR|_MINOR|_PATCH>` - The LLVM version used by rustc.
- `Rust_IS_NIGHTLY` - 1 if a nightly toolchain is used, otherwise 0. Useful for selecting an unstable feature for a
crate, that is only available on nightly toolchains.

### Cargo feature selection

Cargo crates sometimes offer features, which traditionally can be specified with `cargo build` on the
command line as opt-in. You can select the features to enable with the `FEATURES` argument when
calling `corrosion_import_crate`. The following example enables the "chocolate" and "vanilla"
Expand All @@ -172,6 +187,7 @@ parameters for `corrosion_import_crate` called `ALL_FEATURES` and `NO_DEFAULT_FE
boolean target properties - which override any specified values with `corrosion_import_crate` are called
`CORROSION_ALL_FEATURES` and `CORROSION_NO_DEFAULT_FEATURES`.


### Developer/Maintainer Options
These options are not used in the course of normal Corrosion usage, but are used to configure how
Corrosion is built and installed. Only applies to Corrosion builds and subdirectory uses.
Expand Down
4 changes: 2 additions & 2 deletions cmake/FindRust.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ if (_RESOLVE_RUSTUP_TOOLCHAINS)
set(_TOOLCHAIN_OVERRIDE ${_TOOLCHAIN})
endif()
else()
message(WARNING "Didn't reconize toolchain: ${_TOOLCHAIN_RAW}")
message(WARNING "Didn't recognize toolchain: ${_TOOLCHAIN_RAW}")
endif()
endforeach()

Expand Down Expand Up @@ -158,7 +158,7 @@ if (_RESOLVE_RUSTUP_TOOLCHAINS)
message(VERBOSE "Rust toolchain ${_RUSTUP_TOOLCHAIN_FULL}")
message(VERBOSE "Rust toolchain path ${_RUST_TOOLCHAIN_PATH}")

# Is overrided if the user specifies `Rust_COMPILER` explicitly.
# Is overridden if the user specifies `Rust_COMPILER` explicitly.
find_program(
Rust_COMPILER_CACHED
rustc
Expand Down

0 comments on commit 81213a0

Please sign in to comment.