Skip to content

Commit

Permalink
Provide an example for the Go rules, eg.
Browse files Browse the repository at this point in the history
 bazel test examples/go/lib:lib_test
 bazel build examples/go/bin:bin

--
MOS_MIGRATED_REVID=105070940
  • Loading branch information
hanwen authored and kchodorow committed Oct 9, 2015
1 parent efb4590 commit 4718232
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 0 deletions.
4 changes: 4 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ filegroup(
name = "dummy",
visibility = ["//visibility:public"],
)

load("/tools/build_rules/go/def", "go_prefix")

go_prefix("github.com/bazelbuild/bazel")
11 changes: 11 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,14 @@ new_http_archive(
sha256 = "87494218eea2441a7a24b40f227330877dbba75c5fa9014ac6188711baed53f6",
build_file = "tools/build_defs/sass/sassc.BUILD",
)

bind(name = "go_prefix",
actual = "//:go_prefix",
)

new_http_archive(
name= "golang-linux-amd64",
url = "https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz",
build_file = "tools/build_rules/go/toolchain/BUILD.go-toolchain",
sha256 = "2593132ca490b9ee17509d65ee2cd078441ff544899f6afb97a03d08c25524e7"
)
14 changes: 14 additions & 0 deletions examples/go/bin/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package(
default_visibility = ["//visibility:public"],
)

load("/tools/build_rules/go/def", "go_binary")

go_binary(
name = "bin",
srcs = ["bin.go"],
deps = [
"//examples/go/lib:go_default_library",
"//examples/go/vendor/github_com/user/vendored:go_default_library",
],
)
14 changes: 14 additions & 0 deletions examples/go/bin/bin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"fmt"

"github_com/user/vendored"

"github.com/bazelbuild/bazel/examples/go/lib"
)

func main() {
fmt.Println("meaning: ", lib.Meaning())
fmt.Println("vendored: ", vendored.Vendored())
}
20 changes: 20 additions & 0 deletions examples/go/lib/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package(
default_visibility = ["//visibility:public"],
)

load("/tools/build_rules/go/def", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = [
"lib.go",
],
)

go_test(
name = "lib_test",
srcs = [
"lib_test.go",
],
library = ":go_default_library",
)
6 changes: 6 additions & 0 deletions examples/go/lib/lib.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package lib

// Meaning calculates the meaning of Life, the Universe and Everything.
func Meaning() int {
return 42
}
11 changes: 11 additions & 0 deletions examples/go/lib/lib_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package lib

import (
"testing"
)

func TestMeaning(t *testing.T) {
if m := Meaning(); m != 42 {
t.Errorf("got %d, want 42", m)
}
}
12 changes: 12 additions & 0 deletions examples/go/vendor/github_com/user/vendored/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package(
default_visibility = ["//visibility:public"],
)

load("/tools/build_rules/go/def", "go_library")

go_library(
name = "go_default_library",
srcs = [
"vendored.go",
],
)
6 changes: 6 additions & 0 deletions examples/go/vendor/github_com/user/vendored/vendored.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package vendored

// Vendored returns a string.
func Vendored() string {
return "I was vendored"
}

0 comments on commit 4718232

Please sign in to comment.