Skip to content

Commit

Permalink
builder: whitelist temporary directory env var for Clang invocation
Browse files Browse the repository at this point in the history
It looks like this breaks on Windows:
#4557
I haven't confirmed this is indeed the problem, but it would make sense.
And passing through the temporary directory seems like a good idea
regardless, there's not much that could break due to that.
  • Loading branch information
aykevl authored and deadprogram committed Nov 15, 2024
1 parent 6d4dfcf commit d51ef25
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions builder/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,26 @@ func runCCompiler(flags ...string) error {
cmd.Stderr = os.Stderr

// Make sure the command doesn't use any environmental variables.
// Most importantly, it should not use C_INCLUDE_PATH and the like. But
// removing all environmental variables also works.
// Most importantly, it should not use C_INCLUDE_PATH and the like.
cmd.Env = []string{}

// Let some environment variables through. One important one is the
// temporary directory, especially on Windows it looks like Clang breaks if
// the temporary directory has not been set.
// See: https://github.com/tinygo-org/tinygo/issues/4557
// Also see: https://github.com/llvm/llvm-project/blob/release/18.x/llvm/lib/Support/Unix/Path.inc#L1435
for _, env := range os.Environ() {
// We could parse the key and look it up in a map, but since there are
// only a few keys iterating through them is easier and maybe even
// faster.
for _, prefix := range []string{"TMPDIR=", "TMP=", "TEMP=", "TEMPDIR="} {
if strings.HasPrefix(env, prefix) {
cmd.Env = append(cmd.Env, env)
break
}
}
}

return cmd.Run()
}

Expand Down

0 comments on commit d51ef25

Please sign in to comment.