Corrosion is an MIT-licensed CMake package that imports Rust executables, static libraries, and dynamic libraries into an existing CMake build from a Cargo workspace or package manifest, and it is aimed at C and C++ teams that already build with CMake and want to add Rust code without replacing their build system.
What it is
Corrosion, formerly known as cmake-cargo, is a tool for integrating Rust into an existing CMake project. It lives in the CMake ecosystem, at the boundary between CMake and Cargo, and it automatically imports executables, static libraries, and dynamic libraries from a workspace or package manifest, meaning a Cargo.toml file. It is distributed under the MIT licence, so it can be vendored or installed without a commercial agreement.
The concrete problem it solves is the glue code that a mixed Rust and C/C++ project otherwise needs by hand. Without Corrosion, a CMake build must locate Cargo, invoke it through custom commands and custom targets, then locate the produced artifacts by hand and wire them into target_link_libraries calls, while also coping with multi-configuration output directories and cross-compilation toolchains. Corrosion replaces that hand-written plumbing with a single import call that reads the manifest and produces ordinary CMake targets that can be consumed and linked like any other target in the tree.
Key capabilities
- Automatic import of executables, static libraries, and shared libraries from a Rust crate, so Rust artifacts become first-class CMake targets.
corrosion_import_crate(MANIFEST_PATH rust-lib/Cargo.toml) reads a package or workspace manifest and creates those targets in one call.
- Linking in tree through standard CMake, as in
target_link_libraries(your_cpp_bin PUBLIC rust-lib).
- Multi-config generator support, so generated Debug and Release configurations are both handled rather than collapsed to a single build type.
- Simple cross-compilation, so the same project can target non-host toolchains.
- Easy installation of Rust executables as part of a CMake install step.
- Several integration routes: the CMake
FetchContent module, installing Corrosion, or adding it as a subdirectory.
Who uses it and how
- C and C++ projects that already have a working CMake build and want to add a Rust crate as a static or shared library without duplicating the build logic.
- Teams that vendor Corrosion through
FetchContent_Declare pinned to a version tag such as v0.6, a commit hash, or a branch.
- Projects that build through multi-config generators and need both Debug and Release variants of the imported Rust targets.
- Projects that cross-compile and want the Rust portion built for the same target platform as the C/C++ portion.
- Workspaces containing several crates, where the manifest is read once and the individual binaries and libraries are exposed as separate targets.
Getting started
The documented route is CMake FetchContent: declare Corrosion with GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git and a GIT_TAG such as v0.6, then call FetchContent_MakeAvailable(Corrosion) and import the crate with corrosion_import_crate(MANIFEST_PATH rust-lib/Cargo.toml). Installing Corrosion or adding it as a subdirectory is covered in the setup chapter of the documentation; the v0.6 release requires CMake 3.22 or newer, and Rust 1.46 or newer, with some platforms needing a more recent Rust version.
How it compares
No comparable products are listed in the facts for this entry, so Corrosion stands alone in this registry. Its distinguishing position is narrow by design: it does not try to be a general build system, it targets the CMake side of the CMake–Cargo boundary.
When to use it — and when not to
A self-hoster must operate a Rust toolchain alongside CMake, keep the toolchain and cargo registry access working in continuous integration, and accept the version floor of CMake 3.22 for the v0.6 release. It is the wrong choice for a project that does not already build with CMake, or one pinned below CMake 3.15, since the v0.5 line receives critical backports only and newer features may require more recent CMake. The README excerpt is short and defers most detail to the external documentation site, and the repository carries a nontrivial open issue count, so teams should budget time for reading the setup chapter rather than assuming the front page is sufficient.