ccfg
Build-script helpers for crates that compile C code via the cc crate.
Installation
[]
= { = "0.1", = ["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
configure_arch
Configures the compiler for the current target:
- Zephyr cross-compilation — when
ZEPHYR_BASEis set and noCC/TARGET_CCoverride is present, readsCMAKE_C_COMPILERfromCMakeCache.txtand sets it as the compiler. This is the only reliable source for the cross-compiler path inside a west workspace. - riscv64 — adds
-mcmodel=medanyso 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.