bazel-contrib / bazel-contrib/rules_go
Add support for GOSSAFUNC/-ssafunc SSA debug flags in rules_go
- Dominant language
- Go
- Stars
- 1.5k
- Forks
- 760
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 12
Description
## Description
**Background:** The Go compiler’s SSA backend can emit an interactive HTML dump of the SSA IR for a given function when you set the `GOSSAFUNC` environment variable:
```bash
GOSSAFUNC=MyFunc go build
```
This produces an ssa.html file showing all compilation phases, inlining decisions, and optimizations for MyFunc, which is invaluable when investigating performance regressions, validating correctness, or understanding the compiler’s IR transformations.
## Description
This produces an `ssa.html` file showing all compilation phases, inlining decisions, and optimizations for `MyFunc`, which is invaluable when investigating performance regressions, validating correctness, or understanding the compiler’s IR transformations.
## Problem
Currently, **rules\_go** offers no way to request SSA debug output from within a Bazel build:
* Passing `--action_env=GOSSAFUNC=…` has no effect, because Bazel’s sandbox strips most Go toolchain environment variables.
* There is no dedicated `ssafunc` attribute (or extension of `gc_goopts`) on `go_binary`, `go_library`, or `go_test`.
* Teams must build outside Bazel (via plain `go build`) to inspect SSA dumps, breaking hermeticity and reproducibility.
## Proposal
1. **Add a new `ssafunc` attribute** to `go_binary`, `go_library`, and `go_test`:
```starlark
go_binary(
name = "myapp",
srcs = ["main.go"],
ssafunc = ["main", "(*MyType).Compute"],
importpath = "github.com/example/myapp",
)
```
2. **Wire `ssafunc` into the compile action** by either:
* Setting `GOSSAFUNC=` in the sandboxed environment, or
* Passing `-ssafunc=` to `go tool compile` once available upstream.
3. **Emit the SSA HTML into the build output directory**:
```bash
bazel build //:myapp
open bazel-bin/myapp.ssa.html
```
4. **Document the feature** in the [rules\_go README](https://github.com/bazelbuild/rules_go#go-compile-options) alongside `gc_goopts` and `gc_linkopts`.
## Example
```starlark
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
go_binary(
name = "server",
srcs = ["server.go"],
ssafunc = ["(*Server).handleRequest", "helperFunc"],
importpath = "github.com/example/server",
)
```
Building this target will produce `bazel-bin/server.ssa.html`, allowing developers to inspect SSA IR directly from a Bazel build.
Contributor guide
Research direction
Start with the go_binary, go_library, and go_test rule entry points and trace how their compile action handles gc_goopts and the sandboxed environment. Check the available Go compiler SSA flags and the rules_go README section on Go compile options. Done means a hermetic Bazel build accepts ssafunc, produces the requested SSA HTML in the stated output location, and documents the feature.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100