All Projects → lu-zero → Cargo C

lu-zero / Cargo C

Licence: mit
build and install C-compatible libraries

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Cargo C

Cargo Deny
❌ Cargo plugin for linting your dependencies 🦀
Stars: ✭ 533 (+171.94%)
Mutual labels:  hacktoberfest, cargo
Stegbrute
Fast Steganography bruteforce tool written in Rust useful for CTF's
Stars: ✭ 134 (-31.63%)
Mutual labels:  hacktoberfest, cargo
Rustfix
Automatically apply the suggestions made by rustc
Stars: ✭ 586 (+198.98%)
Mutual labels:  hacktoberfest, cargo
Cargo About
📜 Cargo plugin to generate list of all licenses for a crate 🦀
Stars: ✭ 148 (-24.49%)
Mutual labels:  hacktoberfest, cargo
Tarpaulin
A code coverage tool for Rust projects
Stars: ✭ 1,097 (+459.69%)
Mutual labels:  hacktoberfest, cargo
Cargo Spellcheck
Checks all your documentation for spelling and grammar mistakes with hunspell and a nlprule based checker for grammar
Stars: ✭ 183 (-6.63%)
Mutual labels:  hacktoberfest, cargo
Viseron
Self-hosted NVR with object detection
Stars: ✭ 192 (-2.04%)
Mutual labels:  hacktoberfest
Styles
Official repository for Citation Style Language (CSL) citation styles.
Stars: ✭ 2,458 (+1154.08%)
Mutual labels:  hacktoberfest
Linux
Linux kernel variant from Analog Devices; see README.md for details
Stars: ✭ 194 (-1.02%)
Mutual labels:  hacktoberfest
Mullet
Mullet Stack: Facebook in the front. Walmart in the back. (React, Hapijs, Node)
Stars: ✭ 194 (-1.02%)
Mutual labels:  hacktoberfest
Cargo Chef
A cargo-subcommand to speed up Rust Docker builds using Docker layer caching.
Stars: ✭ 192 (-2.04%)
Mutual labels:  cargo
Botbuilder Community Dotnet
Part of the Bot Builder Community Project. Repository for extensions for the Bot Builder .NET SDK, including middleware, dialogs, recognizers and more.
Stars: ✭ 196 (+0%)
Mutual labels:  hacktoberfest
Checkov
Prevent cloud misconfigurations during build-time for Terraform, Cloudformation, Kubernetes, Serverless framework and other infrastructure-as-code-languages with Checkov by Bridgecrew.
Stars: ✭ 3,572 (+1722.45%)
Mutual labels:  hacktoberfest
React Native Dotenv
Load react native environment variables using import statements for multiple env files.
Stars: ✭ 190 (-3.06%)
Mutual labels:  hacktoberfest
Ru.javascript.info
Современный учебник JavaScript
Stars: ✭ 2,648 (+1251.02%)
Mutual labels:  hacktoberfest
Squashfuse
FUSE filesystem to mount squashfs archives
Stars: ✭ 193 (-1.53%)
Mutual labels:  hacktoberfest
Vue Html To Paper
Vue mixin for paper printing html elements.
Stars: ✭ 195 (-0.51%)
Mutual labels:  hacktoberfest
Openqa
openQA web-frontend, scheduler and tools.
Stars: ✭ 194 (-1.02%)
Mutual labels:  hacktoberfest
Trilogy
TypeScript SQLite layer with support for both native C++ & pure JavaScript drivers.
Stars: ✭ 195 (-0.51%)
Mutual labels:  hacktoberfest
Climate Change Data
🌍 A curated list of APIs, open data and ML/AI projects on climate change
Stars: ✭ 195 (-0.51%)
Mutual labels:  hacktoberfest

Cargo C-ABI helpers

LICENSE Crates.io Build Status cargo-c chat

cargo applet to build and install C-ABI compatibile 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.

Installation

cargo-c may be installed from crates.io.

cargo install cargo-c

You must have the cargo build requirements satisfied in order to build cargo-c:

  • git
  • pkg-config (on Unix, used to figure out the host-provided headers/libraries)
  • curl (on Unix)
  • OpenSSL headers (only for Unix, this is the 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

Usage

# 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.

The TL;DR:

  • Create a 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.
  • Make sure you have a lib target and if you are using a workspace the first member is the crate you want to export, that means that you might have to add a "." member at the start of the list.
  • Since Rust 1.38, also add "staticlib" to the "lib" crate-type. Do not specify the crate-type, cargo-c will add the correct library target by itself.
  • You may use the feature capi to add C-API-specific optional dependencies.

    NOTE: It must be always present in Cargo.toml

  • Remember to add a 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++)
  • Once you are happy with the result update your documentation to tell the user to install cargo-c and do cargo cinstall --prefix=/usr --destdir=/tmp/some-place or something along those lines.

Advanced

You may override various aspects of cargo-c via settings in Cargo.toml under the package.metadata.capi key

[package.metadata.capi]
# Configures the minimum required cargo-c version. Trying to run with an
# older version causes an error.
min_version = "0.6.10"

Header Generation

[package.metadata.capi.header]
# Used as header file name. By default this is equal to the crate name.
# The name can be with or without the header filename extension `.h`
name = "new_name"
# Install the header into a subdirectory with the name of the crate. This
# is enabled by default
subdirectory = true
# Generate the header file with `cbindgen`, or copy a pre-generated header
# from the `assets` subdirectory. By default a header is generated.
generation = true
# Can be use to disable header generation completely.
# This can be used when generating dynamic modules instead of an actual library.
enabled = true

pkg-config File Generation

[package.metadata.capi.pkg_config]
# Used as the package name in the pkg-config file and defaults to the crate name.
name = "libfoo"
# Used as the package description in the pkg-config file and defaults to the crate description.
description = "some description"
# Used as the package version in the pkg-config file and defaults to the crate version.
version = "1.2.3"
# Used as the Requires field in the pkg-config file, if defined
requires = "gstreamer-1.0, gstreamer-base-1.0"
# Used as the Requires.private field in the pkg-config file, if defined
requires_private = "gobject-2.0, glib-2.0 >= 2.56.0, gmodule-2.0"

Library Generation

[package.metadata.capi.library]
# Used as the library name and defaults to the crate name. This might get
# prefixed with `lib` depending on the target platform.
name = "new_name"
# Used as library version and defaults to the crate version. How this is used
# depends on the target platform.
version = "1.2.3"
# Used to install the library to a subdirectory of `libdir`.
install_subdir = "gstreamer-1.0"
# Used to disable versioning links when installing the dynamic library
versioning = false

Users

Status

  • [x] cli
    • [x] build command
    • [x] install command
    • [x] test command
    • [x] cargo applet support
  • [x] build targets
    • [x] pkg-config generation
    • [x] header generation (cbindgen integration)
  • [x] staticlib support
  • [x] cdylib support
  • [x] Generate version information in the header
    • [ ] Make it tunable
  • [x] Extra Cargo.toml keys
  • [x] Better status reporting

Sponsors

Acknowledgements

This software has been partially developed in the scope of the H2020 project SIFIS-Home with GA n. 952652.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].