summaryrefslogtreecommitdiff
path: root/tests/projects/c++/modules/precompile_reduced_bmi
diff options
context:
space:
mode:
authorruki <[email protected]>2026-09-04 20:41:49 +0800
committerGitHub <[email protected]>2026-09-04 20:41:49 +0800
commit5a596488e900267054ce185d0e4a65ef3c600315 (patch)
tree99f7dbfd7ece4a5b1a19662da80977eb7ce776f0 /tests/projects/c++/modules/precompile_reduced_bmi
parentc1a32b8b31bb78cf4ac4b51b0a7a08b6c4224505 (diff)
parent416afba0e7c98f50960745347988011108647d13 (diff)
Merge pull request #7742 from ryblust/feat/clang-precompile-reduced-bmiHEADdev
Support Clang 23 `--precompile-reduced-bmi` pipeline
Diffstat (limited to 'tests/projects/c++/modules/precompile_reduced_bmi')
-rw-r--r--tests/projects/c++/modules/precompile_reduced_bmi/src/base.mpp5
-rw-r--r--tests/projects/c++/modules/precompile_reduced_bmi/src/hello.mpp7
-rw-r--r--tests/projects/c++/modules/precompile_reduced_bmi/src/main.cpp5
-rw-r--r--tests/projects/c++/modules/precompile_reduced_bmi/test.lua107
-rw-r--r--tests/projects/c++/modules/precompile_reduced_bmi/xmake.lua6
5 files changed, 130 insertions, 0 deletions
diff --git a/tests/projects/c++/modules/precompile_reduced_bmi/src/base.mpp b/tests/projects/c++/modules/precompile_reduced_bmi/src/base.mpp
new file mode 100644
index 000000000..e3e6224f2
--- /dev/null
+++ b/tests/projects/c++/modules/precompile_reduced_bmi/src/base.mpp
@@ -0,0 +1,5 @@
+export module base;
+
+export int base_value() {
+ return 40;
+}
diff --git a/tests/projects/c++/modules/precompile_reduced_bmi/src/hello.mpp b/tests/projects/c++/modules/precompile_reduced_bmi/src/hello.mpp
new file mode 100644
index 000000000..9de491171
--- /dev/null
+++ b/tests/projects/c++/modules/precompile_reduced_bmi/src/hello.mpp
@@ -0,0 +1,7 @@
+export module hello;
+
+import base;
+
+export int answer() {
+ return base_value() + 2;
+}
diff --git a/tests/projects/c++/modules/precompile_reduced_bmi/src/main.cpp b/tests/projects/c++/modules/precompile_reduced_bmi/src/main.cpp
new file mode 100644
index 000000000..75adbd883
--- /dev/null
+++ b/tests/projects/c++/modules/precompile_reduced_bmi/src/main.cpp
@@ -0,0 +1,5 @@
+import hello;
+
+int main() {
+ return answer() == 42 ? 0 : 1;
+}
diff --git a/tests/projects/c++/modules/precompile_reduced_bmi/test.lua b/tests/projects/c++/modules/precompile_reduced_bmi/test.lua
new file mode 100644
index 000000000..765290f7b
--- /dev/null
+++ b/tests/projects/c++/modules/precompile_reduced_bmi/test.lua
@@ -0,0 +1,107 @@
+inherit(".test_base")
+import("core.base.json")
+
+local _CLANG_MIN_VER = "23"
+
+function clang_min_ver()
+ return _CLANG_MIN_VER
+end
+
+function _check_commands(config, outdata)
+ local has_precompile_reduced_bmi = outdata:find("--precompile-reduced-bmi", 1, true) ~= nil
+ local expect_precompile_reduced_bmi = config.precompile_reduced_bmi and config.two_phases
+ assert(has_precompile_reduced_bmi == expect_precompile_reduced_bmi,
+ "unexpected --precompile-reduced-bmi usage\n%s", outdata)
+
+ if config.two_phases then
+ local object_command
+ for _, line in ipairs(outdata:split("\n", {plain = true})) do
+ if line:find("hello.mpp", 1, true) and
+ (line:find("hello.mpp.o", 1, true) or line:find("hello.mpp.obj", 1, true)) and
+ line:find(" -c ", 1, true) and
+ not line:find("clang-scan-deps", 1, true) and
+ not line:find("--precompile", 1, true) then
+ object_command = line
+ break
+ end
+ end
+ assert(object_command, "module object command missing\n%s", outdata)
+ local consumes_bmi = object_command:find("hello.pcm", 1, true) ~= nil
+ assert(consumes_bmi ~= expect_precompile_reduced_bmi, "unexpected module object input\n%s", outdata)
+ end
+end
+
+function _check_incremental()
+ local outdata = os.iorun("xmake -v")
+ if outdata:find("compiling", 1, true) or
+ outdata:find("linking", 1, true) or
+ outdata:find("generating", 1, true) then
+ raise("Modules incremental compilation does not work\n%s", outdata)
+ end
+end
+
+function _check_compile_commands(config)
+ os.run("xmake project -k compile_commands")
+ local bmi_command
+ local object_command
+ for _, command in ipairs(assert(json.loadfile("compile_commands.json"))) do
+ if command.file:endswith("hello.mpp") then
+ local commandline = command.command or table.concat(command.arguments or {}, " ")
+ if commandline:find("--precompile", 1, true) then
+ bmi_command = commandline
+ elseif commandline:find("hello.mpp.o", 1, true) or commandline:find("hello.mpp.obj", 1, true) then
+ object_command = commandline
+ end
+ end
+ end
+ assert(bmi_command, "module BMI command missing from compile_commands.json")
+ assert(object_command, "module object command missing from compile_commands.json")
+ local expect_precompile_reduced_bmi = config.precompile_reduced_bmi and config.two_phases
+ assert((bmi_command:find("--precompile-reduced-bmi", 1, true) ~= nil) == expect_precompile_reduced_bmi,
+ "unexpected module BMI command\n%s", bmi_command)
+ assert(object_command:find("hello.mpp", 1, true) and not object_command:find("hello.pcm", 1, true),
+ "unexpected module object command\n%s", object_command)
+end
+
+function _configure(config)
+ local argv = {"f", "--yes", "--toolchain=" .. config.toolchain}
+ if config.platform then
+ table.join2(argv, {"-p", config.platform})
+ end
+ if config.runtimes then
+ table.insert(argv, "--runtimes=" .. config.runtimes)
+ end
+ local policies = "--policies=build.c++.modules.std:" .. (config.stdmodule and "y" or "n")
+ policies = policies .. ",build.c++.modules.fallbackscanner:" .. (config.fallbackscanner and "y" or "n")
+ policies = policies .. ",build.c++.modules.two_phases:" .. (config.two_phases and "y" or "n")
+ policies = policies .. ",build.c++.modules.clang.precompile_reduced_bmi:" .. (config.precompile_reduced_bmi and "y" or "n")
+ table.insert(argv, policies)
+ table.join2(argv, config.flags or {})
+ os.execv("xmake", argv)
+end
+
+function _check_build(config)
+ local outdata = os.iorun("xmake -rv")
+ _check_commands(config, outdata)
+
+ os.run("xmake run")
+ _check_incremental()
+ if config.two_phases then
+ _check_compile_commands(config)
+ end
+
+ if config.two_phases then
+ local toggled_config = table.clone(config)
+ toggled_config.precompile_reduced_bmi = not config.precompile_reduced_bmi
+ _configure(toggled_config)
+ local toggled_outdata = os.iorun("xmake -v")
+ _check_commands(toggled_config, toggled_outdata)
+ os.run("xmake run")
+ _check_incremental()
+ _check_compile_commands(toggled_config)
+ end
+end
+
+function main(_)
+ run_tests({compiler = "clang", version = clang_min_ver(), precompile_reduced_bmi = true, build = _check_build})
+end
diff --git a/tests/projects/c++/modules/precompile_reduced_bmi/xmake.lua b/tests/projects/c++/modules/precompile_reduced_bmi/xmake.lua
new file mode 100644
index 000000000..0aa2dc516
--- /dev/null
+++ b/tests/projects/c++/modules/precompile_reduced_bmi/xmake.lua
@@ -0,0 +1,6 @@
+add_rules("mode.release", "mode.debug")
+set_languages("c++20")
+
+target("precompile_reduced_bmi")
+ set_kind("binary")
+ add_files("src/*.cpp", "src/*.mpp")