Skip to content

nixcloud/cargo-build_script_build-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cargo-build_script_build-parser

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

🔧 Supported Features

cargo-cfg
cargo-check-cfg
cargo:rustc-env
cargo:warning

🔧 Ignored Features

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

🔧 Missing Features

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

💡 Example

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)

Extract rustc-arguments

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"))'

Extract environment-variables

parse-build test/output1 environment-variables

Output:

VAR=VALUE
VAR2=

🚀 Installation

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;
  };
}

🧪 Testing

To verify functionality, run:

cargo test

The tests are written directly in main.rs.

📄 License

MIT © 2025 nixcloud

🙏 Acknowledgements

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.

About

A command-line utility that extracts `--cfg` and `--check-cfg` flags from `cargo:`

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published