cc-rs icon indicating copy to clipboard operation
cc-rs copied to clipboard

Support compiling different files with different options

Open joshtriplett opened this issue 5 years ago • 4 comments

I'd like to have better support for compiling different files with different compiler options. For instance, I'd like to compile avx2-foo.c with -mavx2, without applying that flag to any other source file.

joshtriplett avatar Aug 15 '20 23:08 joshtriplett

I think this can be done with separate instances of Build?

alexcrichton avatar Aug 24 '20 15:08 alexcrichton

The problem is that each Build builds a separate library archive, and combining archives requires quite a bit of non-portable platform-specific knowledge. The ideal behavior would be to compile different object files with different options, then combine those objects into one archive.

It might work to use a separate Build for different sets of options, so that you could add common options, clone the Build, add different options, and add the files that use those options. But then there would need to be a way to re-combine the Build instances to link a single library at the end. Perhaps Build could have a function that takes ownership of another Build, and the Build can have a list of owned sub-builds?

joshtriplett avatar Aug 24 '20 16:08 joshtriplett

But you don't need to combine archives? They're just both passed to the linker?

alexcrichton avatar Aug 24 '20 16:08 alexcrichton

@alexcrichton You do when you're building a library that other crates want to find by name, such as if you're constructing a static library and associated pkg-config files and headers to put on the search path.

joshtriplett avatar Aug 24 '20 18:08 joshtriplett