Changes since v0.2.2
Breaking
- The minimum supported rust version (MSRV) was increased to 1.46, due to a cargo issue that recently
surfaced on CI when using crates.io. Please also note that on MacOS 12 at least Rust 1.54 is required. - MacOS 10 and 11 are no longer officially supported and untested in CI.
- Increase the minimum required CMake version to 3.15.
- Corrosion internally invokes
cargo build. When passing arguments tocargo build, Corrosion
now uses the CMakeVERBATIMoption. This may require you to change how you quote
parameters passed to corrosion (e.g. viacorrosion_add_target_rustflags()).
For example setting acfgoption previously required double escaping the rustflag like this
"--cfg=something=\\\"value\\\"", but now it should be passed to corrosion without any escapes:
--cfg=something="value".
Breaking: Removed previously deprecated functionality
- Removed
add_crate()function. Usecorrosio_import_crateinstead. - Removed
cargo_link_libraries()function. Usecorrosion_link_libraries()instead. - Removed experimental CMake option
CORROSION_EXPERIMENTAL_PARSER. This option was never included in an official
release and has been marked as deprecated on the master branch since May 22.
The corresponding stable option isCORROSION_NATIVE_TOOLINGalbeit with inverted semantics. - Previously Corrosion would set the
HOST_CCandHOST_CXXenvironment variables when invoking
cargo build, if the environment variablesCCandCXXoutside of CMake where set.
However this did not work as expected in all cases and sometimes theHOST_CCvariable would be set
to a cross-compiler for unknown reasons. For this reasonHOST_CCandHOST_CXXare not set by
corrosion anymore, but users can still set them manually if required viacorrosion_set_env_vars(). - The
CARGO_RUST_FLAGSfamily of cache variables were removed. Corrosion does not internally use them
anymore.
Potentially breaking
- The working directory when invoking
cargo buildwas changed to the directory of the Manifest
file. This now allows cargo to pick up.cargo/config.tomlfiles located in the source tree.
(205) - Adding a
PRE_BUILDcustom command on acargo-build_<target_name>CMake target will no
longer work as expected. To support executing user defined commands before cargo build is
invoked users should use the newly added targetscargo-prebuild(before all cargo build invocations)
orcargo-prebuild_<target_name>as a dependency target.
Example:add_dependencies(cargo-prebuild code_generator_target)
New features
- Support setting rustflags for only the main target and none of it's dependencies (215).
A new functioncorrosion_add_target_local_rustflags(target_name rustc_flag [more_flags ...])
is added for this purpose.
This is useful in cases where you only need rustflags on the main-crate, but need to set different
flags for different targets. Without "local" Rustflags this would require rebuilds of the
dependencies when switching targets. - Support explicitly selecting a linker (208).
The linker can be selected viacorrosion_set_linker(target_name linker).
Please note that this only has an effect for targets, where the final linker invocation is done
by cargo, i.e. targets where foreign code is linked into rust code and not the other way around. - Corrosion now respects the CMake OUTPUT_DIRECTORY target properties and copies build artifacts to the expected
locations (217), if the properties are set.
This feature requires at least CMake 3.19 and is enabled by default if supported. Please note that theOUTPUT_NAME
target properties are currently not supported.
Specifically, the following target properties are now respected: - Corrosion now supports packages with potentially multiple binaries (bins) and a library (lib) at the
same time. The only requirement is that the names of allbins andlibs in the whole project must be unique.
Users can set the names in theCargo.tomlby addingname = <unique_name>in the[[bin]]and[lib]tables. - FindRust now has improved support for the
VERSIONoption offind_packageand will now attempt to find a matching
toolchain version. Previously it was only checked if the default toolchain matched to required version. - For rustup managed toolchains a CMake error is issued with a helpful message if the required target for
the selected toolchain is not installed.
Fixes
- Fix a CMake developer Warning when a Multi-Config Generator and Rust executable targets
(#213). - FindRust now respects the
QUIEToption tofind_package()in most cases.
Deprecation notice
- Support for the MSVC Generators with CMake toolchains before 3.20 is deprecated and will be removed in the next
release (v0.4). All other Multi-config Generators already require CMake 3.20.
Internal Changes
- The CMake Generator written in Rust and
CorrosionGenerator.cmakewhich are responsible for parsing
cargo metadataoutput to create corresponding CMake targets for all Rust targets now share most code.
This greatly simplified the CMake generator written in Rust and makes it much easier maintaining and adding
new features regardless of howcargo metadatais parsed.