Compare commits

...

10 Commits

Author SHA1 Message Date
6f40b3a405 start 2023-07-03 17:30:53 -05:00
328aa0b8f5 Merge pull request #1 from paniag/master
Fix broken configs for "remote" and "bare" repos.
2017-04-26 21:21:45 -07:00
d37b5ce6c1 Fix repo reference to go.bzl. 2016-04-14 08:39:29 -07:00
aecf949a2a Update to working commit for ws_remote repo. 2016-04-14 08:35:58 -07:00
decd76f19d Minor whitespace, README update. 2016-03-21 16:58:04 -07:00
dad6f57d6d Update WORKSPACE / BUILD to work with bazel at HEAD.
Uses external rules_go github repository.
2016-03-21 16:56:03 -07:00
f189432d24 Add the vendor/ path, and add git submodules to the appropriate
subdirectory paths under vendor/

The intent is to make use of the golang 1.6 VENDOR extension
to build. As seen, the bare example does not correctly build
using bazel in this mode.
2016-03-17 18:39:54 -07:00
53207a1865 Hack around broken bazel go build rules.
Fix comment in submodule/remote.go
2016-03-03 18:14:20 -08:00
dfd84d2172 Hack around broken bazel golang build rules. 2016-03-03 18:12:32 -08:00
a2e269c3f3 Update README with better description. 2016-03-03 15:52:56 -08:00
24 changed files with 96 additions and 149 deletions

6
.gitignore vendored
View File

@ -1 +1,5 @@
bazel-*
bazel-bazel-*
bazel-bin
bazel-genfiles
bazel-out
bazel-testlogs

6
.gitmodules vendored
View File

@ -4,3 +4,9 @@
[submodule "submodule/src/remote"]
path = submodule/src/remote
url = git://github.com/laramiel/bazel-example-golang-remote
[submodule "vendor/github.com/laramiel/bazel-example-golang-remote"]
path = vendor/github.com/laramiel/bazel-example-golang-remote
url = git://github.com/laramiel/bazel-example-golang-remote
[submodule "vendor/github.com/laramiel/bazel-example-golang-bare"]
path = vendor/github.com/laramiel/bazel-example-golang-bare
url = git://github.com/laramiel/bazel-example-golang-bare

35
BUILD
View File

@ -1,36 +1,13 @@
load("@bazel_tools//tools/build_rules/go:def.bzl", "go_prefix", "go_binary")
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
package(
default_visibility = ["//visibility:public"],
)
go_prefix("github.com/laramiel/bazel-example-golang/")
go_binary(
name ="hello",
srcs = [ "hello.go" ],
)
go_binary(
name ="local",
srcs = [ "local.go" ],
deps = [
"//local",
],
)
go_binary(
name ="remote",
srcs = [ "remote.go" ],
deps = [
"@remote//:remote",
],
)
go_binary(
name ="bare",
srcs = [ "bare.go" ],
deps = [
"@bare//:bare",
],
name = "hello",
srcs = ["hello.go"],
deps = [
"//cmd",
]
)

View File

@ -8,15 +8,47 @@ This requires bazel release > `bazel-0.20`.
```
$ git clone https://github.com/laramiel/bazel-example-golang.git
$ cd bazel-example-golang
$ git submodule init
$ git submodule foreach git pull origin master
$ bazel run :hello
$ bazel run :local
$ bazel run :remote
$ bazel run :bare
$ git submodule update --init --recursive
$ bazel run //submodule:bare
$ bazel run //submodule:remote
$ bazel run //with_vendor:remote
$ bazel run //with_vendor:bare
```
# Explanation
This repository works in conjunction with other git repositories to
provide a demonstration of Bazel BUILD rules for golang.
* [bazel-example-golang](https://github.com/laramiel/bazel-example-golang)
The main repository, demonstrating binary, local, and remote repository usage.
* [bazel-example-golang-remote](https://github.com/laramiel/bazel-example-golang-remote)
An example remote repository which includes Bazel rules.
* [bazel-example-golang-bare](https://github.com/laramiel/bazel-example-golang-bare)
An example remote repository without any Bazel rules.
Each of the remote repositories is linked into `go_binary()` targets in several
ways:
1. Using the WORKSPACE file to define `git_repository()` rules.
This accounts for the `:remote` and `:bare` targets.
2. Using git submodules to import the repository source, and
using those paths. This accounts for the `//submodule:bare`
and `//submodule:remote` targets.
3. Using the VENDOR extension introduced in go1.6.

View File

@ -1,30 +1,23 @@
load("@bazel_tools//tools/build_rules/go:def.bzl", "go_repositories")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
go_repositories()
# git_repository(
# name = "io_bazel_rules_go",
# remote = "https://github.com/bazelbuild/rules_go.git",
# branch = "master",
# )
git_repository(
name = "remote",
remote = "https://github.com/laramiel/bazel-example-golang-remote.git",
commit = "8f2e405",
http_archive(
name = "io_bazel_rules_go",
sha256 = "6b65cb7917b4d1709f9410ffe00ecf3e160edf674b78c54a894471320862184f",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip",
],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
BARE_BUILD = """
load("@bazel_tools//tools/build_rules/go:def.bzl", "go_prefix", "go_library")
go_rules_dependencies()
go_prefix("github.com/laramiel/bazel-example-golang-bare")
go_library(
name = "bare",
srcs = [ "bare.go" ],
visibility = ["//visibility:public"],
)
"""
new_git_repository(
name = "bare",
remote = "https://github.com/laramiel/bazel-example-golang-bare.git",
commit = "3bd848f",
build_file_content = BARE_BUILD
)
go_register_toolchains(version = "1.19.3")

10
bare.go
View File

@ -1,10 +0,0 @@
package main
import (
"fmt"
"github.com/laramiel/bazel-example-golang-bare/bare"
)
func main() {
fmt.Println("Hello", bare.World())
}

1
bazel-lotr Symbolic link
View File

@ -0,0 +1 @@
/private/var/tmp/_bazel_christian/3262850bcac806b0124f7f44b81dceb1/execroot/__main__

8
cmd/BUILD Normal file
View File

@ -0,0 +1,8 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name ="cmd",
srcs = [ "cmd.go" ],
visibility = ["//visibility:public"],
importpath= "github.com/squk/lotr/cmd"
)

9
cmd/cmd.go Normal file
View File

@ -0,0 +1,9 @@
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello World. Cmd")
}

1
data/Bot.Cards.json Normal file

File diff suppressed because one or more lines are too long

1
data/Export.Cards.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
package main
package main
import (
"fmt"

View File

@ -1,10 +0,0 @@
package main
import (
"fmt"
"github.com/laramiel/bazel-example-golang/local/local"
)
func main() {
fmt.Println("Hello ", local.World())
}

View File

@ -1,7 +0,0 @@
load("@bazel_tools//tools/build_rules/go:def.bzl", "go_library")
go_library(
name ="local",
srcs = [ "local.go" ],
visibility = ["//visibility:public"],
)

View File

@ -1,5 +0,0 @@
package local
func World() string {
return "local.World!"
}

View File

@ -1,10 +0,0 @@
package main
import (
"fmt"
"github.com/laramiel/bazel-example-golang-remote/remote"
)
func main() {
fmt.Println("Hello ", remote.World())
}

View File

@ -1,21 +0,0 @@
load("@bazel_tools//tools/build_rules/go:def.bzl", "go_prefix", "go_binary")
package(
default_visibility = ["//visibility:public"],
)
go_binary(
name ="bare",
srcs = [ "bare.go" ],
deps = [
"//submodule/src:bare",
],
)
go_binary(
name ="remote",
srcs = [ "remote.go" ],
deps = [
"//submodule/src/remote",
],
)

View File

@ -1,10 +0,0 @@
package main
import (
"fmt"
"github.com/laramiel/bazel-example-golang-bare/bare"
)
func main() {
fmt.Println("Hello", bare.World())
}

View File

@ -1,10 +0,0 @@
package main
import (
"fmt"
"github.com/laramiel/bazel-example-golang-remote/remote"
)
func main() {
fmt.Println("Hello", remote.World())
}

View File

@ -1,9 +0,0 @@
load("@bazel_tools//tools/build_rules/go:def.bzl", "go_prefix", "go_library")
go_prefix("github.com/laramiel/bazel-example-golang-bare/")
go_library(
name = "bare",
srcs = [ "bare/bare.go" ],
visibility = ["//visibility:public"],
)

7
vendor/github.com/laramiel/BUILD generated vendored Normal file
View File

@ -0,0 +1,7 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "bare",
srcs = ["bazel-example-golang-bare/bare.go"],
visibility = ["//visibility:public"],
)