-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrule_go.yue
34 lines (29 loc) · 929 Bytes
/
rule_go.yue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-- example rule for go, without needing to use xmake's builtin dep handling.
-- if you use `go mod`, this is for you.
-- obviously this does not benefit from xmake's other builtins, but that's life
macro raw = (code) ->
{ :code, type: "lua" }
rule "custgolang"
do
set_extensions ".go"
on_link () -> nil
on_build_file (target, files, opt) ->
$raw[[
import("core.project.depend")
import("utils.progress")
]]
os.mkdir target\targetdir!
relp = path.join target\targetdir!, (path.basename target\name!)
if target\is_plat "windows"
relp ..= ".exe"
depend.on_changed (() ->
os.vrunv "go", { "build", "-v", "-o", relp, target\name! }
), { dependfile: (target\dependfile relp), files: files, always_changed: false }
--[[
example use, with a go.mod pkg of `coolpkg`:
target "coolpkg/cmd/thing"
do
set_kind "binary"
add_rules "custgolang"
add_files "cmd/thing/*.go"
]]