bazel-contrib / bazel-contrib/rules_go
Don't use "-linkobj" when compile for a binary or test
- Dominant language
- Go
- Stars
- 1.5k
- Forks
- 760
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 12
Description
Currently in `compilepkg.go`, when we invoke `go tool compile`, we are unconditionally adding `-linkobj` to create 2 separate artifacts: `.x` for downstream library compilation and `.a` for downstream binary linking.
This is efficient for `go_library`, but for the compilation which happens under `go_test` and `go_binary`, the output artifact(s) will not be used for any other downstream actions except GoLink for that test/binary to create the final Go executable.
So for the GoCompilePkg action under `go_test` and `go_binary`, it will be better if we remove `-linkobj` and only generate the `.a` file. In other words, we should only be using `-linkobj` when the downstream consumer of the artifact is unclear, such as for the GoCompilePkg action under `go_library` or `go_proto_library`.
Contributor guide
Research direction
Start in compilepkg.go and trace how GoCompilePkg is configured for go_test, go_binary, go_library, and go_proto_library, including the go tool compile invocation. Verify which artifacts GoLink consumes; done means test and binary compilations produce only the .a artifact while library and proto-library compilations retain -linkobj behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- build-system
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100