From 5c1dde0048109547f843cf9302cd553ad3375344 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 May 2024 12:25:49 +0800 Subject: continue to use ar instead of gcc-ar --- xmake/modules/core/tools/gcc_ar.lua | 22 ---------------------- xmake/toolchains/cross/load.lua | 4 ++-- xmake/toolchains/gnu-rm/xmake.lua | 9 --------- 3 files changed, 2 insertions(+), 33 deletions(-) diff --git a/xmake/modules/core/tools/gcc_ar.lua b/xmake/modules/core/tools/gcc_ar.lua index f6834a20c..ecfdca92a 100644 --- a/xmake/modules/core/tools/gcc_ar.lua +++ b/xmake/modules/core/tools/gcc_ar.lua @@ -20,25 +20,3 @@ inherit("ar") --- make the link arguments list --- @see https://github.com/xmake-io/xmake/issues/5051 --- @note gcc-ar.exe does not support `gcc-ar.exe @file` -function linkargv(self, objectfiles, targetkind, targetfile, flags, opt) - local argv = table.join(flags, targetfile, objectfiles) - return self:program(), argv -end - --- link the library file -function link(self, objectfiles, targetkind, targetfile, flags, opt) - opt = opt or {} - os.mkdir(path.directory(targetfile)) - - -- @note remove the previous archived file first to force recreating a new file - os.tryrm(targetfile) - - -- link it - local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags, opt) - os.runv(program, argv, {envs = self:runenvs(), shell = opt.shell}) -end - - diff --git a/xmake/toolchains/cross/load.lua b/xmake/toolchains/cross/load.lua index f34b1fd58..540d12111 100644 --- a/xmake/toolchains/cross/load.lua +++ b/xmake/toolchains/cross/load.lua @@ -39,8 +39,8 @@ function main(toolchain) toolchain:add("toolset", "ld", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") toolchain:add("toolset", "sh", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") -- old gcc need gcc-ar for lto, @see https://github.com/xmake-io/xmake/issues/5015 - toolchain:add("toolset", "ar", cross .. "gcc-ar", cross .. "ar") - toolchain:add("toolset", "ranlib", cross .. "gcc-ranlib", cross .. "ranlib") + toolchain:add("toolset", "ar", cross .. "ar") + toolchain:add("toolset", "ranlib", cross .. "ranlib") toolchain:add("toolset", "strip", cross .. "strip") -- add bin search library for loading some dependent .dll files windows diff --git a/xmake/toolchains/gnu-rm/xmake.lua b/xmake/toolchains/gnu-rm/xmake.lua index 4a1751172..c6cf822a2 100644 --- a/xmake/toolchains/gnu-rm/xmake.lua +++ b/xmake/toolchains/gnu-rm/xmake.lua @@ -18,23 +18,14 @@ -- @file xmake.lua -- --- define toolchain toolchain("gnu-rm") - - -- set homepage set_homepage("https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm") set_description("GNU Arm Embedded Toolchain") - - -- mark as cross-complation toolchain set_kind("cross") - -- on load on_load(function (toolchain) - - -- load basic configuration of cross toolchain toolchain:load_cross_toolchain() - -- add basic flags toolchain:add("ldflags", "--specs=nosys.specs", "--specs=nano.specs", {force = true}) toolchain:add("shflags", "--specs=nosys.specs", "--specs=nano.specs", {force = true}) toolchain:add("syslinks", "c", "m") -- cgit v1.3.1 From 32bb7f1cfaa79fdd12ca24d4f46ec8cb57143ee5 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 May 2024 13:45:50 +0800 Subject: add lto plugin for gcc --- xmake/rules/c++/build_optimization/config.lua | 32 ++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/xmake/rules/c++/build_optimization/config.lua b/xmake/rules/c++/build_optimization/config.lua index 6baa26802..f252f78c7 100644 --- a/xmake/rules/c++/build_optimization/config.lua +++ b/xmake/rules/c++/build_optimization/config.lua @@ -21,6 +21,28 @@ -- imports import("core.tool.compiler") import("core.project.project") +import("lib.detect.find_file") + +-- get liblto_plugin.so path of gcc +function _get_gcc_liblto_plugin_path(target, gcc) + local cachekey = "lto_plugin_" .. gcc + local plugin_path = target:data(cachekey) + if plugin_path == nil then + local outdata = try { function() return os.iorunv(gcc, {"-print-prog-name=lto-wrapper"}) end } + if outdata then + local lto_plugindir = path.directory(outdata:trim()) + if os.isdir(lto_plugindir) then + if is_host("windows") then + plugin_path = find_file("liblto_plugin*.dll", lto_plugindir) + else + plugin_path = find_file("liblto_plugin.so", lto_plugindir) + end + end + end + target:data_set(cachekey, plugin_path or false) + end + return plugin_path or nil +end -- add lto optimization function _add_lto_optimization(target, sourcekind) @@ -37,7 +59,7 @@ function _add_lto_optimization(target, sourcekind) end -- add ldflags and shflags - local _, ld = target:tool("ld") + local program, ld = target:tool("ld") if ld == "link" then target:add("ldflags", "-LTCG") target:add("shflags", "-LTCG") @@ -47,6 +69,14 @@ function _add_lto_optimization(target, sourcekind) elseif ld == "gcc" or ld == "gxx" then target:add("ldflags", "-flto") target:add("shflags", "-flto") + + -- @see https://github.com/xmake-io/xmake/issues/5015 + -- add lto_plugin.so to ar + local lto_plugin = _get_gcc_liblto_plugin_path(target, program) + if lto_plugin then + target:add("arflags", {"--plugin", lto_plugin}, {force = true, expand = false}) + end + -- to use the link-time optimizer, -flto and optimization options should be specified at compile time and during the final link. -- @see https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html local optimize = target:get("optimize") -- cgit v1.3.1 From 6b447fe2a874c79cc681daf8c7d934ad10da7a22 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 May 2024 16:11:10 +0800 Subject: load lto plugin --- xmake/rules/c++/build_optimization/config.lua | 29 -------------------------- xmake/toolchains/cross/check.lua | 30 +++++++++++++++++++++++++++ xmake/toolchains/cross/load.lua | 11 +++++++--- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/xmake/rules/c++/build_optimization/config.lua b/xmake/rules/c++/build_optimization/config.lua index f252f78c7..357c3cf76 100644 --- a/xmake/rules/c++/build_optimization/config.lua +++ b/xmake/rules/c++/build_optimization/config.lua @@ -21,28 +21,6 @@ -- imports import("core.tool.compiler") import("core.project.project") -import("lib.detect.find_file") - --- get liblto_plugin.so path of gcc -function _get_gcc_liblto_plugin_path(target, gcc) - local cachekey = "lto_plugin_" .. gcc - local plugin_path = target:data(cachekey) - if plugin_path == nil then - local outdata = try { function() return os.iorunv(gcc, {"-print-prog-name=lto-wrapper"}) end } - if outdata then - local lto_plugindir = path.directory(outdata:trim()) - if os.isdir(lto_plugindir) then - if is_host("windows") then - plugin_path = find_file("liblto_plugin*.dll", lto_plugindir) - else - plugin_path = find_file("liblto_plugin.so", lto_plugindir) - end - end - end - target:data_set(cachekey, plugin_path or false) - end - return plugin_path or nil -end -- add lto optimization function _add_lto_optimization(target, sourcekind) @@ -70,13 +48,6 @@ function _add_lto_optimization(target, sourcekind) target:add("ldflags", "-flto") target:add("shflags", "-flto") - -- @see https://github.com/xmake-io/xmake/issues/5015 - -- add lto_plugin.so to ar - local lto_plugin = _get_gcc_liblto_plugin_path(target, program) - if lto_plugin then - target:add("arflags", {"--plugin", lto_plugin}, {force = true, expand = false}) - end - -- to use the link-time optimizer, -flto and optimization options should be specified at compile time and during the final link. -- @see https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html local optimize = target:get("optimize") diff --git a/xmake/toolchains/cross/check.lua b/xmake/toolchains/cross/check.lua index 815b95fd7..6f1df0f9a 100644 --- a/xmake/toolchains/cross/check.lua +++ b/xmake/toolchains/cross/check.lua @@ -21,6 +21,27 @@ -- imports import("core.project.config") import("detect.sdks.find_cross_toolchain") +import("lib.detect.find_file") + +-- find liblto_plugin.so path for gcc +function _find_gcc_liblto_plugin_path(cross_toolchain) + local gcc = find_file((cross_toolchain.cross or "*-") .. "gcc", cross_toolchain.bindir) + if gcc then + local plugin_path + local outdata = try { function() return os.iorunv(gcc, {"-print-prog-name=lto-wrapper"}) end } + if outdata then + local lto_plugindir = path.directory(outdata:trim()) + if os.isdir(lto_plugindir) then + if is_host("windows") then + plugin_path = find_file("liblto_plugin*.dll", lto_plugindir) + else + plugin_path = find_file("liblto_plugin.so", lto_plugindir) + end + end + end + return plugin_path + end +end -- check the cross toolchain function main(toolchain) @@ -47,6 +68,7 @@ function main(toolchain) end end end + if cross_toolchain then toolchain:config_set("cross", cross_toolchain.cross) toolchain:config_set("bindir", cross_toolchain.bindir) @@ -56,6 +78,14 @@ function main(toolchain) if not config.get("target_os") then config.set("target_os", "linux", {readonly = true, force = true}) end + + -- find lto_plugin.so path for gcc + -- @see https://github.com/xmake-io/xmake/issues/5015 + -- https://github.com/xmake-io/xmake/issues/5051 + local lto_plugin = _find_gcc_liblto_plugin_path(cross_toolchain) + if lto_plugin then + toolchain:config_set("lto_plugin", lto_plugin) + end else raise("cross toolchain not found!") end diff --git a/xmake/toolchains/cross/load.lua b/xmake/toolchains/cross/load.lua index 540d12111..ba59a2b84 100644 --- a/xmake/toolchains/cross/load.lua +++ b/xmake/toolchains/cross/load.lua @@ -23,8 +23,6 @@ import("core.project.config") -- load the cross toolchain function main(toolchain) - - -- get cross prefix local cross = toolchain:cross() or "" -- add toolset @@ -38,7 +36,6 @@ function main(toolchain) toolchain:add("toolset", "as", cross .. "gcc", cross .. "clang") toolchain:add("toolset", "ld", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") toolchain:add("toolset", "sh", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") - -- old gcc need gcc-ar for lto, @see https://github.com/xmake-io/xmake/issues/5015 toolchain:add("toolset", "ar", cross .. "ar") toolchain:add("toolset", "ranlib", cross .. "ranlib") toolchain:add("toolset", "strip", cross .. "strip") @@ -48,5 +45,13 @@ function main(toolchain) if bindir and is_host("windows") then toolchain:add("runenvs", "PATH", bindir) end + + -- add lto_plugin.so path for gcc + -- @see https://github.com/xmake-io/xmake/issues/5015 + -- https://github.com/xmake-io/xmake/issues/5051 + local lto_plugin = toolchain:config("lto_plugin") + if lto_plugin then + toolchain:add("arflags", {"--plugin", lto_plugin}) + end end -- cgit v1.3.1 From 8d2d4d5591bfce977cf39fbe27a84db0b8eb864f Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 May 2024 16:18:39 +0800 Subject: add force --- xmake/toolchains/cross/load.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/toolchains/cross/load.lua b/xmake/toolchains/cross/load.lua index ba59a2b84..ab04d634f 100644 --- a/xmake/toolchains/cross/load.lua +++ b/xmake/toolchains/cross/load.lua @@ -51,7 +51,7 @@ function main(toolchain) -- https://github.com/xmake-io/xmake/issues/5051 local lto_plugin = toolchain:config("lto_plugin") if lto_plugin then - toolchain:add("arflags", {"--plugin", lto_plugin}) + toolchain:add("arflags", {"--plugin", lto_plugin}, {force = true}) end end -- cgit v1.3.1 From c98f9f32c45b1dc80e22401ebb70694810529f4a Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 May 2024 16:24:34 +0800 Subject: add some comments --- xmake/toolchains/cross/load.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xmake/toolchains/cross/load.lua b/xmake/toolchains/cross/load.lua index ab04d634f..8bb869d03 100644 --- a/xmake/toolchains/cross/load.lua +++ b/xmake/toolchains/cross/load.lua @@ -37,7 +37,7 @@ function main(toolchain) toolchain:add("toolset", "ld", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") toolchain:add("toolset", "sh", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") toolchain:add("toolset", "ar", cross .. "ar") - toolchain:add("toolset", "ranlib", cross .. "ranlib") + toolchain:add("toolset", "ranlib", cross .. "gcc-ranlib", cross .. "ranlib") toolchain:add("toolset", "strip", cross .. "strip") -- add bin search library for loading some dependent .dll files windows @@ -48,7 +48,9 @@ function main(toolchain) -- add lto_plugin.so path for gcc -- @see https://github.com/xmake-io/xmake/issues/5015 - -- https://github.com/xmake-io/xmake/issues/5051 + -- + -- and we cannot use gcc-ar, @see https://github.com/xmake-io/xmake/issues/5051 + -- local lto_plugin = toolchain:config("lto_plugin") if lto_plugin then toolchain:add("arflags", {"--plugin", lto_plugin}, {force = true}) -- cgit v1.3.1 From 1924008b1db3bbf3fc6842a2d0afac209979ad5b Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 May 2024 16:50:09 +0800 Subject: only enable lto plugin on windows --- xmake/toolchains/cross/load.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xmake/toolchains/cross/load.lua b/xmake/toolchains/cross/load.lua index 8bb869d03..ddc645db3 100644 --- a/xmake/toolchains/cross/load.lua +++ b/xmake/toolchains/cross/load.lua @@ -36,7 +36,6 @@ function main(toolchain) toolchain:add("toolset", "as", cross .. "gcc", cross .. "clang") toolchain:add("toolset", "ld", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") toolchain:add("toolset", "sh", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") - toolchain:add("toolset", "ar", cross .. "ar") toolchain:add("toolset", "ranlib", cross .. "gcc-ranlib", cross .. "ranlib") toolchain:add("toolset", "strip", cross .. "strip") @@ -52,8 +51,11 @@ function main(toolchain) -- and we cannot use gcc-ar, @see https://github.com/xmake-io/xmake/issues/5051 -- local lto_plugin = toolchain:config("lto_plugin") - if lto_plugin then + if is_host("windows") and lto_plugin then toolchain:add("arflags", {"--plugin", lto_plugin}, {force = true}) + toolchain:add("toolset", "ar", cross .. "ar") + else + toolchain:add("toolset", "ar", cross .. "gcc-ar", cross .. "ar") end end -- cgit v1.3.1 From 2d0f7082ce3346e71445a94d0c492472150b94b7 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 May 2024 20:47:33 +0800 Subject: improve gcc-ar --- xmake/modules/core/tools/gcc_ar.lua | 54 +++++++++++++++++++++++++++++++++++++ xmake/toolchains/cross/check.lua | 29 -------------------- xmake/toolchains/cross/load.lua | 14 +--------- 3 files changed, 55 insertions(+), 42 deletions(-) diff --git a/xmake/modules/core/tools/gcc_ar.lua b/xmake/modules/core/tools/gcc_ar.lua index ecfdca92a..8a063bead 100644 --- a/xmake/modules/core/tools/gcc_ar.lua +++ b/xmake/modules/core/tools/gcc_ar.lua @@ -19,4 +19,58 @@ -- inherit("ar") +import("lib.detect.find_file") + +-- get liblto_plugin.so path for gcc +function _get_gcc_liblto_plugin_path(self, program) + local plugin_path = _g.LTO_PLUGIN_PATH + if plugin_path == nil then + local gcc = program:gsub("gcc%-ar", "gcc") + local outdata = try { function() return os.iorunv(gcc, {"-print-prog-name=lto-wrapper"}) end } + if outdata then + local lto_plugindir = path.directory(outdata:trim()) + if os.isdir(lto_plugindir) then + if is_host("windows") then + plugin_path = find_file("liblto_plugin*.dll", lto_plugindir) + else + plugin_path = find_file("liblto_plugin.so", lto_plugindir) + end + end + end + plugin_path = plugin_path or false + _g.LTO_PLUGIN_PATH = plugin_path + end + return plugin_path or nil +end + +-- link the library file +function link(self, objectfiles, targetkind, targetfile, flags, opt) + opt = opt or {} + os.mkdir(path.directory(targetfile)) + + -- @note remove the previous archived file first to force recreating a new file + os.tryrm(targetfile) + + -- generate link arguments + local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags, opt) + if is_host("windows") and argv and #argv > 0 and argv[1]:startswith("@") then + -- gcc-ar.exe does not support `@file`, so we need use ar.exe to instead of it. + -- @see https://github.com/xmake-io/xmake/issues/5051 + -- + -- but ar.exe does not support lto, we need also add lto_plugin.so path in `@file` for gcc + -- @see https://github.com/xmake-io/xmake/issues/5015 + -- + -- gcc-ar is the wrapper of `ar --plugin lto_plugin.so ...` + -- + program = program:gsub("gcc%-ar", "ar") + local _, rawargv = linkargv(self, objectfiles, targetkind, targetfile, flags, table.join(opt, {rawargs = true})) + local plugin_path = _get_gcc_liblto_plugin_path(self, program) + if plugin_path then + argv = winos.cmdargv(table.join({"--plugin", plugin_path}, rawargv), {escape = true}) + end + end + + -- link it + os.runv(program, argv, {envs = self:runenvs(), shell = opt.shell}) +end diff --git a/xmake/toolchains/cross/check.lua b/xmake/toolchains/cross/check.lua index 6f1df0f9a..3d8245d08 100644 --- a/xmake/toolchains/cross/check.lua +++ b/xmake/toolchains/cross/check.lua @@ -21,27 +21,6 @@ -- imports import("core.project.config") import("detect.sdks.find_cross_toolchain") -import("lib.detect.find_file") - --- find liblto_plugin.so path for gcc -function _find_gcc_liblto_plugin_path(cross_toolchain) - local gcc = find_file((cross_toolchain.cross or "*-") .. "gcc", cross_toolchain.bindir) - if gcc then - local plugin_path - local outdata = try { function() return os.iorunv(gcc, {"-print-prog-name=lto-wrapper"}) end } - if outdata then - local lto_plugindir = path.directory(outdata:trim()) - if os.isdir(lto_plugindir) then - if is_host("windows") then - plugin_path = find_file("liblto_plugin*.dll", lto_plugindir) - else - plugin_path = find_file("liblto_plugin.so", lto_plugindir) - end - end - end - return plugin_path - end -end -- check the cross toolchain function main(toolchain) @@ -78,14 +57,6 @@ function main(toolchain) if not config.get("target_os") then config.set("target_os", "linux", {readonly = true, force = true}) end - - -- find lto_plugin.so path for gcc - -- @see https://github.com/xmake-io/xmake/issues/5015 - -- https://github.com/xmake-io/xmake/issues/5051 - local lto_plugin = _find_gcc_liblto_plugin_path(cross_toolchain) - if lto_plugin then - toolchain:config_set("lto_plugin", lto_plugin) - end else raise("cross toolchain not found!") end diff --git a/xmake/toolchains/cross/load.lua b/xmake/toolchains/cross/load.lua index ddc645db3..1aca5e247 100644 --- a/xmake/toolchains/cross/load.lua +++ b/xmake/toolchains/cross/load.lua @@ -36,6 +36,7 @@ function main(toolchain) toolchain:add("toolset", "as", cross .. "gcc", cross .. "clang") toolchain:add("toolset", "ld", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") toolchain:add("toolset", "sh", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") + toolchain:add("toolset", "ar", cross .. "gcc-ar", cross .. "ar") toolchain:add("toolset", "ranlib", cross .. "gcc-ranlib", cross .. "ranlib") toolchain:add("toolset", "strip", cross .. "strip") @@ -44,18 +45,5 @@ function main(toolchain) if bindir and is_host("windows") then toolchain:add("runenvs", "PATH", bindir) end - - -- add lto_plugin.so path for gcc - -- @see https://github.com/xmake-io/xmake/issues/5015 - -- - -- and we cannot use gcc-ar, @see https://github.com/xmake-io/xmake/issues/5051 - -- - local lto_plugin = toolchain:config("lto_plugin") - if is_host("windows") and lto_plugin then - toolchain:add("arflags", {"--plugin", lto_plugin}, {force = true}) - toolchain:add("toolset", "ar", cross .. "ar") - else - toolchain:add("toolset", "ar", cross .. "gcc-ar", cross .. "ar") - end end -- cgit v1.3.1 From 262aedb8baaf5f87513f2e7e7ddf2f42450bc720 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 May 2024 20:55:57 +0800 Subject: fix program --- xmake/modules/core/tools/gcc_ar.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/core/tools/gcc_ar.lua b/xmake/modules/core/tools/gcc_ar.lua index 8a063bead..4fba49e6d 100644 --- a/xmake/modules/core/tools/gcc_ar.lua +++ b/xmake/modules/core/tools/gcc_ar.lua @@ -62,12 +62,12 @@ function link(self, objectfiles, targetkind, targetfile, flags, opt) -- -- gcc-ar is the wrapper of `ar --plugin lto_plugin.so ...` -- - program = program:gsub("gcc%-ar", "ar") local _, rawargv = linkargv(self, objectfiles, targetkind, targetfile, flags, table.join(opt, {rawargs = true})) local plugin_path = _get_gcc_liblto_plugin_path(self, program) if plugin_path then argv = winos.cmdargv(table.join({"--plugin", plugin_path}, rawargv), {escape = true}) end + program = program:gsub("gcc%-ar", "ar") end -- link it -- cgit v1.3.1 From 81afb8ae234b900aab9a712a4f38599e34c9c066 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 May 2024 21:00:18 +0800 Subject: add comments --- xmake/toolchains/cross/load.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/xmake/toolchains/cross/load.lua b/xmake/toolchains/cross/load.lua index 1aca5e247..0195b8c9a 100644 --- a/xmake/toolchains/cross/load.lua +++ b/xmake/toolchains/cross/load.lua @@ -36,6 +36,7 @@ function main(toolchain) toolchain:add("toolset", "as", cross .. "gcc", cross .. "clang") toolchain:add("toolset", "ld", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") toolchain:add("toolset", "sh", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") + -- need gcc-ar for lto, @see https://github.com/xmake-io/xmake/issues/5015 toolchain:add("toolset", "ar", cross .. "gcc-ar", cross .. "ar") toolchain:add("toolset", "ranlib", cross .. "gcc-ranlib", cross .. "ranlib") toolchain:add("toolset", "strip", cross .. "strip") -- cgit v1.3.1 From eb1e30aeffb3b8cce42f591da449c9f2ebfb90ad Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 May 2024 21:03:04 +0800 Subject: improve comments --- xmake/modules/core/tools/gcc_ar.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/core/tools/gcc_ar.lua b/xmake/modules/core/tools/gcc_ar.lua index 4fba49e6d..d7731a115 100644 --- a/xmake/modules/core/tools/gcc_ar.lua +++ b/xmake/modules/core/tools/gcc_ar.lua @@ -57,7 +57,7 @@ function link(self, objectfiles, targetkind, targetfile, flags, opt) -- gcc-ar.exe does not support `@file`, so we need use ar.exe to instead of it. -- @see https://github.com/xmake-io/xmake/issues/5051 -- - -- but ar.exe does not support lto, we need also add lto_plugin.so path in `@file` for gcc + -- but ar.exe does not support lto, we need also add lto_plugin-0.dll path in `@file` for gcc -- @see https://github.com/xmake-io/xmake/issues/5015 -- -- gcc-ar is the wrapper of `ar --plugin lto_plugin.so ...` -- cgit v1.3.1 From e2eee64979c35ff8ad3efabc1f51bc21432ea833 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 May 2024 21:08:01 +0800 Subject: improve to replace program --- xmake/modules/core/tools/gcc_ar.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/xmake/modules/core/tools/gcc_ar.lua b/xmake/modules/core/tools/gcc_ar.lua index d7731a115..b2131d9e8 100644 --- a/xmake/modules/core/tools/gcc_ar.lua +++ b/xmake/modules/core/tools/gcc_ar.lua @@ -21,11 +21,24 @@ inherit("ar") import("lib.detect.find_file") +-- replace gcc-ar +function _replace_gcc_ar(program, name) + local dir = path.directory(program) + local filename = path.filename(program) + filename = filename:gsub("gcc%-ar", name) + if dir and dir ~= "." then + program = path.join(dir, filename) + else + program = filename + end + return program +end + -- get liblto_plugin.so path for gcc function _get_gcc_liblto_plugin_path(self, program) local plugin_path = _g.LTO_PLUGIN_PATH if plugin_path == nil then - local gcc = program:gsub("gcc%-ar", "gcc") + local gcc = _replace_gcc_ar(program, "gcc") local outdata = try { function() return os.iorunv(gcc, {"-print-prog-name=lto-wrapper"}) end } if outdata then local lto_plugindir = path.directory(outdata:trim()) @@ -67,7 +80,7 @@ function link(self, objectfiles, targetkind, targetfile, flags, opt) if plugin_path then argv = winos.cmdargv(table.join({"--plugin", plugin_path}, rawargv), {escape = true}) end - program = program:gsub("gcc%-ar", "ar") + program = _replace_gcc_ar(program, "ar") end -- link it -- cgit v1.3.1