2 releases
| 0.1.1 | Jun 29, 2026 |
|---|---|
| 0.1.0 | Jun 29, 2026 |
#579 in Embedded development
7KB
ccfg
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_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.
Dependencies
~74KB