diff --git a/go/tools/builders/compilepkg.go b/go/tools/builders/compilepkg.go index e6f5446466..04722a85a4 100644 --- a/go/tools/builders/compilepkg.go +++ b/go/tools/builders/compilepkg.go @@ -178,7 +178,12 @@ func compileArchive( defer cleanup() if len(srcs.goSrcs) == 0 { - emptyPath := filepath.Join(workDir, "_empty.go") + // We need to run the compiler to create a valid archive, even if there's + // nothing in it. GoPack will complain if we try to add assembly or cgo + // objects. + // _empty.go needs to be in a deterministic location (not tmpdir) in order + // to ensure deterministic output + emptyPath := filepath.Join(filepath.Dir(outPath), "_empty.go") if err := ioutil.WriteFile(emptyPath, []byte("package empty\n"), 0666); err != nil { return err } diff --git a/tests/integration/reproducibility/reproducibility_test.go b/tests/integration/reproducibility/reproducibility_test.go index 38493b1375..2e9bc59144 100644 --- a/tests/integration/reproducibility/reproducibility_test.go +++ b/tests/integration/reproducibility/reproducibility_test.go @@ -35,7 +35,13 @@ func TestMain(m *testing.M) { bazel_testing.TestMain(m, bazel_testing.Args{ Main: ` -- BUILD.bazel -- -load("@io_bazel_rules_go//go:def.bzl", "go_binary") +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") + +go_library( + name = "empty_lib", + srcs = [], + importpath = "empty_lib", +) go_binary( name = "hello",