Skip to content

Commit

Permalink
Review feedback plus documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthehat committed Dec 15, 2017
1 parent 11aed7f commit e3623ea
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 165 deletions.
40 changes: 32 additions & 8 deletions go/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Core go rules
.. _gazelle: tools/gazelle/README.rst
.. _build constraints: http://golang.org/pkg/go/build/
.. _GoLibrary: providers.rst#GoLibrary
.. _GoSourceList: providers.rst#GoSourceList
.. _GoSource: providers.rst#GoSource
.. _GoArchive: providers.rst#GoArchive
.. _cgo: http://golang.org/cmd/cgo/
.. _"Make variable": https://docs.bazel.build/versions/master/be/make-variables.html
Expand All @@ -15,6 +15,8 @@ Core go rules
.. _cc library deps: https://docs.bazel.build/versions/master/be/c-cpp.html#cc_library.deps
.. _pure: modes.rst#pure
.. _static: modes.rst#static
.. _goos: modes.rst#goos
.. _goarch: modes.rst#goarch
.. _mode attributes: modes.rst#mode-attributes

.. role:: param(kbd)
Expand Down Expand Up @@ -58,7 +60,7 @@ Providers
^^^^^^^^^

* GoLibrary_
* GoSourceList_
* GoSource_
* GoArchive_

Attributes
Expand Down Expand Up @@ -94,7 +96,7 @@ Attributes
| :param:`embed` | :type:`label_list` | :value:`None` |
+----------------------------+-----------------------------+---------------------------------------+
| List of Go libraries this test library directly. |
| These may be go_library rules or compatible rules with the GoSourceList_ provider. |
| These may be go_library rules or compatible rules with the GoLibrary_ provider. |
| These can provide both :param:`srcs` and :param:`deps` to this library. |
| See Embedding_ for more information about how and when to use this. |
+----------------------------+-----------------------------+---------------------------------------+
Expand Down Expand Up @@ -167,7 +169,8 @@ Providers
^^^^^^^^^

* GoLibrary_
* GoSourceList_
* GoSource_
* GoArchive_

Attributes
^^^^^^^^^^
Expand Down Expand Up @@ -202,7 +205,7 @@ Attributes
| :param:`embed` | :type:`label_list` | :value:`None` |
+----------------------------+-----------------------------+---------------------------------------+
| List of Go libraries this binary embeds directly. |
| These may be go_library rules or compatible rules with the GoSourceList_ provider. |
| These may be go_library rules or compatible rules with the GoLibrary_ provider. |
| These can provide both :param:`srcs` and :param:`deps` to this binary. |
| See Embedding_ for more information about how and when to use this. |
+----------------------------+-----------------------------+---------------------------------------+
Expand All @@ -223,6 +226,26 @@ Attributes
| This is one of the `mode attributes`_ that controls whether to link in static_ mode. |
| It should be one of :value:`on`, :value:`off` or :value:`auto`. |
+----------------------------+-----------------------------+---------------------------------------+
| :param:`goos` | :type:`string` | :value:`auto` |
+----------------------------+-----------------------------+---------------------------------------+
| This is one of the `mode attributes`_ that controls which goos_ to compile and link for. |
| |
| If set to anything other than :value:`auto` this overrideds the default as set by the current |
| target platform, and allows for single builds to make binaries for multiple architectures. |
| |
| Because this has no control over the cc toolchain, it does not work for cgo, so if this |
| attribute is set then :param:`pure` must be set to :value:`on`. |
+----------------------------+-----------------------------+---------------------------------------+
| :param:`goarch` | :type:`string` | :value:`auto` |
+----------------------------+-----------------------------+---------------------------------------+
| This is one of the `mode attributes`_ that controls which goarch_ to compile and link for. |
| |
| If set to anything other than :value:`auto` this overrideds the default as set by the current |
| target platform, and allows for single builds to make binaries for multiple architectures. |
| |
| Because this has no control over the cc toolchain, it does not work for cgo, so if this |
| attribute is set then :param:`pure` must be set to :value:`on`. |
+----------------------------+-----------------------------+---------------------------------------+
| :param:`gc_goopts` | :type:`string_list` | :value:`[]` |
+----------------------------+-----------------------------+---------------------------------------+
| List of flags to add to the Go compilation command when using the gc compiler. |
Expand Down Expand Up @@ -314,7 +337,7 @@ Attributes
| :param:`embed` | :type:`label_list` | :value:`None` |
+----------------------------+-----------------------------+---------------------------------------+
| List of Go libraries this test embeds directly. |
| These may be go_library rules or compatible rules with the GoSourceList_ provider. |
| These may be go_library rules or compatible rules with the GoLibrary_ provider. |
| These can provide both :param:`srcs` and :param:`deps` to this test. |
| See Embedding_ for more information about how and when to use this. |
+----------------------------+-----------------------------+---------------------------------------+
Expand Down Expand Up @@ -438,7 +461,8 @@ This is used as a way of easily declaring a common set of sources re-used in mul
Providers
^^^^^^^^^

* GoSourceList_
* GoLibrary_
* GoSource_

Attributes
^^^^^^^^^^
Expand All @@ -464,7 +488,7 @@ Attributes
| :param:`embed` | :type:`label_list` | :value:`None` |
+----------------------------+-----------------------------+---------------------------------------+
| List of sources to directly embed in this list. |
| These may be go_library rules or compatible rules with the GoSourceList_ provider. |
| These may be go_library rules or compatible rules with the GoSource_ provider. |
| These can provide both :param:`srcs` and :param:`deps` to this library. |
| See Embedding_ for more information about how and when to use this. |
+----------------------------+-----------------------------+---------------------------------------+
Expand Down
26 changes: 25 additions & 1 deletion go/modes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The entire transitive set of libraries that a leaf depends on are built in the m
the binary rule. The compiled libraries are distinct and multiple modes can be built in a single pass,
but are shared between leaves building in the same mode.

Currently only static_ and pure_ can be specified as attributes.
Currently only static_, pure_, goos_ and goarch_ can be specified as attributes.
Both of these can take one of the values "on", "off" or "auto", and "auto" is the default.

+--------------+-------------------------------------------------------------------------+
Expand All @@ -88,6 +88,8 @@ following fields that control the bevhaviour of those actions:
* link_
* debug_
* strip_
* goos_
* goarch_

Build modes
-----------
Expand Down Expand Up @@ -148,6 +150,16 @@ strip

Causes debugging information to be stripped from the binaries.

goos
~~~~

This controls which operating system to target.

goarch
~~~~~~

This controls which architecture to target.

Using build modes
-----------------

Expand Down Expand Up @@ -204,3 +216,15 @@ the mode of tests by using
.. code::
bazel test --features=race //...
but in general it is strongly recommended instead to turn it on for specific tests.

.. code::
go_test(
name = "go_default_test",
srcs = ["lib_test.go"],
embed = [":go_default_library"],
race = "on",
)
1 change: 0 additions & 1 deletion go/private/actions/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def emit_binary(go,
source = None,
gc_linkopts = [],
x_defs = {},
wrap = None,
linkstamp=None,
version_file=None,
info_file=None):
Expand Down
3 changes: 1 addition & 2 deletions go/private/context.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014 The Bazel Authors. All rights reserved.
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -158,7 +158,6 @@ def go_context(ctx, attr=None):
if not stdlib:
fail("No matching standard library for "+mode_string(mode))

members = structs.to_dict(toolchain.actions)
return GoContext(
# Fields
toolchain = toolchain,
Expand Down
2 changes: 1 addition & 1 deletion go/private/rules/cgo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def _pure(ctx, mode):
def _not_pure(ctx, mode):
return not mode.pure

def _cgo_library_to_source(ctx, attr, source, merge):
def _cgo_library_to_source(go, attr, source, merge):
library = source["library"]
if source["mode"].pure:
source["srcs"] = library.input_go_srcs + source["srcs"]
Expand Down
2 changes: 1 addition & 1 deletion go/private/rules/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ load("@io_bazel_rules_go//go/private:rules/aspect.bzl",
"go_archive_aspect",
)

def _testmain_library_to_source(ctx, attr, source, merge):
def _testmain_library_to_source(go, attr, source, merge):
source["deps"] = source["deps"] + [attr.library]

def _go_test_impl(ctx):
Expand Down
Loading

0 comments on commit e3623ea

Please sign in to comment.