Skip to content

Commit d51ef25

Browse files
aykevldeadprogram
authored andcommitted
builder: whitelist temporary directory env var for Clang invocation
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.
1 parent 6d4dfcf commit d51ef25

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

builder/tools.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,26 @@ func runCCompiler(flags ...string) error {
3232
cmd.Stderr = os.Stderr
3333

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

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

0 commit comments

Comments
 (0)