c2rust icon indicating copy to clipboard operation
c2rust copied to clipboard

Support multiple compilation commands for a given source file

Open randomPoison opened this issue 2 years ago • 4 comments

When transpiling dav1d to Rust I ran into the issue that some of the source files get transpiled multiple times with different defines. Currently c2rust ignores duplicate compile commands for a given source file, so when transpiling dav1d I get the following warnings:

warning: Skipping duplicate compilation cmd for /home/randompoison/dev/rav1d/src/cdef_apply_tmpl.c
warning: Skipping duplicate compilation cmd for /home/randompoison/dev/rav1d/src/cdef_tmpl.c
warning: Skipping duplicate compilation cmd for /home/randompoison/dev/rav1d/src/filmgrain_tmpl.c
warning: Skipping duplicate compilation cmd for /home/randompoison/dev/rav1d/src/fg_apply_tmpl.c
warning: Skipping duplicate compilation cmd for /home/randompoison/dev/rav1d/src/ipred_prepare_tmpl.c
warning: Skipping duplicate compilation cmd for /home/randompoison/dev/rav1d/src/ipred_tmpl.c
warning: Skipping duplicate compilation cmd for /home/randompoison/dev/rav1d/src/itx_tmpl.c
warning: Skipping duplicate compilation cmd for /home/randompoison/dev/rav1d/src/loopfilter_tmpl.c
warning: Skipping duplicate compilation cmd for /home/randompoison/dev/rav1d/src/lf_apply_tmpl.c
warning: Skipping duplicate compilation cmd for /home/randompoison/dev/rav1d/src/looprestoration_tmpl.c
warning: Skipping duplicate compilation cmd for /home/randompoison/dev/rav1d/src/lr_apply_tmpl.c
warning: Skipping duplicate compilation cmd for /home/randompoison/dev/rav1d/src/mc_tmpl.c
warning: Skipping duplicate compilation cmd for /home/randompoison/dev/rav1d/src/recon_tmpl.c

It would be better if c2rust supported these duplicated compile commands and generated one Rust file for each compilation. This would require automatically appending some prefix to the generated file name to avoid collisions, but otherwise I don't see an obvious reason why this couldn't be supported.

randomPoison avatar Mar 06 '23 21:03 randomPoison

@randomPoison, would it be useful in seeing if there's an easy fix for this?

kkysen avatar Mar 06 '23 22:03 kkysen

Yeah, if there's a quick fix for this then it'd be useful functionality to have for the dav1d porting effort.

randomPoison avatar Mar 07 '23 00:03 randomPoison

I think we need to discuss what a good solution would look like. For instance, should this be controlled by a CLI flag. How should prefixes be chosen/generated. IIRC, one existing use case we have is when a library compiles all its source files twice - once to build a shared library, once to build a static library.

thedataking avatar Mar 08 '23 19:03 thedataking

Could we use the output field rather than the file field of the compile commands to determine the Rust source path? With duplicate compile commands per source file, the output file should be different. The output path could only be used instead of the file path in duplicate cases where disambiguation is needed.

kkysen avatar Mar 15 '23 09:03 kkysen