16050
|
1 |
# Corrosion
|
|
2 |
[![Build Status](https://github.com/corrosion-rs/corrosion/actions/workflows/test.yaml/badge.svg)](https://github.com/corrosion-rs/corrosion/actions?query=branch%3Amaster)
|
|
3 |
[![Documentation](https://img.shields.io/badge/docs-latest-blue.svg)](https://corrosion-rs.github.io/corrosion/)
|
|
4 |
![License](https://img.shields.io/badge/license-MIT-blue)
|
|
5 |
|
|
6 |
Corrosion, formerly known as cmake-cargo, is a tool for integrating Rust into an existing CMake
|
|
7 |
project. Corrosion can automatically import executables, static libraries, and dynamic libraries
|
|
8 |
from a workspace or package manifest (`Cargo.toml` file).
|
|
9 |
|
|
10 |
## Features
|
|
11 |
- Automatic Import of Executable, Static, and Shared Libraries from Rust Crate
|
|
12 |
- Easy Installation of Rust Executables
|
|
13 |
- Trivially Link Rust Executables to C/C++ Libraries in Tree
|
|
14 |
- Multi-Config Generator Support
|
|
15 |
- Simple Cross-Compilation
|
|
16 |
|
|
17 |
## Sample Usage with FetchContent
|
|
18 |
|
|
19 |
Using the CMake `FetchContent` module allows you to easily integrate corrosion into your build.
|
|
20 |
Other methods including installing corrosion or adding it as a subdirectory are covered in the
|
|
21 |
[setup chapter](https://corrosion-rs.github.io/corrosion/setup_corrosion.html) of the
|
|
22 |
corrosion [documentation](https://corrosion-rs.github.io/corrosion/).
|
|
23 |
|
|
24 |
```cmake
|
|
25 |
include(FetchContent)
|
|
26 |
|
|
27 |
FetchContent_Declare(
|
|
28 |
Corrosion
|
|
29 |
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
|
|
30 |
GIT_TAG v0.5 # Optionally specify a commit hash, version tag or branch here
|
|
31 |
)
|
|
32 |
FetchContent_MakeAvailable(Corrosion)
|
|
33 |
|
|
34 |
# Import targets defined in a package or workspace manifest `Cargo.toml` file
|
|
35 |
corrosion_import_crate(MANIFEST_PATH rust-lib/Cargo.toml)
|
|
36 |
|
|
37 |
add_executable(your_cpp_bin main.cpp)
|
|
38 |
target_link_libraries(your_cpp_bin PUBLIC rust-lib)
|
|
39 |
```
|
|
40 |
|
16067
|
41 |
## Requirements
|
|
42 |
|
|
43 |
### Stable v0.5 Release
|
|
44 |
|
|
45 |
- CMake 3.15 or newer. Some features may only be available on more recent CMake versions
|
|
46 |
- Rust 1.46 or newer. Some platforms / features may require more recent Rust versions
|
|
47 |
|
|
48 |
### Development (master branch)
|
|
49 |
|
|
50 |
- CMake 3.22 or newer
|