From 6b89d8b1edc849f8324dae490e635dca080ac473 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 24 Jul 2020 22:36:33 +0800 Subject: inherit go modules --- xmake/rules/go/xmake.lua | 5 +++++ xmake/rules/utils/inherit_links/inherit_links.lua | 4 ++++ xmake/templates/go/console/project/src/main.go | 9 +-------- xmake/templates/go/console/project/xmake.lua | 6 ------ xmake/templates/go/static/project/xmake.lua | 20 ++------------------ 5 files changed, 12 insertions(+), 32 deletions(-) (limited to 'xmake') diff --git a/xmake/rules/go/xmake.lua b/xmake/rules/go/xmake.lua index 8fa23e9dd..874a60ae1 100644 --- a/xmake/rules/go/xmake.lua +++ b/xmake/rules/go/xmake.lua @@ -28,4 +28,9 @@ rule("go.build") on_build_files("build.object") rule("go") + + -- add build rules add_deps("go.build") + + -- inherit links and linkdirs of all dependent targets by default + add_deps("utils.inherit.links") diff --git a/xmake/rules/utils/inherit_links/inherit_links.lua b/xmake/rules/utils/inherit_links/inherit_links.lua index ba97e4380..d55c32227 100644 --- a/xmake/rules/utils/inherit_links/inherit_links.lua +++ b/xmake/rules/utils/inherit_links/inherit_links.lua @@ -40,6 +40,10 @@ function main(target) local targetfile = target:targetfile() target:add("links", target:basename(), {interface = true}) target:add("linkdirs", path.directory(targetfile), {interface = true}) + if target:rule("go") then + -- we need add includedirs to support import modules for golang + target:add("includedirs", path.directory(targetfile), {interface = true}) + end for _, name in ipairs({"frameworkdirs", "frameworks", "linkdirs", "links", "syslinks"}) do local values = _get_values_from_target(target, name) if values and #values > 0 then diff --git a/xmake/templates/go/console/project/src/main.go b/xmake/templates/go/console/project/src/main.go index 8ea127243..b689db480 100644 --- a/xmake/templates/go/console/project/src/main.go +++ b/xmake/templates/go/console/project/src/main.go @@ -1,14 +1,7 @@ package main -/* ///////////////////////////////////////////////////////////////////////////////////////////////// - * imports - */ import "fmt" -/* ///////////////////////////////////////////////////////////////////////////////////////////////// - * main - */ func main() { - - fmt.Println("hello xmake for go!") + fmt.Println("hello xmake!") } diff --git a/xmake/templates/go/console/project/xmake.lua b/xmake/templates/go/console/project/xmake.lua index e1c7a3735..09355a74b 100644 --- a/xmake/templates/go/console/project/xmake.lua +++ b/xmake/templates/go/console/project/xmake.lua @@ -1,13 +1,7 @@ --- add modes: debug and release add_rules("mode.debug", "mode.release") --- add target target("${TARGETNAME}") - - -- set kind set_kind("binary") - - -- add files add_files("src/*.go") ${FAQ} diff --git a/xmake/templates/go/static/project/xmake.lua b/xmake/templates/go/static/project/xmake.lua index 96932450c..2e06e32ff 100644 --- a/xmake/templates/go/static/project/xmake.lua +++ b/xmake/templates/go/static/project/xmake.lua @@ -1,28 +1,12 @@ --- add target -target("module") +add_rules("mode.debug", "mode.release") - -- set kind +target("module") set_kind("static") - - -- add files add_files("src/test/*.go") --- add target target("${TARGETNAME}_demo") - - -- set kind set_kind("binary") - - -- add deps add_deps("module") - - -- add files add_files("src/*.go") - -- add link directory - add_linkdirs("$(buildir)") - - -- add include directory - add_includedirs("$(buildir)") - ${FAQ} -- cgit v1.3.1