sstadick / cargo-bundle-licenses

Generate a THIRDPARTY file with all licenses in a cargo project.
Apache License 2.0
90 stars 6 forks source link

Add option to filter licenses by targets #19

Open jwodder opened 1 year ago

jwodder commented 1 year ago

If one is planning to only build & distribute binaries of a project for a limited number of targets, it doesn't make much sense to bundle licenses for dependencies exclusive to other targets that will never be used. (For example, if a project depends on chrono and its clock feature, then iana-time-zone will be pulled into the dependency tree, and this package depends on android_system_properties on Android and js-sys & wasm-bindgen on WASM, but if you're only building for Linux, macOS, and Windows, you shouldn't need to bundle those packages' licenses.)

I therefore request a feature for specifying a set of target triples by which to filter the dependencies for which licenses are bundled.

sstadick commented 1 year ago

Agreed, this would be nice to have. I'm not sure how to implement this off the top of my head as this tool heavily relies on cargo-metadata to build up the deps, and I'm not sure that is target aware.

jwodder commented 1 year ago

cargo metadata has a --filter-platform <triple> option for only showing dependencies for a given triple, so one way to implement this would be run the command for each triple and combine the results.

jwodder commented 1 year ago

I've just discovered the krates crate, which provides functionality for determining all dependencies of a package filtered by kind and/or target, among other things.

sstadick commented 1 year ago

That does seem like it should work...

I don't have a lot of spare time at the moment but I do want to work this in at a future point!