summaryrefslogtreecommitdiff
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
parent3ad0524f1c963c974741285b633157f3f28718db (diff)
inherit go modules
-rw-r--r--tests/projects/go/console/src/main.go9
-rw-r--r--tests/projects/go/console/xmake.lua8
-rw-r--r--tests/projects/go/console_with_deps/src/main.go11
-rw-r--r--tests/projects/go/console_with_deps/xmake.lua6
-rw-r--r--tests/projects/go/static_library/xmake.lua20
-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
10 files changed, 31 insertions, 67 deletions
diff --git a/tests/projects/go/console/src/main.go b/tests/projects/go/console/src/main.go
index 8ea127243..b689db480 100644
--- a/tests/projects/go/console/src/main.go
+++ b/tests/projects/go/console/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/tests/projects/go/console/xmake.lua b/tests/projects/go/console/xmake.lua
index b263bdac7..753a88a08 100644
--- a/tests/projects/go/console/xmake.lua
+++ b/tests/projects/go/console/xmake.lua
@@ -1,12 +1,6 @@
--- add rules
add_rules("mode.debug", "mode.release")
--- add target
-target("console_go")
-
- -- set kind
+target("test")
set_kind("binary")
-
- -- add files
add_files("src/*.go")
diff --git a/tests/projects/go/console_with_deps/src/main.go b/tests/projects/go/console_with_deps/src/main.go
new file mode 100644
index 000000000..cf33b2d7f
--- /dev/null
+++ b/tests/projects/go/console_with_deps/src/main.go
@@ -0,0 +1,11 @@
+package main
+
+import (
+ log "github.com/sirupsen/logrus"
+)
+
+func main() {
+ log.WithFields(log.Fields{
+ "animal": "walrus",
+ }).Info("A walrus appears")
+}
diff --git a/tests/projects/go/console_with_deps/xmake.lua b/tests/projects/go/console_with_deps/xmake.lua
new file mode 100644
index 000000000..753a88a08
--- /dev/null
+++ b/tests/projects/go/console_with_deps/xmake.lua
@@ -0,0 +1,6 @@
+add_rules("mode.debug", "mode.release")
+
+target("test")
+ set_kind("binary")
+ add_files("src/*.go")
+
diff --git a/tests/projects/go/static_library/xmake.lua b/tests/projects/go/static_library/xmake.lua
index 8284fb983..99ca434f9 100644
--- a/tests/projects/go/static_library/xmake.lua
+++ b/tests/projects/go/static_library/xmake.lua
@@ -1,30 +1,10 @@
--- add rules
add_rules("mode.debug", "mode.release")
--- add target
target("module")
-
- -- set kind
set_kind("static")
-
- -- add files
add_files("src/test/*.go")
--- add target
target("test")
-
- -- set kind
set_kind("binary")
-
- -- add deps
add_deps("module")
-
- -- add files
add_files("src/*.go")
-
- -- add link directory
- add_linkdirs("$(buildir)/$(plat)/$(arch)/$(mode)")
-
- -- add include directory
- add_includedirs("$(buildir)/$(plat)/$(arch)/$(mode)")
-
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}