Skip to content

Commit e1cf8f6

Browse files
committed
(C++ modules support) add support of libstdc++ std module for clang/llvm
1 parent 6b69dfd commit e1cf8f6

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ function get_stdmodules(target)
277277
end
278278
end
279279
elseif cpplib == "stdc++" then
280-
-- libstdc++ doesn't have a std module file atm
280+
-- dont be greedy and don't enable stdc++ std module support for llvm < 19
281+
local clang_version = get_clang_version(target)
282+
if clang_version and semver.compare(clang_version, "19.0") >= 0 then
283+
return import(".gcc.support").get_stdmodules(target, {warn = false})
284+
end
281285
elseif cpplib == "msstl" then
282286
-- msstl std module file is not compatible with llvm < 19
283287
local clang_version = get_clang_version(target)

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,26 +166,29 @@ function _get_std_module_manifest_path(target)
166166
end
167167
end
168168

169-
function get_stdmodules(target)
169+
function get_stdmodules(target, opt)
170+
opt = opt or {}
170171
if not target:policy("build.c++.modules.std") then
171172
return
172173
end
173174
local modules_json_path = _get_std_module_manifest_path(target)
174-
if not modules_json_path then
175-
return
176-
end
177-
local modules_json = json.loadfile(modules_json_path)
178-
if modules_json and modules_json.modules and #modules_json.modules > 0 then
179-
local std_module_files = {}
180-
local modules_json_dir = path.directory(modules_json_path)
181-
for _, module_file in ipairs(modules_json.modules) do
182-
local module_file_path = module_file["source-path"]
183-
if not path.is_absolute(module_file_path) then
184-
module_file_path = path.join(modules_json_dir, module_file_path)
175+
if modules_json_path then
176+
local modules_json = json.loadfile(modules_json_path)
177+
if modules_json and modules_json.modules and #modules_json.modules > 0 then
178+
local std_module_files = {}
179+
local modules_json_dir = path.directory(modules_json_path)
180+
for _, module_file in ipairs(modules_json.modules) do
181+
local module_file_path = module_file["source-path"]
182+
if not path.is_absolute(module_file_path) then
183+
module_file_path = path.join(modules_json_dir, module_file_path)
184+
end
185+
table.insert(std_module_files, path.normalize(module_file_path))
185186
end
186-
table.insert(std_module_files, path.normalize(module_file_path))
187+
return std_module_files
187188
end
188-
return std_module_files
189+
end
190+
if not opt.dont_warn then
191+
wprint("std and std.compat modules not found! maybe try to add --sdk=<PATH/TO/LLVM> or install libc++")
189192
end
190193
end
191194

0 commit comments

Comments
 (0)