diff options
| author | Francesco Guastella <[email protected]> | 2025-10-16 17:22:41 +0200 |
|---|---|---|
| committer | Francesco Guastella <[email protected]> | 2025-10-16 17:22:41 +0200 |
| commit | 7d3754bfead56d403b4d7839a0addf14a68b57c2 (patch) | |
| tree | 67ad631107557a64be574dcd085768e6a49bc4fb | |
| parent | 4253fdd36cf2b4de908466b24da608a865fe9400 (diff) | |
refactor(toolchain): separate gcc/clang registration from definition to prevent redundant loading
23 files changed, 172 insertions, 133 deletions
diff --git a/xmake/toolchains/clang-12/xmake.lua b/xmake/toolchains/clang-12/xmake.lua index 306d2f5c9..d7c143451 100644 --- a/xmake/toolchains/clang-12/xmake.lua +++ b/xmake/toolchains/clang-12/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../clang/xmake.lua")) +includes(path.join(os.scriptdir(), "../clang/toolchain_clang.lua")) toolchain_clang("12") diff --git a/xmake/toolchains/clang-13/xmake.lua b/xmake/toolchains/clang-13/xmake.lua index ea5094922..779a98d9d 100644 --- a/xmake/toolchains/clang-13/xmake.lua +++ b/xmake/toolchains/clang-13/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../clang/xmake.lua")) +includes(path.join(os.scriptdir(), "../clang/toolchain_clang.lua")) toolchain_clang("13") diff --git a/xmake/toolchains/clang-14/xmake.lua b/xmake/toolchains/clang-14/xmake.lua index 9af9ac17b..a0809f3d8 100644 --- a/xmake/toolchains/clang-14/xmake.lua +++ b/xmake/toolchains/clang-14/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../clang/xmake.lua")) +includes(path.join(os.scriptdir(), "../clang/toolchain_clang.lua")) toolchain_clang("14") diff --git a/xmake/toolchains/clang-15/xmake.lua b/xmake/toolchains/clang-15/xmake.lua index b97fcc150..fcff4cdf4 100644 --- a/xmake/toolchains/clang-15/xmake.lua +++ b/xmake/toolchains/clang-15/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../clang/xmake.lua")) +includes(path.join(os.scriptdir(), "../clang/toolchain_clang.lua")) toolchain_clang("15") diff --git a/xmake/toolchains/clang-16/xmake.lua b/xmake/toolchains/clang-16/xmake.lua index e3e6033fe..ba01bee44 100644 --- a/xmake/toolchains/clang-16/xmake.lua +++ b/xmake/toolchains/clang-16/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../clang/xmake.lua")) +includes(path.join(os.scriptdir(), "../clang/toolchain_clang.lua")) toolchain_clang("16") diff --git a/xmake/toolchains/clang-17/xmake.lua b/xmake/toolchains/clang-17/xmake.lua index 8aa533cdc..9303295a5 100644 --- a/xmake/toolchains/clang-17/xmake.lua +++ b/xmake/toolchains/clang-17/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../clang/xmake.lua")) +includes(path.join(os.scriptdir(), "../clang/toolchain_clang.lua")) toolchain_clang("17") diff --git a/xmake/toolchains/clang-18/xmake.lua b/xmake/toolchains/clang-18/xmake.lua index c5e6dbf08..f1aa1d987 100644 --- a/xmake/toolchains/clang-18/xmake.lua +++ b/xmake/toolchains/clang-18/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../clang/xmake.lua")) +includes(path.join(os.scriptdir(), "../clang/toolchain_clang.lua")) toolchain_clang("18") diff --git a/xmake/toolchains/clang-19/xmake.lua b/xmake/toolchains/clang-19/xmake.lua index 3ffc948a1..a1f89fea2 100644 --- a/xmake/toolchains/clang-19/xmake.lua +++ b/xmake/toolchains/clang-19/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../clang/xmake.lua")) +includes(path.join(os.scriptdir(), "../clang/toolchain_clang.lua")) toolchain_clang("19") diff --git a/xmake/toolchains/clang-20/xmake.lua b/xmake/toolchains/clang-20/xmake.lua index 446747664..d209a5dae 100644 --- a/xmake/toolchains/clang-20/xmake.lua +++ b/xmake/toolchains/clang-20/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../clang/xmake.lua")) +includes(path.join(os.scriptdir(), "../clang/toolchain_clang.lua")) toolchain_clang("20") diff --git a/xmake/toolchains/clang/toolchain_clang.lua b/xmake/toolchains/clang/toolchain_clang.lua new file mode 100644 index 000000000..c22bd3d75 --- /dev/null +++ b/xmake/toolchains/clang/toolchain_clang.lua @@ -0,0 +1,87 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, Xmake Open Source Community. +-- +-- @author ruki, romeoxbm +-- @file toolchain_clang.lua +-- + +-- define toolchain +function toolchain_clang(version) + local suffix = version and ("-" .. version) or "" + + toolchain("clang" .. suffix) + set_kind("standalone") + set_homepage("https://clang.llvm.org/") + set_description("A C language family frontend for LLVM" .. (version and (" (" .. version .. ")") or "")) + set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared") + + set_toolset("cc", "clang" .. suffix) + set_toolset("cxx", "clang++" .. suffix, "clang" .. suffix) + set_toolset("ld", "clang++" .. suffix, "clang" .. suffix) + set_toolset("sh", "clang++" .. suffix, "clang" .. suffix) + set_toolset("ar", "llvm-ar" .. suffix, "ar") + set_toolset("strip", "llvm-strip" .. suffix, "strip") + set_toolset("ranlib", "llvm-ranlib" .. suffix, "ranlib") + set_toolset("objcopy", "llvm-objcopy" .. suffix, "objcopy") + set_toolset("nm", "llvm-nm" .. suffix, "nm") + set_toolset("mm", "clang" .. suffix) + set_toolset("mxx", "clang++" .. suffix, "clang" .. suffix) + set_toolset("as", "clang" .. suffix) + set_toolset("mrc", "llvm-rc" .. suffix) + set_toolset("dlltool", "llvm-dlltool" .. suffix) + + on_check(function (toolchain) + if toolchain:is_plat("windows") then + local rootdir = path.join(path.directory(os.scriptdir()), "clang") + local result = import("check", {rootdir = rootdir})(toolchain, suffix) + if result then + return result + end + end + + return import("lib.detect.find_tool")("clang", {program = "clang" .. suffix}) + end) + + on_load(function (toolchain) + import("core.project.project") + + if project.policy("build.optimization.lto") then + toolchain:set("toolset", "ar", "llvm-ar" .. suffix) + toolchain:set("toolset", "ranlib", "llvm-ranlib" .. suffix) + end + + local march + if toolchain:is_arch("x86_64", "x64") then + march = "-m64" + elseif toolchain:is_arch("i386", "x86") then + march = "-m32" + end + if march then + toolchain:add("cxflags", march) + toolchain:add("mxflags", march) + toolchain:add("asflags", march) + toolchain:add("ldflags", march) + toolchain:add("shflags", march) + end + if toolchain:is_plat("windows") then + toolchain:add("runtimes", "MT", "MTd", "MD", "MDd") + end + if toolchain:is_plat("windows", "mingw") then + local rootdir = path.join(path.directory(os.scriptdir()), "clang") + import("load", {rootdir = rootdir})(toolchain, suffix) + end + end) +end diff --git a/xmake/toolchains/clang/xmake.lua b/xmake/toolchains/clang/xmake.lua index b454afa86..f9df59779 100644 --- a/xmake/toolchains/clang/xmake.lua +++ b/xmake/toolchains/clang/xmake.lua @@ -18,73 +18,6 @@ -- @file xmake.lua -- --- define toolchain -function toolchain_clang(version) -local suffix = "" -if version then - suffix = suffix .. "-" .. version -end -toolchain("clang" .. suffix) - set_kind("standalone") - set_homepage("https://clang.llvm.org/") - set_description("A C language family frontend for LLVM" .. (version and (" (" .. version .. ")") or "")) - set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared") +includes(path.join(os.scriptdir(), "toolchain_clang.lua")) - set_toolset("cc", "clang" .. suffix) - set_toolset("cxx", "clang++" .. suffix, "clang" .. suffix) - set_toolset("ld", "clang++" .. suffix, "clang" .. suffix) - set_toolset("sh", "clang++" .. suffix, "clang" .. suffix) - set_toolset("ar", "llvm-ar" .. suffix, "ar") - set_toolset("strip", "llvm-strip" .. suffix, "strip") - set_toolset("ranlib", "llvm-ranlib" .. suffix, "ranlib") - set_toolset("objcopy", "llvm-objcopy" .. suffix, "objcopy") - set_toolset("nm", "llvm-nm" .. suffix, "nm") - set_toolset("mm", "clang" .. suffix) - set_toolset("mxx", "clang++" .. suffix, "clang" .. suffix) - set_toolset("as", "clang" .. suffix) - set_toolset("mrc", "llvm-rc" .. suffix) - set_toolset("dlltool", "llvm-dlltool" .. suffix) - - on_check(function (toolchain) - if toolchain:is_plat("windows") then - local rootdir = path.join(path.directory(os.scriptdir()), "clang") - local result = import("check", {rootdir = rootdir})(toolchain, suffix) - if result then - return result - end - end - - return import("lib.detect.find_tool")("clang", {program = "clang" .. suffix}) - end) - - on_load(function (toolchain) - import("core.project.project") - - if project.policy("build.optimization.lto") then - toolchain:set("toolset", "ar", "llvm-ar" .. suffix) - toolchain:set("toolset", "ranlib", "llvm-ranlib" .. suffix) - end - - local march - if toolchain:is_arch("x86_64", "x64") then - march = "-m64" - elseif toolchain:is_arch("i386", "x86") then - march = "-m32" - end - if march then - toolchain:add("cxflags", march) - toolchain:add("mxflags", march) - toolchain:add("asflags", march) - toolchain:add("ldflags", march) - toolchain:add("shflags", march) - end - if toolchain:is_plat("windows") then - toolchain:add("runtimes", "MT", "MTd", "MD", "MDd") - end - if toolchain:is_plat("windows", "mingw") then - local rootdir = path.join(path.directory(os.scriptdir()), "clang") - import("load", {rootdir = rootdir})(toolchain, suffix) - end - end) -end toolchain_clang() diff --git a/xmake/toolchains/gcc-10/xmake.lua b/xmake/toolchains/gcc-10/xmake.lua index b1e2c8883..c94754290 100644 --- a/xmake/toolchains/gcc-10/xmake.lua +++ b/xmake/toolchains/gcc-10/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../gcc/xmake.lua")) +includes(path.join(os.scriptdir(), "../gcc/toolchain_gcc.lua")) toolchain_gcc("10") diff --git a/xmake/toolchains/gcc-11/xmake.lua b/xmake/toolchains/gcc-11/xmake.lua index 2714c7718..8ffda8d7b 100644 --- a/xmake/toolchains/gcc-11/xmake.lua +++ b/xmake/toolchains/gcc-11/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../gcc/xmake.lua")) +includes(path.join(os.scriptdir(), "../gcc/toolchain_gcc.lua")) toolchain_gcc("11") diff --git a/xmake/toolchains/gcc-12/xmake.lua b/xmake/toolchains/gcc-12/xmake.lua index 073a1d64a..9a400417b 100644 --- a/xmake/toolchains/gcc-12/xmake.lua +++ b/xmake/toolchains/gcc-12/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../gcc/xmake.lua")) +includes(path.join(os.scriptdir(), "../gcc/toolchain_gcc.lua")) toolchain_gcc("12") diff --git a/xmake/toolchains/gcc-13/xmake.lua b/xmake/toolchains/gcc-13/xmake.lua index dd2fe8c0a..7935e6df1 100644 --- a/xmake/toolchains/gcc-13/xmake.lua +++ b/xmake/toolchains/gcc-13/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../gcc/xmake.lua")) +includes(path.join(os.scriptdir(), "../gcc/toolchain_gcc.lua")) toolchain_gcc("13") diff --git a/xmake/toolchains/gcc-14/xmake.lua b/xmake/toolchains/gcc-14/xmake.lua index 74be64c59..cc6f29d34 100644 --- a/xmake/toolchains/gcc-14/xmake.lua +++ b/xmake/toolchains/gcc-14/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../gcc/xmake.lua")) +includes(path.join(os.scriptdir(), "../gcc/toolchain_gcc.lua")) toolchain_gcc("14") diff --git a/xmake/toolchains/gcc-15/xmake.lua b/xmake/toolchains/gcc-15/xmake.lua index 1919d4225..56b742362 100644 --- a/xmake/toolchains/gcc-15/xmake.lua +++ b/xmake/toolchains/gcc-15/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../gcc/xmake.lua")) +includes(path.join(os.scriptdir(), "../gcc/toolchain_gcc.lua")) toolchain_gcc("15") diff --git a/xmake/toolchains/gcc-4.8/xmake.lua b/xmake/toolchains/gcc-4.8/xmake.lua index 6519646b1..8695753a8 100644 --- a/xmake/toolchains/gcc-4.8/xmake.lua +++ b/xmake/toolchains/gcc-4.8/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../gcc/xmake.lua")) +includes(path.join(os.scriptdir(), "../gcc/toolchain_gcc.lua")) toolchain_gcc("4.8") diff --git a/xmake/toolchains/gcc-4.9/xmake.lua b/xmake/toolchains/gcc-4.9/xmake.lua index 4b489fa5d..b54c53958 100644 --- a/xmake/toolchains/gcc-4.9/xmake.lua +++ b/xmake/toolchains/gcc-4.9/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../gcc/xmake.lua")) +includes(path.join(os.scriptdir(), "../gcc/toolchain_gcc.lua")) toolchain_gcc("4.9") diff --git a/xmake/toolchains/gcc-8/xmake.lua b/xmake/toolchains/gcc-8/xmake.lua index 716477e01..463ef017e 100644 --- a/xmake/toolchains/gcc-8/xmake.lua +++ b/xmake/toolchains/gcc-8/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../gcc/xmake.lua")) +includes(path.join(os.scriptdir(), "../gcc/toolchain_gcc.lua")) toolchain_gcc("8") diff --git a/xmake/toolchains/gcc-9/xmake.lua b/xmake/toolchains/gcc-9/xmake.lua index d33f396f6..05432d12c 100644 --- a/xmake/toolchains/gcc-9/xmake.lua +++ b/xmake/toolchains/gcc-9/xmake.lua @@ -1,3 +1,3 @@ -includes(path.join(os.scriptdir(), "../gcc/xmake.lua")) +includes(path.join(os.scriptdir(), "../gcc/toolchain_gcc.lua")) toolchain_gcc("9") diff --git a/xmake/toolchains/gcc/toolchain_gcc.lua b/xmake/toolchains/gcc/toolchain_gcc.lua new file mode 100644 index 000000000..caa60c85a --- /dev/null +++ b/xmake/toolchains/gcc/toolchain_gcc.lua @@ -0,0 +1,64 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, Xmake Open Source Community. +-- +-- @author ruki, romeoxbm +-- @file toolchain_gcc.lua +-- + +-- define toolchain +function toolchain_gcc(version) + local suffix = version and ("-" .. version) or "" + + toolchain("gcc" .. suffix) + set_kind("standalone") + set_homepage("https://gcc.gnu.org/") + set_description("GNU Compiler Collection" .. (version and (" (" .. version .. ")") or "")) + set_runtimes("stdc++_static", "stdc++_shared") + + set_toolset("cc", "gcc" .. suffix) + set_toolset("cxx", "g++" .. suffix, "gcc" .. suffix) + set_toolset("ld", "g++" .. suffix, "gcc" .. suffix) + set_toolset("sh", "g++" .. suffix, "gcc" .. suffix) + set_toolset("ar", "ar") + set_toolset("strip", "strip") + set_toolset("objcopy", "objcopy") + set_toolset("ranlib", "ranlib") + set_toolset("mm", "gcc" .. suffix) + set_toolset("mxx", "g++" .. suffix, "gcc" .. suffix) + set_toolset("as", "gcc" .. suffix) + + on_check(function (toolchain) + return import("lib.detect.find_tool")("gcc", {program = "gcc" .. suffix}) + end) + + on_load(function (toolchain) + + -- add march flags + local march + if toolchain:is_arch("x86_64", "x64") then + march = "-m64" + elseif toolchain:is_arch("i386", "x86") then + march = "-m32" + end + if march then + toolchain:add("cxflags", march) + toolchain:add("mxflags", march) + toolchain:add("asflags", march) + toolchain:add("ldflags", march) + toolchain:add("shflags", march) + end + end) +end diff --git a/xmake/toolchains/gcc/xmake.lua b/xmake/toolchains/gcc/xmake.lua index 502f10c3b..e478e4712 100644 --- a/xmake/toolchains/gcc/xmake.lua +++ b/xmake/toolchains/gcc/xmake.lua @@ -17,51 +17,6 @@ -- @author ruki -- @file xmake.lua -- +includes(path.join(os.scriptdir(), "toolchain_gcc.lua")) --- define toolchain -function toolchain_gcc(version) -local suffix = "" -if version then - suffix = suffix .. "-" .. version -end -toolchain("gcc" .. suffix) - set_kind("standalone") - set_homepage("https://gcc.gnu.org/") - set_description("GNU Compiler Collection" .. (version and (" (" .. version .. ")") or "")) - set_runtimes("stdc++_static", "stdc++_shared") - - set_toolset("cc", "gcc" .. suffix) - set_toolset("cxx", "g++" .. suffix, "gcc" .. suffix) - set_toolset("ld", "g++" .. suffix, "gcc" .. suffix) - set_toolset("sh", "g++" .. suffix, "gcc" .. suffix) - set_toolset("ar", "ar") - set_toolset("strip", "strip") - set_toolset("objcopy", "objcopy") - set_toolset("ranlib", "ranlib") - set_toolset("mm", "gcc" .. suffix) - set_toolset("mxx", "g++" .. suffix, "gcc" .. suffix) - set_toolset("as", "gcc" .. suffix) - - on_check(function (toolchain) - return import("lib.detect.find_tool")("gcc", {program = "gcc" .. suffix}) - end) - - on_load(function (toolchain) - - -- add march flags - local march - if toolchain:is_arch("x86_64", "x64") then - march = "-m64" - elseif toolchain:is_arch("i386", "x86") then - march = "-m32" - end - if march then - toolchain:add("cxflags", march) - toolchain:add("mxflags", march) - toolchain:add("asflags", march) - toolchain:add("ldflags", march) - toolchain:add("shflags", march) - end - end) -end toolchain_gcc() |
