Skip to content

Commit

Permalink
Add Add cppfront's header(*.h2) support,use add_deps instead of on_bu…
Browse files Browse the repository at this point in the history
…ildcmd_file,
  • Loading branch information
shaoxie1986 committed Apr 7, 2024
1 parent 014639a commit 4044b79
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
6 changes: 2 additions & 4 deletions tests/projects/cppfront/console/src/main.cpp2
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "println.h2"
main: () -> int =
println("Hello world!\n");

println: (msg: _) -> int = {
std::cout << msg;
return 0;
}

4 changes: 4 additions & 0 deletions tests/projects/cppfront/console/src/println.h2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
println: (msg: _) -> int = {
std::cout << msg;
return 0;
}
1 change: 1 addition & 0 deletions tests/projects/cppfront/console/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ target("test")
add_rules("cppfront")
set_kind("binary")
add_files("src/*.cpp2")
add_files("src/*.h2")
add_packages("cppfront")

32 changes: 32 additions & 0 deletions xmake/rules/cppfront/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.cpp2 %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")
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()
Expand Down Expand Up @@ -66,6 +95,9 @@ rule("cppfront.build")
-- define rule: cppfront
rule("cppfront")

-- add_build.h2 rules
add_deps("cppfront.build.h2")

-- add build rules
add_deps("cppfront.build")

Expand Down

0 comments on commit 4044b79

Please sign in to comment.