summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-08-31 00:39:10 +0800
committerruki <[email protected]>2024-08-31 00:39:10 +0800
commita50553989fd578547255c34616fff4e18ba84784 (patch)
tree3a0157f0f437804b6d829532688a687afe325918
parent456eedcebb5adac9063d9417f68a47ebe0cddb49 (diff)
fix map flags for package runtimes
-rw-r--r--tests/projects/c++/snippet_runtimes/xmake.lua1
-rw-r--r--xmake/core/package/package.lua16
2 files changed, 12 insertions, 5 deletions
diff --git a/tests/projects/c++/snippet_runtimes/xmake.lua b/tests/projects/c++/snippet_runtimes/xmake.lua
index 1e5436ba4..8ef59ed4f 100644
--- a/tests/projects/c++/snippet_runtimes/xmake.lua
+++ b/tests/projects/c++/snippet_runtimes/xmake.lua
@@ -4,7 +4,6 @@ add_requires("bar")
target("foo")
set_kind("binary")
add_files("src/*.cpp")
-
add_packages("bar")
on_config(function(target)
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 22a8dfb2b..c837b5bdc 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -1283,7 +1283,7 @@ end
-- get the package compiler
function _instance:compiler(sourcekind)
- local compilerinst = self:_memcache():get("compiler")
+ local compilerinst = self:_memcache():get2("compiler", sourcekind)
if not compilerinst then
if not sourcekind then
os.raise("please pass sourcekind to the first argument of package:compiler(), e.g. cc, cxx, as")
@@ -1293,21 +1293,24 @@ function _instance:compiler(sourcekind)
os.raise(errors)
end
compilerinst = instance
- self:_memcache():set("compiler", compilerinst)
+ self:_memcache():set2("compiler", sourcekind, compilerinst)
end
return compilerinst
end
-- get the package linker
function _instance:linker(targetkind, sourcekinds)
- local linkerinst = self:_memcache():get("linker")
+ local linkerinst = self:_memcache():get3("linker", targetkind, sourcekinds)
if not linkerinst then
+ if not sourcekinds then
+ os.raise("please pass sourcekinds to the second argument of package:linker(), e.g. cc, cxx, as")
+ end
local instance, errors = linker.load(targetkind, sourcekinds, self)
if not instance then
os.raise(errors)
end
linkerinst = instance
- self:_memcache():set("linker", linkerinst)
+ self:_memcache():set3("linker", targetkind, sourcekinds, linkerinst)
end
return linkerinst
end
@@ -2371,7 +2374,11 @@ function _instance:_generate_build_configs(configs, opt)
end
end
if runtimes then
+ -- @note we need to patch package:sourcekinds(), because it wiil be called nf_runtime for gcc/clang
local sourcekind = opt.sourcekind or "cxx"
+ self.sourcekinds = function (self)
+ return sourcekind
+ end
local compiler = self:compiler(sourcekind)
local cxflags = compiler:map_flags("runtime", runtimes, {target = self})
configs.cxflags = table.wrap(configs.cxflags)
@@ -2384,6 +2391,7 @@ function _instance:_generate_build_configs(configs, opt)
local shflags = self:linker("shared", sourcekind):map_flags("runtime", runtimes, {target = self})
configs.shflags = table.wrap(configs.shflags)
table.join2(configs.shflags, shflags)
+ self.sourcekinds = nil
end
if self:config("lto") then
local configs_lto = self:_generate_lto_configs(opt.sourcekind or "cxx")