A single compiler for a single architecture (say, x86_64) may support many different microarchitectures underneath. For example, the gcc -march flag can have a major impact on the set of instructions generated. See, eg:
https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#index-march-14
What makes this tricky is that it requires enabling different sets of compiler flags for the entire build process. For $REASONS, I don't want to be passing the copts on the command-line because I'm also going to be supporting multiple "traditional" platforms in a single build operation, all of which are handled via cross-compilation.
I'm trying to figure out the best way to get multi-microarchitecture support working when targeting several CPUs which all use the same compiler.
Ideas I've considered:
1. Add select() statements to add the necessary -march flag to copts for every cc_library() statement which will filter off of constraints from the platform. This makes the BUILD files large and ugly, but at least it uses straight-forward definitions
2. Like #2, but rewrap cc_library in something which determines the environment to add the copts flags automatically. This is similar to what the drake team did here:
3. Create a separate cc_toolchain (complete with separate config) for each microarchitecture. This allows everything else to Just Work, but requires moving away from the "standard" @platforms:cpu constraints for the platform resolution code to work correctly.
I'm not certain which of these would be the best choice, if there are others I haven't considered, and if there are any good examples of this usecase.
Thanks again!
- Garrett