rust-lang / cc-rs

Rust library for build scripts to compile C/C++ code into a Rust library
https://docs.rs/cc
Apache License 2.0
1.84k stars 442 forks source link

Add a public file iterator #987

Closed gzz2000 closed 7 months ago

gzz2000 commented 7 months ago

Hi, I am adding a public interface for iterating the files to be compiled. My use case is to generate compile_commands.json outside. This configuration is needed by various language servers/IDEs and contains the mapping between source files and their compile commands. We can already get the compile commands using get_compiler, but the files are not exposed through any public interface yet. I've made this interface a little more general by not exposing Arc<Path> but give an iterator instead.

I am also wondering if adding a compile_commands.json-generator directly into cc-rs might be useful as this is a built-in feature for many build systems including cmake, bazel, makefile, ninja, and some rust ones etc. It is better if one can generate one json combined from multiple cc::Build instances.

NobodyXu commented 7 months ago

Thank you!

I am also wondering if adding a compile_commands.json-generator directly into cc-rs might be useful

I think that is a bit too much, cc is often used in build.rs, so it should strive to be as simple/small as possible.

I think it's better to write another crate generating compile_command.json, given the API in this PR should be enough for a third-party crate to use it directly or indirectly.

gzz2000 commented 7 months ago

Thank you very much!