See ABOUT.md for background information, why this repo exists, why it's set up this way, etc.
Build targets and dependencies in this repo are managed by bazel, so there are BUILD.bazel files located in most directories.
I've included a top-level Makefile with some helper targets:
make gazelle, make gofmt and so on just to save some typing at the terminal.
- git clone this repo
- install bazelisk
- Now
bazel build //...should work
brew install coreutils(in order to install therealpathcli command, which is used bybazel run //:go).
You should now be able to bazel build //..., bazel run //... etc whatever targets are defined in this repo.
Commands for updating, building, testing and running things in this repo:
- build:
bazel build //<target> - test:
bazel test //<target> - run:
bazel run //<target>
Instead of running
go <command> <args...>
run this form:
bazel run //:go -- <command> <args...>
Doing so will make sure your go command is use the same toolchain and environment that bazel does when it deals with your go targets.
This is a little more complicated than it might be in a purely go-based project repo, but it's still pretty straightforward:
Suppose you want to use an external go package. We'll use github.com/urfave/cli/v2 as an example:
- run
bazel run //:go -- get github.com/urfave/cli/v2to updatego.mod - add
"github.com/urfave/cli/v2"to your.gofile'simports - run
make gazelleto updatego_modules.bzlbased on the aforementioned update togo.mod
Note that bazel build does not actually look at the contents of go.mod - it uses go_dependencies.bzl, which make gazelle generates from go.mod.
Use bazel run @pnpm instead of npm:
bazel run @pnpm -- install --dir $(pwd) <package name> [options...]
e.g.:
bazel run @pnpm -- install --dir $(pwd) -D prettier -w
Edit requirements.in (NOT requirements.txt) to reflect your updated direct dependencies - packages your code actually imports, directly, by name.
- Add the name you would normally use for
pip install <package-name>torequirements.in. - You probably need to figure out which version of the package you need and also specify it on that same line, separated by
==. Seerequirements.infor examples. - Run
bazel run //:requirements.updatein the root directory of this repo. This will generate the fullrequirements.txtfile including all the direct dependency's transitive dependencies as well. - In your
py_binaryorpy_libraryetc target, you'll need to add new lines to thedeps=[...]list:requirement("<package name>"),. (You may need to addload("@pip_deps//:requirements.bzl", "requirement")to that BUILD file if it's not there already.)
Maintaining BUILD targets by hand can be a pain. To automatically update BUILD.bazel files based on source import statements (and protobuf options, etc): run bazel run //:gazelle.