#pkg-config #build #build-dependencies #cc #path #args #bindgen

build cc-args

The clue between pkg-config and bindgen, cc

2 unstable releases

0.2.0 Jan 20, 2024
0.1.0 Jun 11, 2022

#8 in #pkg-config

Custom license

15KB
433 lines

cc-args

crate.io rustdocs

tl;dr

bindgen::Builder::merge_cc_args(&self, &pkg_config::Library)

This crate exports CcArgs and MergeCcArgs.

CcArgs

It provides link_paths, include_paths, framework_paths, frameworks, libs, ld_args and defines.

MergeCcArgs

It provides the method merge_cc_args that accept a CcArgs implementation.

Features
  • pkg_config implements CcArgs for pkg_config::Library
  • cc implements MergeCcArgs for cc::Build
  • bindgen implements MergeCcArgs for bindgen::Builder

Example

build.rs

use std::path::PathBuf;

use cc_args::{bindgen, pkg_config, MergeCcArgs};

fn main() {
    let out_path = PathBuf::from(std::env::var("OUT_DIR").unwrap());
    println!("cargo:rerun-if-changed=wrapper.h");
    bindgen::Builder::default()
        .merge_cc_args(&pkg_config::probe_library("libzstd").unwrap())
        .header("wrapper.h")
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        .generate()
        .unwrap()
        .write_to_file(out_path.join("bindings.rs"))
        .unwrap();
}

Dependencies

~0–1.3MB
~25K SLoC