Skip to content
No description, website, or topics provided.
C++ CMake Shell Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
deps
sourmash @ e5658b1
src
.gitignore
.gitmodules
CMakeLists.txt
Makefile
README.md
clean.sh

README.md

Compiling a C++ Program with a Statically-Linked Rust Library Using CMake

This is based on https://github.com/AndrewGaspar/cmake_including_rust but using sourmash as an example.

Project Set-Up

This is an test case for adding Rust to a C++ project that is currently being compiled using CMake, through the ExternalProject module. It's desired to have this library be statically linked (using a *.a file) vs. dynamically-linked (using a .so file).

Clone with submodules:

$ git clone https://github.com/luizirber/sourmash_cpp
$ cd sourmash_cpp
$ git submodule update --init --remote --recursive

The project can be built by doing the following:

$ mkdir -p _build 
$ cd _build 
$ cmake ..
$ make

The set-up is currently the following:

    .
    ├── CMakeLists.txt
    ├── README.md
    ├── sourmash
    │   ├── include
    │   │   └── kmer_min_hash.hh
    │   ├── Cargo.toml
    │   └── src
    │       └── ...
    └── src
        └── main.cpp

The Rust library is compiled using cargo build through the ExternalProject module in CMake.

The Cargo.toml file for that project specifies that both a static and dynamic library should be built, by specifying crate-type = ["staticlib","cdylib"] under [lib].

Links from the original repo

Reddit thread about this:

Rust Embedded's "A little Rust with your C":

A project using CMake and Rust to run Rust on a BBC micro:bit (search for ExternalProject):

You can’t perform that action at this time.