mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.32k stars 299 forks source link

Ignore dev-dependencies #666

Open Manishearth opened 3 years ago

Manishearth commented 3 years ago

Currently cbindgen in parse-deps mode seems to include dev-dependencies and build-dependencies. It would be nice if that could be avoided.

(In my case it means that we hit https://github.com/eqrion/cbindgen/issues/665 even though it's only used by criterion)

emilio commented 3 years ago

Yeah, that's silly. Should be trivial to fix, let me know if you're blocked on it or need it fast and I should be able to fix quick.

Manishearth commented 3 years ago

Not blocked on it at the moment, I'm writing manual bindings for now.

jonhoo commented 3 years ago

One challenge here will probably be that when you invoke cargo metadata, it downloads all dependencies regardless of how they're pulled in. So while we may be able to make cbindgen not parse dev-dependencies, we may still end up having to fetch them.

ophilli commented 1 year ago

One challenge here will probably be that when you invoke cargo metadata, it downloads all dependencies regardless of how they're pulled in. So while we may be able to make cbindgen not parse dev-dependencies, we may still end up having to fetch them.

I just ran into this exact issue. My company builds each package in a network jail & so each package only has access to whatever it explicitly fetches. cbindgen's use of cargo metadata is effectively converting my dev-dependencies into build dependencies, regardless of whether or not I enable / disable parse_deps.

Looks like the parse_deps option gets passed here from builder::generate() into Cargo::load() as use_cargo_lock which is used here and doesn't control whether or not cargo metadata is called.

If I get some free time I might poke around and see if it's feasible to skip the cargo metadata invocation, but for now I'll just copy all my dev-dependencies into build-dependencies.

ophilli commented 1 year ago

Looks like the cargo metadata fork was added on May 24, 2017 in https://github.com/mozilla/cbindgen/commit/d826d98b9e471f92170d2bd7b2771c2caa74f5e1 with the --no-deps option removed, and then dependency parsing was made optional on Jun 21, 2017 in https://github.com/mozilla/cbindgen/commit/7a60c528f3c1de1b66bf218671f15f34b5bf6dec.

Perhaps we can now back out the fork of cargo metadata and make the parse_deps config invoke --no-deps.