ccfg 0.1.1

Build-script helpers for crates that compile C code via the cc crate
Documentation
  • Coverage
  • 66.67%
    2 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 7.15 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 251.4 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 6s Average build duration of successful builds.
  • all releases: 6s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • SzymonTurno

ccfg

crates.io docs.rs License

Build-script helpers for crates that compile C code via the cc crate.

Installation

[build-dependencies]
ccfg = { version = "0.1", features = ["build"] }

The build feature gates the cc dependency so it is only pulled in when building build.rs, not in the final binary.

Usage

// build.rs
fn main() {
    let mut build = cc::Build::new();
    build.file("src/c_src/re.c");

    ccfg::configure_arch(&mut build);
    ccfg::apply_coverage(&mut build);

    build.compile("re");
}

configure_arch

Configures the compiler for the current target:

  • Zephyr cross-compilation — when ZEPHYR_BASE is set and no CC/TARGET_CC override is present, reads CMAKE_C_COMPILER from CMakeCache.txt and sets it as the compiler. This is the only reliable source for the cross-compiler path inside a west workspace.
  • riscv64 — adds -mcmodel=medany so relocations work when Zephyr places the binary outside the low-2 GB address window.

Emits the appropriate cargo:rerun-if-changed and cargo:rerun-if-env-changed directives as side effects.

apply_coverage

Reconfigures build for LLVM source-based coverage when the calling crate's coverage Cargo feature is active. Sets the compiler to Clang, forces -O0, and adds -fprofile-instr-generate/-fcoverage-mapping. No-op otherwise.

Must be called after any build.opt_level() call, as it overrides that setting.

License

Apache-2.0 — see LICENSE.