rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Add support for config files

Open pvdrz opened this issue 1 year ago • 1 comments

This PR adds support for configuration files when using bindgen-cli.

The main motivation for this feature is that, with the growing number of options that bindgen has, it is hard to keep track on the options used in each invocation.

I decided to use TOML as it has become the de-facto configuration format in several Rust projects such as Cargo and Rustfmt.

To use this feature you can either pass the --config-path arguments to bindgen with the path to the configuration file, or create a bindgen.toml file in the current directory.

If you want to use this feature but you don't want to transcribe your CLI arguments by hand, you can use the --dump-config flag to dump the passed configuration into stdout.

If you want to keep using bindgen the old way, you can pass the --ignore-config flag. Which will ignore any configuration file, this includes both the --config-path argument and the default bindgen.toml file.

Fixes https://github.com/rust-lang/rust-bindgen/issues/1898 and https://github.com/rust-lang/rust-bindgen/issues/2508

pvdrz avatar Aug 30 '24 20:08 pvdrz

This is great (lacking tests but that should be doable?)

yeah testing this shouldn't be that hard.

that said, why making it cli-only? It seems it might be worth making it usable from the library as well.

this would have the extra hiccup of having to move BindgenOptions from bindgen-cli to bindgen and only make it public when the __cli feature is enabled. But it should be doable.

That way we can possibly even replace the bindgen-flags: stuff.

That would be cool but at the same time we need some kind of test for the CLI args so we can check the flags actually work.

But anyways even cli-only it seems worth doing.

:tada:

pvdrz avatar Sep 03 '24 04:09 pvdrz