c2rust
                                
                                
                                
                                    c2rust copied to clipboard
                            
                            
                            
                        Support multiple compilation commands for a given source file
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, would it be useful in seeing if there's an easy fix for this?
Yeah, if there's a quick fix for this then it'd be useful functionality to have for the dav1d porting effort.
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.
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.