Skip to content
Open
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
62 changes: 39 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
# Go Rules
This repo provides Golang build rules for the [Please](https://please.build) build system.

# Basic usage
This repo provides [Go](https://go.dev/) build rules for the [Please](https://please.build) build system.

Go is especially suited to writing command line tools and utilities. Binaries can be run with `plz run`, or used
as tools for [custom rules](https://please.build/codelabs/genrule/#0).

# Installation
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just recommend using plz init plugin go here? (and maybe leave the manual process as an appendix)


First, add the plugin to your Please repo. In `plugins/BUILD`:
Copy link
Contributor

Choose a reason for hiding this comment

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

It isn't strictly required that it be plugins/BUILD; can we rephrase this?


First add the plugin to your project. In `plugins/BUILD`:
```python
plugin_repo(
name = "go",
revision="vx.x.x",
revision = "vx.x.x", # A go-rules version
Copy link
Contributor

Choose a reason for hiding this comment

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

Where should the reader find which version to use?

)
```

Then add the plugin config:
Next, define a version of Go for the plugin to use. In `third_party/go/BUILD`:

```python
subinclude("///go//build_defs:go")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we recommend

[parse]
preloadsubincludes = ///go//build_defs:go

(plz plugin init sets this up)

Copy link

Choose a reason for hiding this comment

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

Agreed.

The phases of plz initialization and implicit actions are barriers to entry. Documentation should put users on the happy path/path of least resistance, not the path of maximal detail. The detail needs to be explained someplace, but it shouldn't be in the readmes that get things up to speed for a user. If people want to see what changed, git diff should be sufficient to see what happens when someone runs plz plugin init go, or whatever. $0.02.


go_toolchain(
name = "toolchain",
version = "1.x.x", # A Go version (see https://go.dev/dl/)
)
```

Finally, configure the plugin in `.plzconfig`:

```ini
[Plugin "go"]
Target = //plugins:go
GoTool = //third_party/go:toolchain|go
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to add Stdlib here?

ImportPath = github.com/example/repo
```

You can then compile and test go Packages like so:
# Basic usage

```python
subinclude("///go//build_defs:go")

Expand All @@ -41,15 +60,27 @@ go_test(
)
```

You can define third party code using `go_get`:
Compile binaries with `go_binary`:

```python
subinclude("///go//build_defs:go")

go_binary(
name = "bin",
srcs = ["main.go"],
)
```

Introduce dependencies on third-party Go modules with `go_repo`:
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth a reference to puku here?

Copy link

Choose a reason for hiding this comment

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

Worth doing, but puku is not quite my friend yet: I still routinely fall back to go_module and find myself fighting puku sync with some degree of regularity. The idealized end-to-end workflow for "day in the life of an engineer using a repo with plz" isn't well defined and requires a fair amount of digging.


```python
subinclude("///go//build_defs:go")

# We can give direct modules a name, and install list so we can reference them nicely as :testify
go_repo(
name = "testify",
module = "github.com/stretchr/testify",
version="v1.8.2",
version = "v1.8.2",
# We add the subset of packages we actually depend on here
install = [
"assert",
Expand All @@ -63,18 +94,3 @@ go_repo(module = "github.com/pmezard/go-difflib", version="v1.0.0")
go_repo(module = "github.com/stretchr/objx", version="v0.5.0")
go_repo(module = "gopkg.in/yaml.v3", version="v3.0.1")
```

To compile a binary, you can use `go_binary()`:
```python
subinclude("///go//build_defs:go")

go_binary(
name = "bin",
srcs = ["main.go"],
)
```

Go is especially well suited to writing command line tools and utilities. Binaries can be ran with `plz run`, or used
as a tool for other [custom rules](https://please.build/codelabs/genrule/#0).

**WARNING: From Go 1.20, Golang no longer ships the precompiled standard library and thus you MUST use `go_toolchain` or `go_system_toolchain`.**