diff options
| author | carols <[email protected]> | 2024-04-07 12:57:02 +0800 |
|---|---|---|
| committer | carols <[email protected]> | 2024-04-07 12:57:02 +0800 |
| commit | 99e57fc8e1ac160832860547e7d220254366a96a (patch) | |
| tree | 18fcae157f8b88f8d51bf054e138b0d8c1ec0c5e | |
| parent | 7e0f8751549ed166fefa13afb300527b76bb190a (diff) | |
Add cppfront's header(*.h2) support
| -rw-r--r-- | tests/projects/cppfront/console/src/main.cpp2 | 6 | ||||
| -rw-r--r-- | tests/projects/cppfront/console/src/println.h2 | 4 | ||||
| -rw-r--r-- | tests/projects/cppfront/console/xmake.lua | 1 | ||||
| -rw-r--r-- | xmake/rules/cppfront/xmake.lua | 63 |
4 files changed, 52 insertions, 22 deletions
diff --git a/tests/projects/cppfront/console/src/main.cpp2 b/tests/projects/cppfront/console/src/main.cpp2 index 1ab54b94b..4bf37d8c3 100644 --- a/tests/projects/cppfront/console/src/main.cpp2 +++ b/tests/projects/cppfront/console/src/main.cpp2 @@ -1,7 +1,5 @@ +#include "println.h2" + main: () -> int = println("Hello world!\n"); -println: (msg: _) -> int = { - std::cout << msg; - return 0; -} diff --git a/tests/projects/cppfront/console/src/println.h2 b/tests/projects/cppfront/console/src/println.h2 new file mode 100644 index 000000000..24c244da4 --- /dev/null +++ b/tests/projects/cppfront/console/src/println.h2 @@ -0,0 +1,4 @@ +println: (msg: _) -> int = { + std::cout << msg; + return 0; +} diff --git a/tests/projects/cppfront/console/xmake.lua b/tests/projects/cppfront/console/xmake.lua index 65b68cd6e..4c99bfadb 100644 --- a/tests/projects/cppfront/console/xmake.lua +++ b/tests/projects/cppfront/console/xmake.lua @@ -6,5 +6,6 @@ target("test") add_rules("cppfront") set_kind("binary") add_files("src/*.cpp2") + add_files("src/*.h2") add_packages("cppfront") diff --git a/xmake/rules/cppfront/xmake.lua b/xmake/rules/cppfront/xmake.lua index 90153df85..e0d535e7e 100644 --- a/xmake/rules/cppfront/xmake.lua +++ b/xmake/rules/cppfront/xmake.lua @@ -20,7 +20,7 @@ -- define rule: cppfront.build rule("cppfront.build") - set_extensions(".cpp2") + set_extensions(".cpp2", ".h2") on_load(function (target) -- only cppfront source files? we need to patch cxx source kind for linker local sourcekinds = target:sourcekinds() @@ -35,31 +35,58 @@ rule("cppfront.build") end end end) - on_buildcmd_file(function (target, batchcmds, sourcefile_cpp2, opt) + on_buildcmd_files(function (target, batchcmds, sourcebatch, opt) + -- order files h2->cpp2 + cpp2_files = {} + all_files = {} + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + if string.endswith(sourcefile, ".h2") then + table.insert(all_files, sourcefile) + elseif string.endswith(sourcefile, ".cpp2") then + table.insert(cpp2_files, sourcefile) + end + end + table.join2(all_files, cpp2_files) -- get cppfront import("lib.detect.find_tool") local cppfront = assert(find_tool("cppfront", {check = "-h"}), "cppfront not found!") - -- get c++ source file for cpp2 - local sourcefile_cpp = target:autogenfile((sourcefile_cpp2:gsub(".cpp2$", ".cpp"))) - local basedir = path.directory(sourcefile_cpp) + for _, sourcefile_cpp2 in ipairs(all_files) do -- get c++ source file for cpp2 + local sourcefile_cpp = "" + local is_h2 = string.endswith(sourcefile_cpp2, ".h2") + if is_h2 then + sourcefile_cpp = target:autogenfile((sourcefile_cpp2:gsub(".h2$", ".h"))) + else + sourcefile_cpp = target:autogenfile((sourcefile_cpp2:gsub(".cpp2$", ".cpp"))) + end + local basedir = path.directory(sourcefile_cpp) + + -- add objectfile + local objectfile = "" + if not is_h2 then + objectfile = target:objectfile(sourcefile_cpp) + table.insert(target:objectfiles(), objectfile) + end - -- add objectfile - local objectfile = target:objectfile(sourcefile_cpp) - table.insert(target:objectfiles(), objectfile) + -- add commands + local argv = {"-verb", "-e", "-o", path(sourcefile_cpp), path(sourcefile_cpp2)} - -- add commands - local argv = {"-o", path(sourcefile_cpp), path(sourcefile_cpp2)} - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.cpp2 %s", sourcefile_cpp2) - batchcmds:mkdir(basedir) - batchcmds:vrunv(cppfront.program, argv) - batchcmds:compile(sourcefile_cpp, objectfile, {configs = {languages = "c++20"}}) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.cpp2 %s", sourcefile_cpp2) + batchcmds:mkdir(basedir) + batchcmds:vrunv(cppfront.program, argv) + if not is_h2 then + batchcmds:compile(sourcefile_cpp, objectfile, {configs = {languages = "c++20"}}) + end - -- add deps - batchcmds:add_depfiles(sourcefile_cpp2) - batchcmds:set_depmtime(os.mtime(objectfile)) - batchcmds:set_depcache(target:dependfile(objectfile)) + -- add deps + batchcmds:add_depfiles(sourcefile_cpp2) + if not is_h2 then + batchcmds:set_depmtime(os.mtime(objectfile)) + batchcmds:set_depcache(target:dependfile(objectfile)) + end + end + end) |
