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.76k stars 425 forks source link

add as_excutable option #1080

Closed ds1sqe closed 4 weeks ago

ds1sqe commented 1 month ago

add new option on build ( as_executable(flag:bool) ) which create executable output and do not compile as lib

ds1sqe commented 1 month ago

But it's will be great if can compile into executable, and i think we can do that by a little efforts. So why do not add feature with unstable? and with my PR, we can compile as executable (if the "files" have unique main) on gcc and clang and msvc, if the language is C or C++. with existing out_dir and compile(path) option. ( the executable will be placed on out_dir / compile_arg)

ds1sqe commented 1 month ago

And also there are some projects which have to compile some c / cpp project and configure root rust project with compiled c / cpp executable. that's why i upload this PR. I think the .as_executable option will be much help on that case

thomcc commented 4 weeks ago

I don't think we have the maintainer resources to support large new features like this, honestly. The architecture is also not set up to make this easy, and it's not clear to me that this patch is actually correct for multi-file projects in parallel mode. Either way, I think this is probably going to have to be closed, sorry.

NobodyXu commented 4 weeks ago

I think you can create another crate cc-executable which uses cc to generate an archive first, then compile it to an executable.

The code in this PR breaks parallel compilation, whereas using cc to generate an archive first would support parallel compilation and easier to implement.

cc @thomcc @ds1sqe I do think we can support generating object files instead of archive though, to support compiling to executable in another crate