Skip to content

Commit a505539

Browse files
committed
fix map flags for package runtimes
1 parent 456eedc commit a505539

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

tests/projects/c++/snippet_runtimes/xmake.lua

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ add_requires("bar")
44
target("foo")
55
set_kind("binary")
66
add_files("src/*.cpp")
7-
87
add_packages("bar")
98

109
on_config(function(target)

xmake/core/package/package.lua

+12-4
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ end
12831283

12841284
-- get the package compiler
12851285
function _instance:compiler(sourcekind)
1286-
local compilerinst = self:_memcache():get("compiler")
1286+
local compilerinst = self:_memcache():get2("compiler", sourcekind)
12871287
if not compilerinst then
12881288
if not sourcekind then
12891289
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)
12931293
os.raise(errors)
12941294
end
12951295
compilerinst = instance
1296-
self:_memcache():set("compiler", compilerinst)
1296+
self:_memcache():set2("compiler", sourcekind, compilerinst)
12971297
end
12981298
return compilerinst
12991299
end
13001300

13011301
-- get the package linker
13021302
function _instance:linker(targetkind, sourcekinds)
1303-
local linkerinst = self:_memcache():get("linker")
1303+
local linkerinst = self:_memcache():get3("linker", targetkind, sourcekinds)
13041304
if not linkerinst then
1305+
if not sourcekinds then
1306+
os.raise("please pass sourcekinds to the second argument of package:linker(), e.g. cc, cxx, as")
1307+
end
13051308
local instance, errors = linker.load(targetkind, sourcekinds, self)
13061309
if not instance then
13071310
os.raise(errors)
13081311
end
13091312
linkerinst = instance
1310-
self:_memcache():set("linker", linkerinst)
1313+
self:_memcache():set3("linker", targetkind, sourcekinds, linkerinst)
13111314
end
13121315
return linkerinst
13131316
end
@@ -2371,7 +2374,11 @@ function _instance:_generate_build_configs(configs, opt)
23712374
end
23722375
end
23732376
if runtimes then
2377+
-- @note we need to patch package:sourcekinds(), because it wiil be called nf_runtime for gcc/clang
23742378
local sourcekind = opt.sourcekind or "cxx"
2379+
self.sourcekinds = function (self)
2380+
return sourcekind
2381+
end
23752382
local compiler = self:compiler(sourcekind)
23762383
local cxflags = compiler:map_flags("runtime", runtimes, {target = self})
23772384
configs.cxflags = table.wrap(configs.cxflags)
@@ -2384,6 +2391,7 @@ function _instance:_generate_build_configs(configs, opt)
23842391
local shflags = self:linker("shared", sourcekind):map_flags("runtime", runtimes, {target = self})
23852392
configs.shflags = table.wrap(configs.shflags)
23862393
table.join2(configs.shflags, shflags)
2394+
self.sourcekinds = nil
23872395
end
23882396
if self:config("lto") then
23892397
local configs_lto = self:_generate_lto_configs(opt.sourcekind or "cxx")

0 commit comments

Comments
 (0)