diff options
| author | ruki <[email protected]> | 2024-04-07 23:57:16 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-04-07 23:57:16 +0800 |
| commit | 1cdbbde962a0699c21be76529ec2493f18b21feb (patch) | |
| tree | 57a0f5c9481bef399d0567fc3c3ccfe2a3b70c94 | |
| parent | 7e0f8751549ed166fefa13afb300527b76bb190a (diff) | |
| parent | 0539773b74bcc7eabab6f16a8d1760c79bf75a14 (diff) | |
Merge pull request #4943 from shaoxie1986/dev
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 | 36 |
4 files changed, 41 insertions, 6 deletions
diff --git a/tests/projects/cppfront/console/src/main.cpp2 b/tests/projects/cppfront/console/src/main.cpp2 index 1ab54b94b..1c8bf1c0e 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..b90222aa9 100644 --- a/xmake/rules/cppfront/xmake.lua +++ b/xmake/rules/cppfront/xmake.lua @@ -18,9 +18,38 @@ -- @file xmake.lua -- +rule("cppfront.build.h2") + set_extensions(".h2") + + on_buildcmd_file(function (target, batchcmds, sourcefile_h2, opt) + + -- get cppfront + import("lib.detect.find_tool") + local cppfront = assert(find_tool("cppfront", {check = "-h"}), "cppfront not found!") + + -- get h header file for h2 + local sourcefile_h = target:autogenfile((sourcefile_h2:gsub(".h2$", ".h"))) + local basedir = path.directory(sourcefile_h) + + -- add commands + local argv = {"-o", path(sourcefile_h), path(sourcefile_h2)} + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.h2 %s", sourcefile_h2) + batchcmds:mkdir(basedir) + batchcmds:vrunv(cppfront.program, argv) + + -- add deps + batchcmds:add_depfiles(sourcefile_h2) + batchcmds:set_depmtime(os.mtime(sourcefile_h)) + batchcmds:set_depcache(target:dependfile(sourcefile_h)) + end) + -- define rule: cppfront.build -rule("cppfront.build") +rule("cppfront.build.cpp2") set_extensions(".cpp2") + + -- .h2 must compile before .cpp2 + add_deps("cppfront.build.h2", {order = true}) + on_load(function (target) -- only cppfront source files? we need to patch cxx source kind for linker local sourcekinds = target:sourcekinds() @@ -66,8 +95,11 @@ rule("cppfront.build") -- define rule: cppfront rule("cppfront") + -- add_build.h2 rules + add_deps("cppfront.build.h2") + -- add build rules - add_deps("cppfront.build") + add_deps("cppfront.build.cpp2") -- set compiler runtime, e.g. vs runtime add_deps("utils.compiler.runtime") |
