Support custom rustfmt.toml path for formatting generated bindings.
This CL avoids hardcoding "external/rustfmt/rustfmt.toml" path in the
`rustfmt` function in `token_stream_printer.rs`. This is replaced with
an argument of a new cmdline parameter: `--rustfmt_config_path`.
After this CL:
- Unit tests in `ir_from_cc_test.rs`, `src_code_gen.rs`, etc. will
switch to using the default rustfmt config (i.e. the one hardcoded in
the `token_stream_printer::RustfmtConfig::default()`).
- End-to-end tests in `test/golden`, other `test/...` directories, and
actual bindings will keep using "external/rustfmt/rustfmt.toml"
(as they did before this CL).
PiperOrigin-RevId: 446980646
diff --git a/rs_bindings_from_cc/src_code_gen.cc b/rs_bindings_from_cc/src_code_gen.cc
index a01e16e..590dad2 100644
--- a/rs_bindings_from_cc/src_code_gen.cc
+++ b/rs_bindings_from_cc/src_code_gen.cc
@@ -21,7 +21,8 @@
};
// This function is implemented in Rust.
-extern "C" FfiBindings GenerateBindingsImpl(FfiU8Slice json);
+extern "C" FfiBindings GenerateBindingsImpl(FfiU8Slice json,
+ FfiU8Slice rustfmt_config_path);
// Creates `Bindings` instance from copied data from `ffi_bindings`.
static Bindings MakeBindingsFromFfiBindings(const FfiBindings& ffi_bindings) {
@@ -48,9 +49,11 @@
FreeFfiU8SliceBox(ffi_bindings.rs_api_impl);
}
-Bindings GenerateBindings(const IR& ir) {
+Bindings GenerateBindings(const IR& ir, absl::string_view rustfmt_config_path) {
std::string json = llvm::formatv("{0}", ir.ToJson());
- FfiBindings ffi_bindings = GenerateBindingsImpl(MakeFfiU8Slice(json));
+
+ FfiBindings ffi_bindings = GenerateBindingsImpl(
+ MakeFfiU8Slice(json), MakeFfiU8Slice(rustfmt_config_path));
Bindings bindings = MakeBindingsFromFfiBindings(ffi_bindings);
FreeFfiBindings(ffi_bindings);
return bindings;