Skip to content
Open
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: 23 additions & 9 deletions docs/codelabs/genrule.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ Duration: 3

Before we jump into writing custom build definitions, let me introduce you to `genrule()`, the generic build rule. Let's
just create a new project and initialise Please in it:
```
$ mkdir custom_rules && cd custom_rules
$ plz init --no_prompt
```bash
mkdir custom_rules && cd custom_rules
plz init --no_prompt
```

Then create a `BUILD` file in the root of the repository like so:
Expand All @@ -54,13 +54,13 @@ genrule(
```

Then create file.txt:
```
$ echo "the quick brown fox jumped over the lazy dog" > file.txt
```bash
echo "the quick brown fox jumped over the lazy dog" > file.txt
```

and build it:

```
```bash
$ plz build //:word_count
Build finished; total time 70ms, incrementality 0.0%. Outputs:
//:word_count:
Expand All @@ -70,6 +70,14 @@ $ cat plz-out/gen/file.wc
1 9 45 file.txt
```

### Troubleshooting: "can't store data at section "scm""

This message means the runner is using an older Please release that doesn’t understand the `[scm]` section in your `.plzconfig`, so parsing fails before any build work begins.

**How to fix**
- Upgrade the Please version invoked in CI (pin the same version locally via `pleasew`, `setup-please`, or `PLZ_VERSION`).
- If upgrading immediately is impractical, temporarily remove or comment the `[scm]` block until the runner is updated.

### So what's going on?
Here we've used one of the built-in rules, `genrule()`, to run a custom command. `genrule()` can take a number of
parameters, most notably: the name of the rule, the inputs (sources and dependencies), its outputs, and the command
Expand Down Expand Up @@ -199,8 +207,12 @@ word_count(

And check it still works:

```bash
plz build //:word_count
```
The output:

```
$ plz build //:word_count
Build finished; total time 30ms, incrementality 100.0%. Outputs:
//:word_count:
plz-out/gen/word_count.wc
Expand Down Expand Up @@ -261,9 +273,10 @@ wc -w $@

### `tools/BUILD`
```python
sh_binary(
filegroup(
name = "wc",
main = "wc.sh",
srcs = ["wc.sh"],
binary = True,
visibility = ["PUBLIC"],
)
```
Expand Down Expand Up @@ -392,3 +405,4 @@ If you create something you believe will be useful to the wider world, we might
[pleasings](https://github.com/thought-machine/pleasings) repo!

If you get stuck, jump on [gitter](https://gitter.im/please-build/Lobby) and we'll do our best to help you!

3 changes: 1 addition & 2 deletions docs/codelabs/github_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ stuck you can find us on [gitter](https://gitter.im/please-build/Lobby)!
## GitHub Actions
Duration: 5

GitHub Actions is an extensible CI/CD platform provided by GitHub.
Compared to other CI/CD solutions, GitHub Actions allows you to build all kinds automations (called workflows) triggered by various events (eg. pushing code to a branch).
GitHub Actions is GitHub's built-in automation platform for CI/CD and other workflows. It runs workflows defined as YAML files in the .github/workflows directory, triggered by events (push, pull_request, schedule, manual, etc.). Workflows consist of jobs (run on hosted or self‑hosted runners) and steps that execute shell commands or reusable actions from the marketplace. Key benefits include tight GitHub integration, flexible triggers and matrices, a large action marketplace, and caching for faster builds.

### Setting up GitHub Actions

Expand Down
57 changes: 40 additions & 17 deletions docs/codelabs/go_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ Duration: 2

The easiest way to get started is from an existing Go module:

```text
$ mkdir getting_started_go && cd getting_started_go
$ plz init
$ plz init plugin go
$ go mod init github.com/example/module
```bash
mkdir getting_started_go && cd getting_started_go
plz init
plz init plugin go
go mod init github.com/example/module
```


Expand Down Expand Up @@ -78,6 +78,16 @@ This configures the Go plugin, and makes the build definitions available in the
automatically. Alternatively, if you're not using Go everywhere, you can remove the `preloadsubincludes` config and add
`subinclude("///go//build_defs:go")` to each `BUILD` file that needs access to Go rules.

### Troubleshooting: "unknown rule go_binary"
Duration: 1

Seeing `unknown rule go_binary` (or similar for other Go rules) means the plugin was not loaded. Confirm the plugin target exists and re-run the init script if needed.

**Fix checklist**
- `plz query config Plugin.go.Target` should report `//plugins:go`.
- Ensure `plugins/BUILD` is present and contains the Go plugin target.
- If `.plzconfig` was edited manually, re-run `plz init plugin go` or restore the snippet above.

Read the [config](/config.html) and [go plugin config](/plugins.html#go.config) docs for more information on
configuration.

Expand Down Expand Up @@ -143,8 +153,8 @@ Path = /usr/local/go/bin:/usr/local/bin:/usr/bin:/bin
Additionally, from version 1.20, golang no longer includes the standard library with its distribution. To use 1.20 from
the path with Please, you must install it. This can be done like so:

```text
$ GODEBUG="installgoroot=all" go install std
```bash
GODEBUG="installgoroot=all" go install std
```

## Hello, world!
Expand All @@ -158,8 +168,8 @@ package main

import "fmt"

func main(){
fmt.Println("Hello, world!")
func main() {
fmt.Println("Hello, world!")
}
```

Expand All @@ -175,8 +185,14 @@ go_binary(
```

That's it! You can now run this with:

```bash
plz run //src:main
```

You should see the output:

```text
$ plz run //src:main
Hello, world!
```

Expand Down Expand Up @@ -223,13 +239,18 @@ go_library(
)
```

We can then build it like so:
Then run the following command to build the greetings package:

```bash
plz build //src/greetings
```

You should see output similar to:

```text
$ plz build //src/greetings
Build finished; total time 290ms, incrementality 50.0%. Outputs:
//src/greetings:greetings:
plz-out/gen/src/greetings/greetings.a
plz-out/gen/src/greetings/greetings.a
```

Here we can see that the output of a `go_library` rule is a `.a` file which is stored in
Expand All @@ -244,7 +265,7 @@ NB: This syntax can also be used on the command line e.g. `plz build //src/...`
## Using our new package
Duration: 2
To maintain a principled model for incremental and hermetic builds, Please requires that rules are explicit about their
inputs and outputs. To use this new package in our "hello world" program, we have to add it as a dependency:
inputs and outputs. To use this new package in our "hello world" program, we have to add it as a dependency of our binary rule:

### `src/BUILD`
```python
Expand All @@ -270,18 +291,20 @@ import (
"github.com/example/module/src/greetings"
)

func main(){
func main() {
fmt.Printf("%s, world!\n", greetings.Greeting())
}
```

Give it a whirl:
Give it a whirl by running the following command:

```text
$ plz run //src:main
Bonjour, world!
```

The greeting is selected at random, so your output may vary each time you run the command.

## Testing our code
Duration: 5

Expand Down Expand Up @@ -338,7 +361,7 @@ package greetings_test

import (
"testing"

// We now need to import the "production" package
"github.com/example/module/src/greetings"
)
Expand Down
Loading