commit | fbd0bc8f5cf2526533c9b9846db0f2f242113faf | [log] [tgz] |
---|---|---|
author | Yuki Yugui Sonoda <yugui@yugui.jp> | Thu Aug 11 05:11:57 2016 +0900 |
committer | Paul Bethe <pmbethe09@users.noreply.github.com> | Wed Aug 10 16:11:57 2016 -0400 |
tree | 261718865705230c455a97d6e9edb50b5f2816e6 | |
parent | a994fbddc874ecef1e10a9869894173558e6f0ec [diff] |
Import minimal version of gazelle, a BUILD file generator (#57)
The rules should be considered experimental. They support:
They currently do not support (in order of importance):
//+build
tagsDecide on the name of your package, eg. github.com/joe/project
Add the following to your WORKSPACE file:
git_repository( name = "io_bazel_rules_go", remote = "https://github.com/bazelbuild/rules_go.git", tag = "0.0.4", ) load("@io_bazel_rules_go//go:def.bzl", "go_repositories") go_repositories()
Add a BUILD
file to the top of your workspace, declaring the name of your workspace using go_prefix
. It is strongly recommended that the prefix is not empty.
load("@io_bazel_rules_go//go:def.bzl", "go_prefix") go_prefix("github.com/joe/project")
For a library github.com/joe/project/lib
, create lib/BUILD
, containing
load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( name = "go_default_library", srcs = ["file.go"] )
Inside your project, you can use this library by declaring a dependency
go_binary( ... deps = ["//lib:go_default_library"] )
In this case, import the library as github.com/joe/project/lib
.
For vendored libraries, you may depend on //lib/vendor/github.com/user/project:go_default_library
. Vendored libraries should have BUILD files like normal libraries.
To declare a test,
go_test( name = "mytest", srcs = ["file_test.go"], library = ":go_default_library" )
go
tool?Yes, this setup was deliberately chosen to be compatible with the go
tool. Make sure your workspace appears under
$GOROOT/src/github.com/joe/project/
eg.
mkdir -p $GOROOT/src/github.com/joe/ ln -s my/bazel/workspace $GOROOT/src/github.com/joe/project
and it should work.
These rules are not supported by Google's Go team.
go_prefix(prefix)
go_library(name, srcs, deps, data)
cgo_library(name, srcs, copts, clinkopts, cdeps, deps, data)
srcs
cannot contain pure-Go files, which do not have import "C"
. So you need to define another go_library
when you build a go package with both cgo-enabled and pure-Go sources.
cgo_library( name = "cgo_enabled", srcs = ["cgo-enabled.go", "foo.cc", "bar.S", "baz.a"], ) go_library( name = "go_default_library", srcs = ["pure-go.go"], library = ":cgo_enabled", )
go_binary(name, srcs, deps, data)
go_test(name, srcs, deps, data)