summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2020-07-24 22:36:33 +0800
committerruki <[email protected]>2020-07-24 22:36:33 +0800
commit6b89d8b1edc849f8324dae490e635dca080ac473 (patch)
tree51f863f80ffbc70d7f8ac3d9b8489d340abdedcd /xmake
parent3ad0524f1c963c974741285b633157f3f28718db (diff)
inherit go modules
Diffstat (limited to 'xmake')
-rw-r--r--xmake/rules/go/xmake.lua5
-rw-r--r--xmake/rules/utils/inherit_links/inherit_links.lua4
-rw-r--r--xmake/templates/go/console/project/src/main.go9
-rw-r--r--xmake/templates/go/console/project/xmake.lua6
-rw-r--r--xmake/templates/go/static/project/xmake.lua20
5 files changed, 12 insertions, 32 deletions
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}