Creating a new crate

First, if you havenโ€™t done so already, create a new crate within your project directory using cargo new --lib. It is recommended that the crate root is a sibling of the other native build folders for ease of config, e.g.:

โ”œโ”€โ”€ android
โ”œโ”€โ”€ ios
โ”œโ”€โ”€ lib
โ”œโ”€โ”€ linux
โ”œโ”€โ”€ macos
โ”œโ”€โ”€ $crate
โ”‚ย ย  โ”œโ”€โ”€ Cargo.toml
โ”‚ย ย  โ””โ”€โ”€ src
โ”œโ”€โ”€ test
โ”œโ”€โ”€ web
โ””โ”€โ”€ windows

Throughout this section we will refer to your crate name as $crate. Unless otherwise noted, the crate folder and the crate name will be used interchangeably.

Next, add these two lines to your Cargo.toml:

+[lib]
+crate-type = ["staticlib", "cdylib"]

This configures your crate to be output as a static library for MacOS and iOS, and a dynamic library on other platforms. Configure this to your needs. If you would like to write tests or benchmarks, append "rlib" to the list as well.