Parsing configuration strings (cfg(), #[cfg])

Hello everyone, I'm writing generator for RPM spec files out of Cargo.toml (aka rust2rpm).

Right now, we ask users to manually remove all dependencies like [target."cfg(windows)".dependencies.winapi], but I would like to automate this. The problem is that I can't find any crate which would help me parsing cfg(windows) part.

Any hints?

Do you really need to parse the dependencies? Cargo-deb works around it by calling ldd on executables, so it's able to automatically set system-level dependencies that are actually used.

I think we are talking about different things here. cargo-deb runs ldd on binaries after build and adds that to dependency list, right? What I'm trying to do is to not add winapi and such things to BuildRequires.

We are actually not interested in pre-resolving dependencies, we let dnf/libsolv to do the job.

I've made a crate for it: parse_cfg - Rust

2 Likes