Skip to content

Commit 1e2f79f

Browse files
committed
(C++ modules support) reuse msvc support get_stdmodules for llvm std module support when using msstl
1 parent d1a7e51 commit 1e2f79f

File tree

2 files changed

+20
-38
lines changed

2 files changed

+20
-38
lines changed

xmake/rules/c++/modules/clang/support.lua

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,19 +289,7 @@ function get_stdmodules(target)
289289
local clang_version = get_clang_version(target)
290290
if clang_version and semver.compare(clang_version, "19.0") >= 0 then
291291
local toolchain = target:toolchain("llvm") or target:toolchain("clang") or target:toolchain("clang-cl")
292-
local msvc = import("core.tool.toolchain", {anonymous = true}).load("msvc", {plat = toolchain:plat(), arch = toolchain:arch()})
293-
if msvc and msvc:check({ignore_sdk = true}) then
294-
local vcvars = msvc:config("vcvars")
295-
if vcvars.VCInstallDir and vcvars.VCToolsVersion then
296-
local stdmodulesdir = path.join(vcvars.VCInstallDir, "Tools", "MSVC", vcvars.VCToolsVersion, "modules")
297-
if os.isdir(stdmodulesdir) then
298-
return {path.normalize(path.join(stdmodulesdir, "std.ixx")), path.normalize(path.join(stdmodulesdir, "std.compat.ixx"))}
299-
end
300-
end
301-
end
302-
else
303-
wprint("msstl std module file is not compatible with llvm < 19, please upgrade clang/clang-cl version!")
304-
return
292+
return import(".msvc.support").get_stdmodules(target, {dont_warn = false, toolchain = toolchain})
305293
end
306294
end
307295
end

xmake/rules/c++/modules/msvc/support.lua

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ end
9999

100100
-- provide toolchain include dir for stl headerunit when p1689 is not supported
101101
function toolchain_includedirs(target)
102-
103102
for _, toolchain_inst in ipairs(target:toolchains()) do
104103
if toolchain_inst:name() == "msvc" then
105104
local vcvars = toolchain_inst:config("vcvars")
@@ -117,22 +116,27 @@ function has_two_phase_compilation_support(_)
117116
end
118117

119118
-- build c++23 standard modules if needed
120-
function get_stdmodules(target)
121-
122-
if target:policy("build.c++.modules.std") then
123-
local msvc = target:toolchain("msvc")
124-
if msvc then
125-
local vcvars = msvc:config("vcvars")
126-
if vcvars.VCInstallDir and vcvars.VCToolsVersion then
127-
modules = {}
128-
129-
local stdmodulesdir = path.join(vcvars.VCInstallDir, "Tools", "MSVC", vcvars.VCToolsVersion, "modules")
130-
131-
if os.isdir(stdmodulesdir) then
132-
return {path.normalize(path.join(stdmodulesdir, "std.ixx")), path.normalize(path.join(stdmodulesdir, "std.compat.ixx"))}
133-
end
119+
function get_stdmodules(target, opt)
120+
opt = opt or {}
121+
if not target:policy("build.c++.modules.std") then
122+
return
123+
end
124+
local msvc
125+
if opt.toolchain then
126+
msvc = import("core.tool.toolchain", {anonymous = true}).load("msvc", {plat = opt.toolchain:plat(), arch = opt.toolchain:arch()})
127+
else
128+
msvc = target:toolchain("msvc")
129+
end
130+
if msvc and msvc:check() then
131+
local vcvars = msvc:config("vcvars")
132+
if vcvars.VCInstallDir and vcvars.VCToolsVersion then
133+
local stdmodulesdir = path.join(vcvars.VCInstallDir, "Tools", "MSVC", vcvars.VCToolsVersion, "modules")
134+
if os.isdir(stdmodulesdir) then
135+
return {path.normalize(path.join(stdmodulesdir, "std.ixx")), path.normalize(path.join(stdmodulesdir, "std.compat.ixx"))}
134136
end
135137
end
138+
end
139+
if not opt.dont_warn then
136140
wprint("std and std.compat modules not found! disabling them for the build")
137141
end
138142
end
@@ -142,7 +146,6 @@ function get_bmi_extension()
142146
end
143147

144148
function get_ifcoutputflag(target)
145-
146149
local ifcoutputflag = _g.ifcoutputflag
147150
if ifcoutputflag == nil then
148151
local compinst = target:compiler("cxx")
@@ -156,7 +159,6 @@ function get_ifcoutputflag(target)
156159
end
157160

158161
function get_ifconlyflag(target)
159-
160162
local ifconlyflag = _g.ifconlyflag
161163
if ifconlyflag == nil then
162164
local compinst = target:compiler("cxx")
@@ -169,7 +171,6 @@ function get_ifconlyflag(target)
169171
end
170172

171173
function get_interfaceflag(target)
172-
173174
local interfaceflag = _g.interfaceflag
174175
if interfaceflag == nil then
175176
local compinst = target:compiler("cxx")
@@ -183,7 +184,6 @@ function get_interfaceflag(target)
183184
end
184185

185186
function get_referenceflag(target)
186-
187187
local referenceflag = _g.referenceflag
188188
if referenceflag == nil then
189189
local compinst = target:compiler("cxx")
@@ -197,7 +197,6 @@ function get_referenceflag(target)
197197
end
198198

199199
function get_headernameflag(target)
200-
201200
local headernameflag = _g.headernameflag
202201
if headernameflag == nil then
203202
local compinst = target:compiler("cxx")
@@ -211,7 +210,6 @@ function get_headernameflag(target)
211210
end
212211

213212
function get_headerunitflag(target)
214-
215213
local headerunitflag = _g.headerunitflag
216214
if headerunitflag == nil then
217215
local compinst = target:compiler("cxx")
@@ -226,7 +224,6 @@ function get_headerunitflag(target)
226224
end
227225

228226
function get_exportheaderflag(target)
229-
230227
local exportheaderflag = _g.exportheaderflag
231228
if exportheaderflag == nil then
232229
if get_headernameflag(target) then
@@ -238,7 +235,6 @@ function get_exportheaderflag(target)
238235
end
239236

240237
function get_scandependenciesflag(target)
241-
242238
local scandependenciesflag = _g.scandependenciesflag
243239
if scandependenciesflag == nil then
244240
local compinst = target:compiler("cxx")
@@ -261,7 +257,6 @@ function get_scandependenciesflag(target)
261257
end
262258

263259
function get_cppversionflag(target)
264-
265260
local cppversionflag = _g.cppversionflag
266261
if cppversionflag == nil then
267262
local compinst = target:compiler("cxx")
@@ -272,7 +267,6 @@ function get_cppversionflag(target)
272267
end
273268

274269
function get_internalpartitionflag(target)
275-
276270
local internalpartitionflag = _g.internalpartitionflag
277271
if internalpartitionflag == nil then
278272
local compinst = target:compiler("cxx")

0 commit comments

Comments
 (0)