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

Add parent directory creation to write_to_file function

Open Enes1313 opened this issue 2 years ago • 3 comments

This commit adds the ability to create parent directories if they don't exist before writing a file in the write_to_file function. Additionally, an integration test has been changed to validate the behavior of the updated write_to_file function with parent directory creation.

This feature enables preserving the hierarchical structure of C/C++ projects where header files with the same name exist in different folders when generating bindings.

Additionally, this enhancement could have been implemented as an optional parameter if desired. If preferred, I can try refactor the changes to incorporate the functionality as an optional parameter.

@emilio

Enes1313 avatar Jul 16 '23 21:07 Enes1313

Is there any use case where calling create_dir_all before write_to_file is not enough?

pvdrz avatar Jul 17 '23 00:07 pvdrz

I thought it would be nicer to solve this by using the bindgen library. At the same time, in the bindgen CLI usage, there is no need for an additional operation like "mkdirs" command or "--create_dir_all" as the output is directly given. In this specific use case, simply outputting the generated bindings without performing a separate directory creation step is sufficient.

Enes1313 avatar Jul 17 '23 06:07 Enes1313

Even though I understand your point, I think this is not a strong enough reason to add this feature. That being said, I'll defer this to @emilio as he might think otherwise.

pvdrz avatar Jul 18 '23 21:07 pvdrz