@@ -486,8 +486,10 @@ def _go_tool_binary_impl(ctx):
486486
487487 out = ctx .actions .declare_file (name )
488488
489- # Using pre-declared directory for temporary output to avoid needing to use shell to create it.
490- gotmp = ctx .actions .declare_directory (name + "_gotmp" )
489+ # Using pre-declared directory for temporary output to avoid dependencies
490+ # on shell or non-hermetic coreutils.
491+ gotmp = ctx .actions .declare_directory ("gotmp" )
492+
491493 if sdk .goos == "windows" :
492494 cmd = """@echo off
493495set GOMAXPROCS=1
@@ -525,22 +527,14 @@ exit /b %GO_EXIT_CODE%
525527 mnemonic = "GoToolchainBinaryBuild" ,
526528 )
527529 else :
528- # A dummy action to generate `gotmp`; this way the compilation below can avoid listing it in `outputs`.
529- # The net effect is to avoid copying out the GOCACHE when actions run sandboxed.
530- # Incidentally, this makes the reproducibility test pass.
531- ctx .actions .write (
532- output = gotmp ,
533- content = "" ,
534- )
535-
536- # In case actions are running unsandboxed, GOCACHE in `gotmp` may have been polluted.
537- # -a flag forces a rebuild so we are not affected by it.
530+ # -a flag instructs the compiler to not read from GOCACHE and force a rebuild.
531+ # This provides extra safety in cases of unsandboxed execution.
538532 args = ctx .actions .args ()
539533 args .add ("build" )
540534 args .add ("-a" )
541535 args .add ("-o" , out )
542536 args .add ("-trimpath" )
543- args .add ("-ldflags" , ctx .attr .ldflags , format = '-buildid="" %s' )
537+ args .add ("-ldflags" , ctx .attr .ldflags , format = '-w -s - buildid="" %s' )
544538 args .add_all (ctx .files .srcs )
545539
546540 ctx .actions .run (
@@ -552,17 +546,14 @@ exit /b %GO_EXIT_CODE%
552546 "GO111MODULE" : "off" ,
553547 "GOTELEMETRY" : "off" ,
554548 "GOENV" : "off" ,
555- # GOCACHE and GOPATH will default themselves to locations under $HOME.
556- # Otherwise we would need to set them explicitly, in which case they must be absolute paths.
557- # That would require a wrapper script/shell dependency.
558549 "HOME" : gotmp .path ,
559550 },
560551 inputs = depset (
561552 ctx .files .srcs ,
562553 transitive = [sdk .headers , sdk .srcs , sdk .libs , sdk .tools ],
563554 ),
564- outputs = [out ],
565555 toolchain = None ,
556+ outputs = [out , gotmp ],
566557 mnemonic = "GoToolchainBinaryBuild" ,
567558 )
568559
0 commit comments