A command-line utility that extracts --cfg
and --check-cfg
flags from cargo:
lines generated by a Rust build.rs
script.
This is useful when integrating crates like libc
, which emit configuration flags during their build process.
https://github.com/nixcloud/cargo-build_script_build-parser
https://doc.rust-lang.org/cargo/reference/build-scripts.html
- Outputs all flags as a single command-line string
- Simple command-line interface
- Tests included
- Distributed as a Nix Flake
cargo-cfg
cargo-check-cfg
cargo:rustc-env
cargo:warning
cargo:rerun-if-changed
cargo:rerun-if-env-changed
cargo:rerun-if-changed-bin
cargo:rerun-if-changed-glob
cargo:rerun-if-changed-dir
cargo:rerun-if-changed-recursive
cargo:rerun-if-changed-env
cargo:rustc-link-lib
cargo:rustc-link-search
cargo:rustc-flags
cargo:rustc-cdylib-link-arg
cargo:rustc-bin-link-arg
cargo:rustc-link-arg-bin
Simply run:
nix run .#default -- test/output1 rustc-arguments
Given an input file output.txt
with the following content:
cargo:rustc-cfg=freebsd11
cargo:rustc-cfg=libc_const_extern_fn
cargo:rustc-check-cfg=cfg(freebsd11)
cargo:rustc-check-cfg=cfg(libc_ctest)
nix run .#default -- output.txt rustc-arguments
Output:
--cfg='libc_const_extern_fn' --cfg='freebsd11' --check-cfg='cfg(espidf_time32)' --check-cfg='cfg(target_arch,values("mips64r6"))'
parse-build test/output1 environment-variables
Output:
VAR=VALUE
VAR2=
This project is distributed as a Nix Flake.
{
cargo-build_script_build-parser.url = "github:nixcloud/cargo-build_script_build-parser";
outputs = { self, cargo-build_script_build-parser, ... }: {
packages.x86_64-linux.cargo-build_script_build-parser = cargo-build_script_build-parser.packages.x86_64-linux.default;
};
}
To verify functionality, run:
cargo test
The tests are written directly in main.rs.
MIT © 2025 nixcloud
This utility was inspired by how libc and similar crates communicate configuration to cargo and downstream consumers. It simplifies extracting those configurations in reproducible or cross-compiled environments.