Skip to content

Commit

Permalink
README: detail how to use bazel rule [skip ci]
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Koch <chrisko@google.com>
  • Loading branch information
hugelgupf committed Sep 17, 2020
1 parent fa615d9 commit 0f9a791
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,56 @@ git clone https://github.com/gokrazy/gokrazy
makebb ./p9/cmd/* ./gokrazy/cmd/*
```

For the moment, `makebb` is tested with repositories on the local file system.
Using Go import paths is supported, as well, but not as well-tested.

### APIs

Besides the makebb CLI command, there is a
[Go API at src/pkg/bb](https://pkg.go.dev/github.com/u-root/gobusybox/src/pkg/bb)
and bazel rules in [src/gobb2.bzl](src/gobb2.bzl).

#### Using bazel go_busybox rule

Assuming you have [rules_go](https://github.com/bazelbuild/rules_go) set up, add
the following to your `WORKSPACE`:

```bzl
git_repository(
name = "com_github_u_root_gobusybox",

# We do not have regular releases yet.
#
# We also do not guarantee compatibility yet, so it may be worth choosing a
# commit and setting `commit = "hash"` here instead of the branch.
branch = "main",
remote = "https://github.com/u-root/gobusybox.git",
)
```

Then, in any `BUILD` file, you can create a busybox like this:

```bzl
load("@com_github_u_root_gobusybox//src:gobb2.bzl", "go_busybox")

go_busybox(
name = "bb",
cmds = [
# These must be absolute labels, for the moment, and each command must
# be listed individually. (No :... or :all target patterns.)
"//cmd/foobar",
"//cmd/otherbar",

# Another repository's go_binarys are totally fine, e.g. if imported
# with gazelle's go_repository rule.
"@com_github_u-root_u-root//cmds/core/ls",
],
)
```

For the moment, the targets listed on `cmds` must be **individual, absolute
labels** (issue [#38](https://github.com/u-root/gobusybox/issues/38)).

### Shortcomings

- Any *imported* packages' `init` functions are run for *every* command.
Expand Down

0 comments on commit 0f9a791

Please sign in to comment.