cbindgen icon indicating copy to clipboard operation
cbindgen copied to clipboard

Ignore dev-dependencies

Open Manishearth opened this issue 4 years ago • 5 comments

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)

Manishearth avatar Mar 10 '21 22:03 Manishearth

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.

emilio avatar Mar 14 '21 10:03 emilio

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

Manishearth avatar Mar 14 '21 20:03 Manishearth

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.

jonhoo avatar Apr 06 '21 17:04 jonhoo

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 avatar Jun 03 '23 05:06 ophilli

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.

ophilli avatar Jun 03 '23 05:06 ophilli