diff options
| author | ruki <[email protected]> | 2025-12-20 00:27:27 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-20 00:27:27 +0800 |
| commit | 50e52b0aa88b409f65181b8a6607427c8e17a28d (patch) | |
| tree | 8a972a4b311b310c8ba5f030b8b18dfe93b6dc07 | |
| parent | dee8082d12241d69cf370c7f566c48c0ca8827bd (diff) | |
| parent | 4cb4b4e691ec53a7af6af9a862d332377fcd4ffe (diff) | |
Merge pull request #7152 from xmake-io/runtimes
Fix clang runtimes and improve toolchains
36 files changed, 256 insertions, 436 deletions
diff --git a/tests/projects/c++/modules/test_base.lua b/tests/projects/c++/modules/test_base.lua index 466a59e98..6f2a42088 100644 --- a/tests/projects/c++/modules/test_base.lua +++ b/tests/projects/c++/modules/test_base.lua @@ -95,7 +95,8 @@ function build_tests(toolchain_name, opt) if opt.runtimes then runtimes = " --runtimes=" .. opt.runtimes .. " " end - print("running with config: (toolchain: %s, compiler: %s, version: %s, runtimes: %s, stdmodule: %s, fallback scanner: %s, two phases: %s)", toolchain_name, compiler, version, opt.runtimes or "default", opt.stdmodule or false, opt.fallbackscanner or false, two_phases) + print("running with config: (toolchain: %s, compiler: %s, version: %s, runtimes: %s, stdmodule: %s, fallback scanner: %s, two phases: %s)", + toolchain_name, compiler, version, opt.runtimes or "default", opt.stdmodule or false, opt.fallbackscanner or false, two_phases) local flags = "" if opt.flags then diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 9fb765f21..90efb3751 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -546,7 +546,8 @@ function _finish_requireinfo(requireinfo, package) else runtimes = {} end - if not table.contains(runtimes, "MT", "MD", "MTd", "MDd") then + -- we should not set default runtimes if runtimes has been set, e.g. `xmake f --toolchain=clang --runtimes=c++_shared` + if #runtimes == 0 then local vs_runtime_default = project.policy("build.c++.msvc.runtime") if vs_runtime_default and is_mode("debug") then vs_runtime_default = vs_runtime_default .. "d" diff --git a/xmake/modules/private/utils/toolchain.lua b/xmake/modules/private/utils/toolchain.lua index 49af8193f..29036a2c2 100644 --- a/xmake/modules/private/utils/toolchain.lua +++ b/xmake/modules/private/utils/toolchain.lua @@ -91,6 +91,63 @@ function check_vstudio(toolchain, check) return vs end +-- add the given vs environment +function _add_vsenv(toolchain, name, curenvs) + + -- get vcvars + local vcvars = toolchain:config("vcvars") + if not vcvars then + return + end + + -- get the paths for the vs environment + local new = vcvars[name] + if new then + -- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. + -- @see https://github.com/xmake-io/xmake/issues/4751 + for k, c in pairs(curenvs) do + if name:lower() == k:lower() and name ~= k then + name = k + break + end + end + -- msvc-wine on linux + if (name == "INCLUDE" or name == "LIB") and not is_host("windows") then + toolchain:add("runenvs", name, path.joinenv(path.splitenv(new), ";")) + else + toolchain:add("runenvs", name, table.unwrap(path.splitenv(new))) + end + end +end + +-- add vs environments +function add_vsenvs(toolchain, expect_vars) + local curenvs = os.getenvs() + expect_vars = expect_vars or {"PATH", "LIB", "INCLUDE", "LIBPATH"} + for _, name in ipairs(expect_vars) do + _add_vsenv(toolchain, name, curenvs) + end + for _, name in ipairs(find_vstudio.get_vcvars()) do + if not table.contains(expect_vars, name:upper()) then + _add_vsenv(toolchain, name, curenvs) + end + end +end + +-- set llvm runtimes +function set_llvm_runtimes(toolchain) + -- We should set them up uniformly here, because runtimes will be accessed early (in sanitizer), + -- which automatically triggers lazy loading of the toolchain. + -- However, if some runtime configurations are set in advance in the descriptor scope, + -- lazy loading will not be triggered when the runtimes are accessed, and some Windows runtimes may be lost. + -- + -- @see https://github.com/xmake-io/xmake/pull/7146#issuecomment-3674402132 + toolchain:set("runtimes", "c++_static", "c++_shared", "stdc++_static", "stdc++_shared") + if toolchain:is_plat("windows") then + toolchain:add("runtimes", "MT", "MTd", "MD", "MDd") + end +end + -- check vc build tools sdk function check_vc_build_tools(toolchain, sdkdir, check) local opt = {} @@ -367,5 +424,3 @@ function add_llvm_runenvs(toolchain) end end end - - diff --git a/xmake/toolchains/clang-12/xmake.lua b/xmake/toolchains/clang-12/xmake.lua index d7c143451..7de29a968 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/toolchain_clang.lua")) +includes(path.join(os.scriptdir(), "../clang")) toolchain_clang("12") diff --git a/xmake/toolchains/clang-13/xmake.lua b/xmake/toolchains/clang-13/xmake.lua index 779a98d9d..8593959ba 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/toolchain_clang.lua")) +includes(path.join(os.scriptdir(), "../clang")) toolchain_clang("13") diff --git a/xmake/toolchains/clang-14/xmake.lua b/xmake/toolchains/clang-14/xmake.lua index a0809f3d8..6b77e2d56 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/toolchain_clang.lua")) +includes(path.join(os.scriptdir(), "../clang")) toolchain_clang("14") diff --git a/xmake/toolchains/clang-15/xmake.lua b/xmake/toolchains/clang-15/xmake.lua index fcff4cdf4..30fbec00a 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/toolchain_clang.lua")) +includes(path.join(os.scriptdir(), "../clang")) toolchain_clang("15") diff --git a/xmake/toolchains/clang-16/xmake.lua b/xmake/toolchains/clang-16/xmake.lua index ba01bee44..baf2f8cbe 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/toolchain_clang.lua")) +includes(path.join(os.scriptdir(), "../clang")) toolchain_clang("16") diff --git a/xmake/toolchains/clang-17/xmake.lua b/xmake/toolchains/clang-17/xmake.lua index 9303295a5..28e4f547c 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/toolchain_clang.lua")) +includes(path.join(os.scriptdir(), "../clang")) toolchain_clang("17") diff --git a/xmake/toolchains/clang-18/xmake.lua b/xmake/toolchains/clang-18/xmake.lua index f1aa1d987..274da52d2 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/toolchain_clang.lua")) +includes(path.join(os.scriptdir(), "../clang")) toolchain_clang("18") diff --git a/xmake/toolchains/clang-19/xmake.lua b/xmake/toolchains/clang-19/xmake.lua index a1f89fea2..9710fa3bf 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/toolchain_clang.lua")) +includes(path.join(os.scriptdir(), "../clang")) toolchain_clang("19") diff --git a/xmake/toolchains/clang-20/xmake.lua b/xmake/toolchains/clang-20/xmake.lua index d209a5dae..49c40341a 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/toolchain_clang.lua")) +includes(path.join(os.scriptdir(), "../clang")) toolchain_clang("20") diff --git a/xmake/toolchains/clang-21/xmake.lua b/xmake/toolchains/clang-21/xmake.lua new file mode 100644 index 000000000..4fd3af636 --- /dev/null +++ b/xmake/toolchains/clang-21/xmake.lua @@ -0,0 +1,3 @@ +includes(path.join(os.scriptdir(), "../clang")) + +toolchain_clang("21") diff --git a/xmake/toolchains/clang-cl/load.lua b/xmake/toolchains/clang-cl/load.lua index a8e3ed199..f445c0739 100644 --- a/xmake/toolchains/clang-cl/load.lua +++ b/xmake/toolchains/clang-cl/load.lua @@ -21,32 +21,8 @@ -- imports import("core.base.option") import("core.project.config") -import("detect.sdks.find_vstudio") import("core.project.project") - --- add the given vs environment -function _add_vsenv(toolchain, name, curenvs) - - -- get vcvars - local vcvars = toolchain:config("vcvars") - if not vcvars then - return - end - - -- get the paths for the vs environment - local new = vcvars[name] - if new then - -- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. - -- @see https://github.com/xmake-io/xmake/issues/4751 - for k, c in pairs(curenvs) do - if name:lower() == k:lower() and name ~= k then - name = k - break - end - end - toolchain:add("runenvs", name, table.unwrap(path.splitenv(new))) - end -end +import("private.utils.toolchain", {alias = "toolchain_utils"}) -- main entry function main(toolchain) @@ -76,16 +52,7 @@ function main(toolchain) end -- add vs environments - local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"} - local curenvs = os.getenvs() - for _, name in ipairs(expect_vars) do - _add_vsenv(toolchain, name, curenvs) - end - for _, name in ipairs(find_vstudio.get_vcvars()) do - if not table.contains(expect_vars, name:upper()) then - _add_vsenv(toolchain, name, curenvs) - end - end + toolchain_utils.add_vsenvs(toolchain) local target if toolchain:is_arch("x86_64", "x64") then diff --git a/xmake/toolchains/clang/check.lua b/xmake/toolchains/clang/check.lua index 107410a0b..145805547 100644 --- a/xmake/toolchains/clang/check.lua +++ b/xmake/toolchains/clang/check.lua @@ -36,7 +36,7 @@ function _check_clang(toolchain, vcvars, suffix) return result end -function main(toolchain, suffix) +function _check_for_windows(toolchain, suffix) -- only for windows or linux (msvc-wine) if not is_host("windows", "linux") then @@ -68,3 +68,10 @@ function main(toolchain, suffix) end end +function main(toolchain, suffix) + if toolchain:is_plat("windows") then + return _check_for_windows(toolchain, suffix) + end + return find_tool("clang", {program = "clang" .. suffix}) +end + diff --git a/xmake/toolchains/clang/load.lua b/xmake/toolchains/clang/load.lua index 3c50e3be2..ba4dbfe94 100644 --- a/xmake/toolchains/clang/load.lua +++ b/xmake/toolchains/clang/load.lua @@ -18,86 +18,94 @@ -- @file xmake.lua -- -import("detect.sdks.find_vstudio") import("detect.sdks.find_mingw") import("core.project.config") +import("core.project.project") import("private.utils.toolchain", {alias = "toolchain_utils"}) --- add the given vs environment -function _add_vsenv(toolchain, name, curenvs) +function _load_windows(toolchain, suffix) - -- get vcvars - local vcvars = toolchain:config("vcvars") - if not vcvars then - return - end + -- add vs environments + toolchain_utils.add_vsenvs(toolchain) - -- get the paths for the vs environment - local new = vcvars[name] - if new then - -- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. - -- @see https://github.com/xmake-io/xmake/issues/4751 - for k, c in pairs(curenvs) do - if name:lower() == k:lower() and name ~= k then - name = k - break - end - end - if name == "INCLUDE" or name == "LIB" then - toolchain:add("runenvs", name, table.concat(path.splitenv(new), ";")) - else - toolchain:add("runenvs", name, table.unwrap(path.splitenv(new))) - end + if is_host("linux") or project.policy("build.optimization.lto") then + toolchain:add("ldflags", "-fuse-ld=lld-link" .. suffix) + toolchain:add("shflags", "-fuse-ld=lld-link" .. suffix) end end -function main(toolchain, suffix) - import("core.project.project") +function _get_target(toolchain) + -- TODO + -- Perhaps in the future we will improve it and allow setting targets on more platforms. + if not toolchain:is_plat("windows", "mingw") then + return + end local target if toolchain:is_arch("x86_64", "x64") then target = "x86_64" - march = "-m64" elseif toolchain:is_arch("i386", "x86", "i686") then target = "i686" - march = "-m32" - elseif toolchain:is_arch("arm64", "aarch64") then + elseif toolchain:is_arch("arm64", "aarch64", "arm64-v8a") then target = "aarch64" - elseif toolchain:is_arch("arm") then + elseif toolchain:is_arch("arm.*") then target = "armv7" end - if toolchain:is_plat("windows") then - target = target .. "-windows-msvc" - - -- add vs environments - local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"} - local curenvs = os.getenvs() - for _, name in ipairs(expect_vars) do - _add_vsenv(toolchain, name, curenvs) - end - for _, name in ipairs(find_vstudio.get_vcvars()) do - if not table.contains(expect_vars, name:upper()) then - _add_vsenv(toolchain, name, curenvs) - end - end - - if is_host("linux") or project.policy("build.optimization.lto") then - toolchain:add("ldflags", "-fuse-ld=lld-link" .. suffix) - toolchain:add("shflags", "-fuse-ld=lld-link" .. suffix) + if target then + if toolchain:is_plat("windows") then + target = target .. "-windows-msvc" + elseif toolchain:is_plat("mingw") then + target = target .. "-w64-windows-gnu" + elseif toolchain:is_plat("linux") then + target = target .. "-linux-gnu" + else + target = nil end - elseif toolchain:is_plat("mingw") then - target = target .. "-w64-windows-gnu" - elseif toolchain:is_plat("linux") then - target = target .. "-linux-gnu" end + return target +end - toolchain_utils.add_llvm_runenvs(toolchain) +function main(toolchain, suffix) + -- init tools for lto + if project.policy("build.optimization.lto") then + toolchain:set("toolset", "ar", "llvm-ar" .. suffix) + toolchain:set("toolset", "ranlib", "llvm-ranlib" .. suffix) + end + + -- init target + local target = _get_target(toolchain) if target then toolchain:add("cxflags", "--target=" .. target) + toolchain:add("mxflags", "--target=" .. target) toolchain:add("asflags", "--target=" .. target) toolchain:add("ldflags", "--target=" .. target) toolchain:add("shflags", "--target=" .. target) + else + 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 + + -- init windows + if toolchain:is_plat("windows") then + _load_windows(toolchain, suffix) end + + -- set llvm runtimes + toolchain_utils.set_llvm_runtimes(toolchain) + + -- add llvm runenvs + toolchain_utils.add_llvm_runenvs(toolchain) end diff --git a/xmake/toolchains/clang/toolchain_clang.lua b/xmake/toolchains/clang/toolchain_clang.lua deleted file mode 100644 index b1e59356f..000000000 --- a/xmake/toolchains/clang/toolchain_clang.lua +++ /dev/null @@ -1,90 +0,0 @@ ---!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) - if is_host("macosx") then - set_toolset("dsymutil", "dsymutil") - end - - 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 f9df59779..de6b9a211 100644 --- a/xmake/toolchains/clang/xmake.lua +++ b/xmake/toolchains/clang/xmake.lua @@ -18,6 +18,39 @@ -- @file xmake.lua -- -includes(path.join(os.scriptdir(), "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_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) + if is_host("macosx") then + set_toolset("dsymutil", "dsymutil") + end + + on_check(function (toolchain) + return import("toolchains.clang.check", {rootdir = os.programdir()})(toolchain, suffix) + end) + + on_load(function (toolchain) + import("toolchains.clang.load", {rootdir = os.programdir()})(toolchain, suffix) + end) +end toolchain_clang() diff --git a/xmake/toolchains/gcc-10/xmake.lua b/xmake/toolchains/gcc-10/xmake.lua index c94754290..8f18c9ffb 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/toolchain_gcc.lua")) +includes(path.join(os.scriptdir(), "../gcc")) toolchain_gcc("10") diff --git a/xmake/toolchains/gcc-11/xmake.lua b/xmake/toolchains/gcc-11/xmake.lua index 8ffda8d7b..713c105bd 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/toolchain_gcc.lua")) +includes(path.join(os.scriptdir(), "../gcc")) toolchain_gcc("11") diff --git a/xmake/toolchains/gcc-12/xmake.lua b/xmake/toolchains/gcc-12/xmake.lua index 9a400417b..9eb2a6dae 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/toolchain_gcc.lua")) +includes(path.join(os.scriptdir(), "../gcc")) toolchain_gcc("12") diff --git a/xmake/toolchains/gcc-13/xmake.lua b/xmake/toolchains/gcc-13/xmake.lua index 7935e6df1..ba45c0f0e 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/toolchain_gcc.lua")) +includes(path.join(os.scriptdir(), "../gcc")) toolchain_gcc("13") diff --git a/xmake/toolchains/gcc-14/xmake.lua b/xmake/toolchains/gcc-14/xmake.lua index cc6f29d34..266894d5b 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/toolchain_gcc.lua")) +includes(path.join(os.scriptdir(), "../gcc")) toolchain_gcc("14") diff --git a/xmake/toolchains/gcc-15/xmake.lua b/xmake/toolchains/gcc-15/xmake.lua index 56b742362..08bf4cd9e 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/toolchain_gcc.lua")) +includes(path.join(os.scriptdir(), "../gcc")) toolchain_gcc("15") diff --git a/xmake/toolchains/gcc-4.8/xmake.lua b/xmake/toolchains/gcc-4.8/xmake.lua index 8695753a8..9b51b85f7 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/toolchain_gcc.lua")) +includes(path.join(os.scriptdir(), "../gcc")) toolchain_gcc("4.8") diff --git a/xmake/toolchains/gcc-4.9/xmake.lua b/xmake/toolchains/gcc-4.9/xmake.lua index b54c53958..89e7cdae1 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/toolchain_gcc.lua")) +includes(path.join(os.scriptdir(), "../gcc")) toolchain_gcc("4.9") diff --git a/xmake/toolchains/gcc-8/xmake.lua b/xmake/toolchains/gcc-8/xmake.lua index 463ef017e..b6bb9e55b 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/toolchain_gcc.lua")) +includes(path.join(os.scriptdir(), "../gcc")) toolchain_gcc("8") diff --git a/xmake/toolchains/gcc-9/xmake.lua b/xmake/toolchains/gcc-9/xmake.lua index 05432d12c..21bd4d436 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/toolchain_gcc.lua")) +includes(path.join(os.scriptdir(), "../gcc")) toolchain_gcc("9") diff --git a/xmake/toolchains/gcc/toolchain_gcc.lua b/xmake/toolchains/gcc/toolchain_gcc.lua deleted file mode 100644 index caa60c85a..000000000 --- a/xmake/toolchains/gcc/toolchain_gcc.lua +++ /dev/null @@ -1,64 +0,0 @@ ---!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 e478e4712..1b4a971f4 100644 --- a/xmake/toolchains/gcc/xmake.lua +++ b/xmake/toolchains/gcc/xmake.lua @@ -17,6 +17,49 @@ -- @author ruki -- @file xmake.lua -- -includes(path.join(os.scriptdir(), "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 toolchain_gcc() diff --git a/xmake/toolchains/icc/load.lua b/xmake/toolchains/icc/load.lua index 7bae8a9d1..20b7daa82 100644 --- a/xmake/toolchains/icc/load.lua +++ b/xmake/toolchains/icc/load.lua @@ -21,31 +21,7 @@ -- imports import("core.base.option") import("core.project.config") -import("detect.sdks.find_vstudio") - --- add the given vs environment -function _add_vsenv(toolchain, name, curenvs) - - -- get vcvars - local vcvars = toolchain:config("vcvars") - if not vcvars then - return - end - - -- get the paths for the vs environment - local new = vcvars[name] - if new then - -- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. - -- @see https://github.com/xmake-io/xmake/issues/4751 - for k, c in pairs(curenvs) do - if name:lower() == k:lower() and name ~= k then - name = k - break - end - end - toolchain:add("runenvs", name, table.unpack(path.splitenv(new))) - end -end +import("private.utils.toolchain", {alias = "toolchain_utils"}) -- add the given icl environment function _add_iclenv(toolchain, name, curenvs) @@ -101,18 +77,15 @@ function _load_intel_on_windows(toolchain) toolchain:set("toolset", "as", "icc") end - -- add vs/icl environments + -- add vs environments + toolchain_utils.add_vsenvs(toolchain) + + -- add icl environments local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"} local curenvs = os.getenvs() for _, name in ipairs(expect_vars) do - _add_vsenv(toolchain, name, curenvs) _add_iclenv(toolchain, name, curenvs) end - for _, name in ipairs(find_vstudio.get_vcvars()) do - if not table.contains(expect_vars, name:upper()) then - _add_vsenv(toolchain, name, curenvs) - end - end end -- load intel on linux diff --git a/xmake/toolchains/icx/load.lua b/xmake/toolchains/icx/load.lua index cd3064676..f91bd5348 100644 --- a/xmake/toolchains/icx/load.lua +++ b/xmake/toolchains/icx/load.lua @@ -21,31 +21,7 @@ -- imports import("core.base.option") import("core.project.config") -import("detect.sdks.find_vstudio") - --- add the given vs environment -function _add_vsenv(toolchain, name, curenvs) - - -- get vcvars - local vcvars = toolchain:config("vcvars") - if not vcvars then - return - end - - -- get the paths for the vs environment - local new = vcvars[name] - if new then - -- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. - -- @see https://github.com/xmake-io/xmake/issues/4751 - for k, c in pairs(curenvs) do - if name:lower() == k:lower() and name ~= k then - name = k - break - end - end - toolchain:add("runenvs", name, table.unpack(path.splitenv(new))) - end -end +import("private.utils.toolchain", {alias = "toolchain_utils"}) -- add the given icx environment function _add_icxenv(toolchain, name, curenvs) @@ -101,18 +77,15 @@ function _load_intel_on_windows(toolchain) toolchain:set("toolset", "as", "icx") end - -- add vs/icx environments + -- add vs environments + toolchain_utils.add_vsenvs(toolchain) + + -- add icx environments local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"} local curenvs = os.getenvs() for _, name in ipairs(expect_vars) do - _add_vsenv(toolchain, name, curenvs) _add_icxenv(toolchain, name, curenvs) end - for _, name in ipairs(find_vstudio.get_vcvars()) do - if not table.contains(expect_vars, name:upper()) then - _add_vsenv(toolchain, name, curenvs) - end - end end -- load intel on linux diff --git a/xmake/toolchains/ifort/load.lua b/xmake/toolchains/ifort/load.lua index 8593b2399..602e0d3b0 100644 --- a/xmake/toolchains/ifort/load.lua +++ b/xmake/toolchains/ifort/load.lua @@ -21,31 +21,7 @@ -- imports import("core.base.option") import("core.project.config") -import("detect.sdks.find_vstudio") - --- add the given vs environment -function _add_vsenv(toolchain, name, curenvs) - - -- get vcvars - local vcvars = toolchain:config("vcvars") - if not vcvars then - return - end - - -- get the paths for the vs environment - local new = vcvars[name] - if new then - -- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. - -- @see https://github.com/xmake-io/xmake/issues/4751 - for k, c in pairs(curenvs) do - if name:lower() == k:lower() and name ~= k then - name = k - break - end - end - toolchain:add("runenvs", name, table.unpack(path.splitenv(new))) - end -end +import("private.utils.toolchain", {alias = "toolchain_utils"}) -- add the given ifort environment function _add_ifortenv(toolchain, name, curenvs) @@ -90,18 +66,15 @@ function _load_intel_on_windows(toolchain) toolchain:set("toolset", "fcsh", "ifort.exe") toolchain:set("toolset", "ar", "link.exe") - -- add ifort and vs environments + -- add vs environments + toolchain_utils.add_vsenvs(toolchain) + + -- add ifort environments local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"} local curenvs = os.getenvs() for _, name in ipairs(expect_vars) do - _add_vsenv(toolchain, name, curenvs) _add_ifortenv(toolchain, name, curenvs) end - for _, name in ipairs(find_vstudio.get_vcvars()) do - if not table.contains(expect_vars, name:upper()) then - _add_vsenv(toolchain, name, curenvs) - end - end end -- load intel on linux diff --git a/xmake/toolchains/ifx/load.lua b/xmake/toolchains/ifx/load.lua index 31fbd3ae5..be2a48129 100644 --- a/xmake/toolchains/ifx/load.lua +++ b/xmake/toolchains/ifx/load.lua @@ -21,31 +21,7 @@ -- imports import("core.base.option") import("core.project.config") -import("detect.sdks.find_vstudio") - --- add the given vs environment -function _add_vsenv(toolchain, name, curenvs) - - -- get vcvars - local vcvars = toolchain:config("vcvars") - if not vcvars then - return - end - - -- get the paths for the vs environment - local new = vcvars[name] - if new then - -- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. - -- @see https://github.com/xmake-io/xmake/issues/4751 - for k, c in pairs(curenvs) do - if name:lower() == k:lower() and name ~= k then - name = k - break - end - end - toolchain:add("runenvs", name, table.unpack(path.splitenv(new))) - end -end +import("private.utils.toolchain", {alias = "toolchain_utils"}) -- add the given ifx environment function _add_ifxenv(toolchain, name, curenvs) @@ -90,18 +66,15 @@ function _load_intel_on_windows(toolchain) toolchain:set("toolset", "fcsh", "ifx.exe") toolchain:set("toolset", "ar", "link.exe") - -- add vs/ifx environments + -- add vs environments + toolchain_utils.add_vsenvs(toolchain) + + -- add ifx environments local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"} local curenvs = os.getenvs() for _, name in ipairs(expect_vars) do - _add_vsenv(toolchain, name, curenvs) _add_ifxenv(toolchain, name, curenvs) end - for _, name in ipairs(find_vstudio.get_vcvars()) do - if not table.contains(expect_vars, name:upper()) then - _add_vsenv(toolchain, name, curenvs) - end - end end -- load intel on linux diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua index b8f37bec1..4a89b4f32 100644 --- a/xmake/toolchains/llvm/xmake.lua +++ b/xmake/toolchains/llvm/xmake.lua @@ -22,7 +22,6 @@ toolchain("llvm") set_kind("standalone") set_homepage("https://llvm.org/") set_description("A collection of modular and reusable compiler and toolchain technologies") - set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared") set_toolset("cc", "clang") set_toolset("cxx", "clang++", "clang") @@ -52,10 +51,8 @@ toolchain("llvm") on_load(function (toolchain) import("private.utils.toolchain", {alias = "toolchain_utils"}) - -- add runtimes - if toolchain:is_plat("windows") then - toolchain:add("runtimes", "MT", "MTd", "MD", "MDd") - end + -- set llvm runtimes + toolchain_utils.set_llvm_runtimes(toolchain) -- add llvm runenvs toolchain_utils.add_llvm_runenvs(toolchain) diff --git a/xmake/toolchains/msvc/load.lua b/xmake/toolchains/msvc/load.lua index 4f6aab45d..c606a0edc 100644 --- a/xmake/toolchains/msvc/load.lua +++ b/xmake/toolchains/msvc/load.lua @@ -22,31 +22,7 @@ import("core.base.option") import("core.base.semver") import("core.project.config") -import("detect.sdks.find_vstudio") - --- add the given vs environment -function _add_vsenv(toolchain, name, curenvs) - - -- get vcvars - local vcvars = toolchain:config("vcvars") - if not vcvars then - return - end - - -- get the paths for the vs environment - local new = vcvars[name] - if new then - -- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. - -- @see https://github.com/xmake-io/xmake/issues/4751 - for k, c in pairs(curenvs) do - if name:lower() == k:lower() and name ~= k then - name = k - break - end - end - toolchain:add("runenvs", name, table.unwrap(path.splitenv(new))) - end -end +import("private.utils.toolchain", {alias = "toolchain_utils"}) -- main entry function main(toolchain) @@ -74,16 +50,7 @@ function main(toolchain) end -- add vs environments - local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"} - local curenvs = os.getenvs() - for _, name in ipairs(expect_vars) do - _add_vsenv(toolchain, name, curenvs) - end - for _, name in ipairs(find_vstudio.get_vcvars()) do - if not table.contains(expect_vars, name:upper()) then - _add_vsenv(toolchain, name, curenvs) - end - end + toolchain_utils.add_vsenvs(toolchain) -- check and add vs_binary_output env local vs = toolchain:config("vs") |
