tools/corrosion/README.md
author unC0Rr
Wed, 04 Sep 2024 14:54:34 +0200
branchtransitional_engine
changeset 16031 1b1d5729ff3e
parent 16021 6a3dc15b78b9
child 16038 d903f8d2395a
permissions -rw-r--r--
Fix test to match new yaml structure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     1
# Corrosion
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     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)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     3
[![Documentation](https://img.shields.io/badge/docs-latest-blue.svg)](https://corrosion-rs.github.io/corrosion/)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     4
![License](https://img.shields.io/badge/license-MIT-blue)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     5
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     6
Corrosion, formerly known as cmake-cargo, is a tool for integrating Rust into an existing CMake
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     7
project. Corrosion can automatically import executables, static libraries, and dynamic libraries
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     8
from a workspace or package manifest (`Cargo.toml` file).
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     9
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    10
## Features
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    11
- Automatic Import of Executable, Static, and Shared Libraries from Rust Crate
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    12
- Easy Installation of Rust Executables
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    13
- Trivially Link Rust Executables to C/C++ Libraries in Tree
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    14
- Multi-Config Generator Support
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    15
- Simple Cross-Compilation
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    16
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    17
## Sample Usage with FetchContent
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    18
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    19
Using the CMake `FetchContent` module allows you to easily integrate corrosion into your build.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    20
Other methods including installing corrosion or adding it as a subdirectory are covered in the
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    21
[setup chapter](https://corrosion-rs.github.io/corrosion/setup_corrosion.html) of the 
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    22
corrosion [documentation](https://corrosion-rs.github.io/corrosion/).
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    23
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    24
```cmake
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    25
include(FetchContent)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    26
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    27
FetchContent_Declare(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    28
    Corrosion
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    29
    GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    30
    GIT_TAG v0.5 # Optionally specify a commit hash, version tag or branch here
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    31
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    32
FetchContent_MakeAvailable(Corrosion)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    33
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    34
# Import targets defined in a package or workspace manifest `Cargo.toml` file
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    35
corrosion_import_crate(MANIFEST_PATH rust-lib/Cargo.toml)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    36
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    37
add_executable(your_cpp_bin main.cpp)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    38
target_link_libraries(your_cpp_bin PUBLIC rust-lib)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    39
```
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    40