cargo applet to build and install C-ABI compatible dynamic and static libraries.
It produces and installs a correct pkg-config file, a static library and a dynamic library, and a C header to be used by any C (and C-compatible) software.
cargo-c may be installed from crates.io.
cargo install cargo-c
The rustc version supported is the same as the one supported by the cargo version embedded in the package version, or as set in the
rust-version field.
You must have the cargo build requirements satisfied in order to build cargo-c:
gitpkg-config (on Unix, used to figure out the host-provided headers/libraries)curl (on Unix)libssl-dev package on deb-based distributions)You may pass --features=vendored-openssl if you have problems building openssl-sys using the host-provided OpenSSL.
cargo install cargo-c --features=vendored-openssl
# build the library, create the .h header, create the .pc file
$ cargo cbuild --destdir=${D} --prefix=/usr --libdir=/usr/lib64
# build the library, create the .h header, create the .pc file, build and run the tests
$ cargo ctest
# build the library, create the .h header, create the .pc file and install all of it
$ cargo cinstall --destdir=${D} --prefix=/usr --libdir=/usr/lib64
For a more in-depth explanation of how cargo-c works and how to use it for
your crates, read Building Crates so they Look Like C ABI Libraries.
This is the ideal setup for a project that wants to keep their C-API within the main crate:
capi.rs with the C-API you want to expose and use
#[cfg(cargo_c)]#[cfg(feature="capi")] to hide it when you build a normal rust library.crate-type.crate-type, cargo-c will add the correct library target by itself.capi to add C-API-specific optional dependencies.
NOTE: It must be always present in
Cargo.toml
cbindgen.toml and fill it with
at least the include guard and probably you want to set the language to C (it
defaults to C++)cargo-c and do cargo cinstall --prefix=/usr --destdir=/tmp/some-place or something along those lines.If you plan to keep the bindings as a separate crate and do not need to autogenerate the headers you may just populate Cargo.toml:
capi feature, since it is used by cargo-c to identify packages that has to be built as C-libraries within a workspace.package.metadata.capi.header.generation to false.package.metadata.capi keysstaticlib supportcdylib supportThis software has been partially developed in the scope of the H2020 project SIFIS-Home with GA n. 952652.
405 followers · starred Feb 2023
1,149 followers · starred Dec 2024
678 followers · starred May 2021
32 followers · starred Apr 2025
Rust
97.8%
Shell
1.3%
cargo applet to build and install C-ABI compatible dynamic and static libraries.
It produces and installs a correct pkg-config file, a static library and a dynamic library, and a C header to be used by any C (and C-compatible) software.
cargo-c may be installed from crates.io.
cargo install cargo-c
The rustc version supported is the same as the one supported by the cargo version embedded in the package version, or as set in the
rust-version field.
You must have the cargo build requirements satisfied in order to build cargo-c:
gitpkg-config (on Unix, used to figure out the host-provided headers/libraries)curl (on Unix)libssl-dev package on deb-based distributions)You may pass --features=vendored-openssl if you have problems building openssl-sys using the host-provided OpenSSL.
cargo install cargo-c --features=vendored-openssl
# build the library, create the .h header, create the .pc file
$ cargo cbuild --destdir=${D} --prefix=/usr --libdir=/usr/lib64
# build the library, create the .h header, create the .pc file, build and run the tests
$ cargo ctest
# build the library, create the .h header, create the .pc file and install all of it
$ cargo cinstall --destdir=${D} --prefix=/usr --libdir=/usr/lib64
For a more in-depth explanation of how cargo-c works and how to use it for
your crates, read Building Crates so they Look Like C ABI Libraries.
This is the ideal setup for a project that wants to keep their C-API within the main crate:
capi.rs with the C-API you want to expose and use
#[cfg(cargo_c)]#[cfg(feature="capi")] to hide it when you build a normal rust library.crate-type.crate-type, cargo-c will add the correct library target by itself.capi to add C-API-specific optional dependencies.
NOTE: It must be always present in
Cargo.toml
cbindgen.toml and fill it with
at least the include guard and probably you want to set the language to C (it
defaults to C++)cargo-c and do cargo cinstall --prefix=/usr --destdir=/tmp/some-place or something along those lines.If you plan to keep the bindings as a separate crate and do not need to autogenerate the headers you may just populate Cargo.toml:
capi feature, since it is used by cargo-c to identify packages that has to be built as C-libraries within a workspace.package.metadata.capi.header.generation to false.package.metadata.capi keysstaticlib supportcdylib supportThis software has been partially developed in the scope of the H2020 project SIFIS-Home with GA n. 952652.
405 followers · starred Feb 2023
1,149 followers · starred Dec 2024
678 followers · starred May 2021
32 followers · starred Apr 2025
Rust
97.8%
Shell
1.3%