Skip to content

Per-target toolchains don't work? #6672

@nwf

Description

@nwf

Xmake Version

v3.0.1+v301.3350cc5ab

Operating System Version and Architecture

Debian 13 powerpc64le

Describe Bug

xmake v3.0.1 does not honor per-target toolchains settings, despite the documentation strongly suggesting that this should work.

Expected Behavior

If a target()'s description invokes set_toolchains(), that should be reflected in the build (and link, and prepare?) commands used for that target, and such settings should not change the toolchains used by any other targets.

Project Configuration

toolchain("tc20")
	set_kind("standalone")
	set_toolset("cxx", "clang++")
	on_load(function (toolchain) toolchain:add("cxflags", "-std=c++20", {force = true}) end)
toolchain_end()

toolchain("tc23")
	set_kind("standalone")
	set_toolset("cxx", "clang++")
	on_load(function (toolchain) toolchain:add("cxflags", "-std=c++23", {force = true}) end)
toolchain_end()

target("a20")
	set_kind("static")
	set_toolchains("tc20")
	add_files("a.cc")
	after_load(function (target) print("--->", target:name(), target:get("toolchains")) end)
target_end()

target("a23")
	set_kind("static")
	set_toolchains("tc23")
	add_files("a.cc")
	after_load(function (target) print("--->", target:name(), target:get("toolchains")) end)
target_end()

Additional Information and Error Logs

We can see that at least some part of xmake thinks it's doing the right thing, as the two targets' after_load callbacks print out the right toolchain names:

---> a20 tc20
---> a23 tc23

But when building (xmake -v), we see that everything in sight gets built with -std=c++20, as if tc20 were the only toolchain defined:

[ 23%]: cache compiling.release a.cc
/usr/bin/clang++ -c -Qunused-arguments -std=c++20 -o build/.objs/a20/linux/ppc64/release/a.cc.o a.cc
[ 35%]: linking.release liba20.a
/usr/bin/ar -cr build/linux/ppc64/release/liba20.a build/.objs/a20/linux/ppc64/release/a.cc.o
[ 59%]: cache compiling.release a.cc
/usr/bin/clang++ -c -Qunused-arguments -std=c++20 -o build/.objs/a23/linux/ppc64/release/a.cc.o a.cc
[ 71%]: linking.release liba23.a
/usr/bin/ar -cr build/linux/ppc64/release/liba23.a build/.objs/a23/linux/ppc64/release/a.cc.o
[100%]: build ok, spent 0.614s

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions