From f981365d1bd0e324881204d3e331b4e0d9c03a6a Mon Sep 17 00:00:00 2001 From: Joel Jeske Date: Wed, 30 Mar 2022 10:19:49 -0500 Subject: [PATCH] Use output dir for empty packages to be hermetic --- go/tools/builders/compilepkg.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 }