Extends package API to support changing the toolchain used for building packages.
Is your feature request related to a problem? Please describe.
Starting from v2.9.1, xmake will use the same toolchain configuration to compile both the project and dependency libraries added by add_requires if the package is built using CMake. However, some dependency libraries may not be fully tested on the toolchain used by the project, which causes package installation failure when configuring host projects. For example, D3D12MemoryAllocator does not support clang-cl toolchain on Windows, which causes installing failure on clang-cl: https://github.com/JX-Master/LunaSDK/actions/runs/8867202690/job/24345488867
This problem can be solved by building such library using msvc and linking them to the host project built with clang-cl toolchain. Currently, xmake provides add_requireconfs that enables the user to provide configurations used when building and installing packages, but as far as I know, the user cannot change the toolchain used for building packages by specifying a uniform parameter in add_requireconfs, it is up to the build system implementation that how the toolchain used to compile the package is selected.
Describe the solution you'd like
The ideal way to solve this is to add one toolchain configuration parameter to add_requireconfs. For example, the following script may forces the library to be built using msvc toolchain, no matter what toolchain the host project uses:
add_requireconfs("example_library", {toolchain = "msvc"})
or
add_requireconfs("example_library", {configs = {toolchain = "msvc"}})
also, since the user can specify configuations directly in add_requires, changing toolchain in add_requires should also be supported:
add_requires("example_library", {toolchain = "msvc"})
or
add_requires("example_library", {configs = {toolchain = "msvc"}})
Describe alternatives you've considered
No response
Additional context
No response
It has been supported since v2.5.5
use toolchains instead of toolchain, we can pass multiple toolchains. toolchains = {"gcc", "yasm"}
add_requires("example_library", {configs = {toolchains = "gcc"}})
For example, D3D12MemoryAllocator does not support clang-cl toolchain on Windows, which causes installing failure on clang-cl:
Currently some platforms are strictly tied to specific toolchains, e.g. windows -> msvc toolchain, mingw -> mingw toolchain.
Because we don't have much time and resources to maintain different toolchains, e.g. on windows platform, ci has run lots of test jobs. such as MT/MD/MTd/MDd + shared/static + vs2019/vs2022 + x86/x64/arm64. The maintainer needs to fix the build errors encountered in each jobs. This is a huge amount of work, and we don't have any more energy to make it support other toolchain switches like clang-cl. And it also makes package scripts harder to maintain.
Also, a strong binding with msvc would provide a better optimisation base for the current cloud pre-compile acceleration.
Of course, xmake already has clang-cl switching support for some packages that use cmake/xmake, but there is no rigorous ci testing, so package installations are unreliable, and users need to maintain them themselves.
The specific library d3d12-memory-allocator does not get built with msvc even if it is configured with {configs = {toolchains = "msvc"}}).
The configuration is here: https://github.com/JX-Master/LunaSDK/blob/b0d6aab221a820fed01f909bfe2aeedf255a4ea9/xmake.lua#L136
The error log is here: https://github.com/JX-Master/LunaSDK/actions/runs/8888856030/job/24406302292
Is there anything I'm missing?
msvc is default toolchain for windows platform, you need not set it.