Skip to content

Update documents and examples #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ They currently do not support (in order of importance):
* Decide on the name of your package, eg. `github.com/joe/project`
* Add the following to your WORKSPACE file:

```python
```bzl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw bzl == python on github.

git_repository(
name = "io_bazel_rules_go",
remote = "https://github.com/bazelbuild/rules_go.git",
Expand All @@ -50,15 +50,15 @@ They currently do not support (in order of importance):
workspace using `go_prefix`. It is strongly recommended that the prefix is not
empty.

```python
```bzl
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

```python
```bzl
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
Expand All @@ -69,7 +69,7 @@ They currently do not support (in order of importance):

* Inside your project, you can use this library by declaring a dependency

```python
```bzl
go_binary(
...
deps = ["//lib:go_default_library"]
Expand All @@ -82,7 +82,7 @@ They currently do not support (in order of importance):
libraries should have BUILD files like normal libraries.
* To declare a test,

```python
```bzl
go_test(
name = "mytest",
srcs = ["file_test.go"],
Expand Down Expand Up @@ -117,7 +117,7 @@ These rules are not supported by Google's Go team.
<a name="go_prefix"></a>
## go\_prefix

```python
```bzl
go_prefix(prefix)
```

Expand Down Expand Up @@ -154,7 +154,7 @@ go_prefix(prefix)
<a name="go_library"></a>
## go\_library

```python
```bzl
go_library(name, srcs, deps, data)
```
<table class="table table-condensed table-bordered table-params">
Expand Down Expand Up @@ -203,7 +203,7 @@ go_library(name, srcs, deps, data)
<a name="cgo_library"></a>
## cgo\_library

```python
```bzl
cgo_library(name, srcs, copts, linkopts, deps, data)
```
<table class="table table-condensed table-bordered table-params">
Expand Down Expand Up @@ -273,9 +273,9 @@ cgo_library(name, srcs, copts, linkopts, deps, data)
So you need to define another `go_library` when you build a go package with
both cgo-enabled and pure-Go sources.

```python
```bzl
cgo_library(
name = "cgo-enabled",
name = "cgo_enabled",
srcs = ["cgo-enabled.go", "foo.cc", "bar.S", "baz.a"],
)

Expand All @@ -289,7 +289,7 @@ go_library(
<a name="go_binary"></a>
## go\_binary

```python
```bzl
go_binary(name, srcs, deps, data)
```
<table class="table table-condensed table-bordered table-params">
Expand All @@ -314,8 +314,8 @@ go_binary(name, srcs, deps, data)
<td><code>srcs</code></td>
<td>
<code>List of labels, required</code>
<p>List of Go <code>.go</code> source files used to build the
binary</p>
<p>List of Go <code>.go</code> (at least one) or ASM <code>.s/.S</code>
source files used to build the binary</p>
</td>
</tr>
<tr>
Expand All @@ -338,7 +338,7 @@ go_binary(name, srcs, deps, data)
<a name="go_test"></a>
## go\_test

```python
```bzl
go_test(name, srcs, deps, data)
```
<table class="table table-condensed table-bordered table-params">
Expand All @@ -363,8 +363,8 @@ go_test(name, srcs, deps, data)
<td><code>srcs</code></td>
<td>
<code>List of labels, required</code>
<p>List of Go <code>.go</code> source files used to build the
test</p>
<p>List of Go <code>.go</code> (at least one) or ASM <code>.s/.S</code>
source files used to build the test</p>
</td>
</tr>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion examples/bin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go_binary(
srcs = ["bin.go"],
deps = [
"//examples/lib:go_default_library",
"//examples/vendor/github.com/user/vendored:go_default_library",
"//examples/vendor/github.com/user/vendored:go_default_library",
],
x_defs = {
"main.buildTime": "2016/05/19 09:10am",
Expand Down
3 changes: 1 addition & 2 deletions examples/bin/bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ package main
import (
"fmt"

"github.com/user/vendored"

"github.com/bazelbuild/rules_go/examples/lib"
"github.com/user/vendored"
)

var buildTime string
Expand Down
13 changes: 8 additions & 5 deletions go/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def _go_importpath(ctx):

def emit_go_compile_action(ctx, sources, deps, out_lib, extra_objects=[]):
"""Construct the command line for compiling Go code.
Constructs a symlink tree to accomodate for workspace name.
Constructs a symlink tree to accommodate for workspace name.

Args:
ctx: The skylark Context.
Expand Down Expand Up @@ -365,7 +365,8 @@ def emit_go_link_action(ctx, importmap, transitive_libs, cgo_deps, lib,

# workaround for a bug in ld(1) on Mac OS X.
# http://lists.apple.com/archives/Darwin-dev/2006/Sep/msg00084.html
# TODO(yugui) Remove this workaround once rules_go stops supporting XCode 7.2 or earlier.
# TODO(yugui) Remove this workaround once rules_go stops supporting XCode 7.2
# or earlier.
if ctx.fragments.cpp.cpu != 'darwin':
link_cmd += ["-s"]

Expand All @@ -377,7 +378,8 @@ def emit_go_link_action(ctx, importmap, transitive_libs, cgo_deps, lib,

cmds = symlink_tree_commands(out_dir, tree_layout)
# Avoided -s on OSX but but it requires dsymutil to be on $PATH.
# TODO(yugui) Remove this workaround once rules_go stops supporting XCode 7.2 or earlier.
# TODO(yugui) Remove this workaround once rules_go stops supporting XCode 7.2
# or earlier.
cmds += ["export PATH=$PATH:/usr/bin"]
cmds += [
"export GOROOT=$(pwd)/" + ctx.file.go_tool.dirname + "/..",
Expand Down Expand Up @@ -816,7 +818,8 @@ def cgo_library(name, srcs,
name: A unique name for this rule.
srcs: List of Go, C and C++ files that are processed to build a Go library.
Those Go files must contain `import "C"`.
C and C++ files can be anything allowed in `srcs` attribute of `cc_library`.
C and C++ files can be anything allowed in `srcs` attribute of
`cc_library`.
copts: Add these flags to the C++ compiler.
linkopts: Add these flags to the C++ linker.
deps: List of C/C++ libraries to be linked into the binary target.
Expand All @@ -830,7 +833,7 @@ def cgo_library(name, srcs,

```
cgo_library(
name = "cgo-enabled",
name = "cgo_enabled",
srcs = ["cgo-enabled.go", "foo.cc", "bar.S", "baz.a"],
)

Expand Down