Skip to content

Instantly share code, notes, and snippets.

@justbuchanan
Last active November 9, 2018 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justbuchanan/29d611e4a3cf46b3624a4d6a3ea2832c to your computer and use it in GitHub Desktop.
Save justbuchanan/29d611e4a3cf46b3624a4d6a3ea2832c to your computer and use it in GitHub Desktop.
Example of bug with rules_go + cgo + bazel aspects. https://github.com/bazelbuild/rules_go/issues/1821

This works: bazel build :main

This doesn't: bazel build :main --experimental_action_listener=//:my_action_listener

Loading: 0 packages loaded
Analyzing: target //:main (0 packages loaded, 0 targets configured)
INFO: Analysed target //:main (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
[0 / 18] no action
ERROR: /usr/local/google/home/justinbuchanan/src/justin/gobug/BUILD:3:1: CGoCodeGen //:main%nacl_amd64p32%cgo_codegen failed (Exit 1) cgo failed: error executing command bazel-out/host/bin/external/io_bazel_rules_go/go/tools/builders/linux_amd64_stripped/cgo -sdk external/go_sdk -installsuffix nacl_amd64p32 -src ... (remaining 19 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
unknown ptrSize for $GOARCH "amd64p32"
CgoCodegen: error running subcommand: exit status 2
Target //:main failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.231s, Critical Path: 0.11s, Remote (0.00% of the time): [queue: 0.00%, setup: 0.00%, process: 0.00%]
INFO: 1 process: 1 linux-sandbox.
FAILED: Build did NOT complete successfully

For some reason, adding an action listener to the mix triggers cgo builds for all supported architectures. The specific error message differs based on which one of these non-host-architecture targets bazel tries to build first.

load("@io_bazel_rules_go//go:def.bzl", "go_binary")
go_binary(
name = "main",
srcs = ["main.go"],
cgo = True,
)
action_listener(
name = "my_action_listener",
extra_actions = [":my_extra_action"],
mnemonics = ["CppCompile"],
visibility = ["//visibility:public"],
)
extra_action(
name = "my_extra_action",
cmd = "echo hello > $(output $(ACTION_ID).txt)",
out_templates = ["$(ACTION_ID).txt"],
)
package main
import "fmt"
func main() {
fmt.Println("hello")
}
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "io_bazel_rules_go",
sha256 = "70d0204f1e834d14fa9eef1e9b97160917a48957cd1e3a39b5ef9acdbdde6972",
url = "https://github.com/bazelbuild/rules_go/releases/download/0.15.2/rules_go-0.15.2.tar.gz",
)
load("@io_bazel_rules_go//go:def.bzl", "go_register_toolchains", "go_rules_dependencies")
go_rules_dependencies()
go_register_toolchains()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment