diff options
| author | Tiangang Song <[email protected]> | 2026-05-03 11:39:39 -0700 |
|---|---|---|
| committer | Tiangang Song <[email protected]> | 2026-05-04 20:30:55 -0700 |
| commit | bbcf7a801e637b89a005751c6bfdf7bfcaa48de8 (patch) | |
| tree | 3c6ded46cac4adfc188ee2b2cbe0816d309aa776 | |
| parent | 931fce9c311f25aca6091d226b48f72b1dc548c9 (diff) | |
Fix lto with zig cc and clang_cl
| -rw-r--r-- | xmake/core/package/package.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/c++/config/optimization.lua | 11 |
2 files changed, 8 insertions, 9 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 636b717c2..95ee2a01b 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -2426,9 +2426,9 @@ function _instance:_generate_lto_configs(sourcekind) if sourcekind then local _, cc = self:tool(sourcekind) local cflag = sourcekind == "cxx" and "cxxflags" or "cflags" - if cc == "cl" then + if cc == "cl" or cc == "clang_cl" then configs[cflag] = "-GL" - elseif cc == "clang" or cc == "clangxx" or cc == "clang_cl" then + elseif cc == "clang" or cc == "clangxx" or cc:startswith("zig") then configs[cflag] = "-flto=thin" elseif cc == "gcc" or cc == "gxx" then configs[cflag] = "-flto" @@ -2440,7 +2440,7 @@ function _instance:_generate_lto_configs(sourcekind) if ld == "link" then configs.ldflags = "-LTCG" configs.shflags = "-LTCG" - elseif ld == "clang" or ld == "clangxx" then + elseif ld == "clang" or ld == "clangxx" or ld:startswith("zig") then configs.ldflags = "-flto=thin" configs.shflags = "-flto=thin" elseif ld == "gcc" or ld == "gxx" then diff --git a/xmake/rules/c++/config/optimization.lua b/xmake/rules/c++/config/optimization.lua index d84515fd2..3df0be36c 100644 --- a/xmake/rules/c++/config/optimization.lua +++ b/xmake/rules/c++/config/optimization.lua @@ -33,20 +33,20 @@ function _add_lto_optimization(target, sourcekind) mxx = "mxxflags" } local cflag = flagnames[sourcekind] or (sourcekind == "cxx" and "cxxflags" or "cflags") - if cc == "cl" then + if cc == "cl" or cc == "clang_cl" then target:add(cflag, "-GL") - elseif cc == "clang" or cc == "clangxx" or cc == "clang_cl" then + elseif cc == "clang" or cc == "clangxx" or cc:startswith("zig") then target:add(cflag, "-flto=thin") elseif cc == "gcc" or cc == "gxx" then target:add(cflag, "-flto") end -- add ldflags and shflags - local program, ld = target:tool("ld") + local _, ld = target:tool("ld") if ld == "link" then target:add("ldflags", "-LTCG") target:add("shflags", "-LTCG") - elseif ld == "clang" or ld == "clangxx" then + elseif ld == "clang" or ld == "clangxx" or ld:startswith("zig") then target:add("ldflags", "-flto=thin") target:add("shflags", "-flto=thin") @@ -88,7 +88,7 @@ function _add_lto_optimization(target, sourcekind) end end - local program, ar = target:tool("ar") + local _, ar = target:tool("ar") if cc == "clang_cl" then if ld == "link" then wprint([[Unsupported toolset(%s) for lto, please use `set_toolset("ld", "lld-link")`]], ld) @@ -109,4 +109,3 @@ function main(target, sourcekind) _add_lto_optimization(target, sourcekind) end end - |
