Skip to content

cmd/go: propagate GOTMPDIR to subprocess temp directory variables#19

Open
hbrooks wants to merge 1 commit into
masterfrom
demo/pr-78679
Open

cmd/go: propagate GOTMPDIR to subprocess temp directory variables#19
hbrooks wants to merge 1 commit into
masterfrom
demo/pr-78679

Conversation

@hbrooks
Copy link
Copy Markdown

@hbrooks hbrooks commented May 28, 2026

Mirror of golang/go#78679 by @iceymoss

When GOTMPDIR is set, the go command uses it to create its own work
directory, but subprocesses such as the linker, C compiler, and cgo
still use the system default temporary directory. This is because
GOTMPDIR is a Go-specific variable that external tools do not recognize.

Fix this by translating GOTMPDIR into the platform-specific temporary
directory environment variable (TMPDIR on Unix, TMP/TEMP on Windows)
so that all subprocesses respect the user's configured temporary
directory.

The fix has two layers:
- Add TMPDIR to cfgChangedEnv so it is explicitly passed to
  subprocesses that use it (compiler, assembler, linker, cgo)
  and is visible in 'go build -x' output.
- Call os.Setenv in BuildInit to set the process-level TMPDIR,
  covering subprocesses that do not receive cfgChangedEnv
  (C compiler, vet, pkg-config, etc.) via cmd.Environ().

Fixes golang#59636
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants