Skip to content

Commit c6acaa9

Browse files
aykevldeadprogram
authored andcommitted
builder: remove environment variables when invoking Clang
This is a problem on Guix, which sets C_INCLUDE_PATH that is not affected by `-nostdlibinc`. And therefore it affects the build in unintended ways. Removing all environmental variables fixes this issue, and perhaps also other issues caused by Clang being affected by environment variables.
1 parent 4ef5109 commit c6acaa9

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

builder/commands.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package builder
33
import (
44
"errors"
55
"fmt"
6-
"os"
76
"os/exec"
87
"runtime"
98
"strings"
@@ -76,14 +75,3 @@ func LookupCommand(name string) (string, error) {
7675
}
7776
return "", errors.New("none of these commands were found in your $PATH: " + strings.Join(commands[name], " "))
7877
}
79-
80-
func execCommand(name string, args ...string) error {
81-
name, err := LookupCommand(name)
82-
if err != nil {
83-
return err
84-
}
85-
cmd := exec.Command(name, args...)
86-
cmd.Stdout = os.Stdout
87-
cmd.Stderr = os.Stderr
88-
return cmd.Run()
89-
}

builder/tools.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,29 @@ import (
1414

1515
// runCCompiler invokes a C compiler with the given arguments.
1616
func runCCompiler(flags ...string) error {
17+
// Find the right command to run Clang.
18+
var cmd *exec.Cmd
1719
if hasBuiltinTools {
1820
// Compile this with the internal Clang compiler.
19-
cmd := exec.Command(os.Args[0], append([]string{"clang"}, flags...)...)
20-
cmd.Stdout = os.Stdout
21-
cmd.Stderr = os.Stderr
22-
return cmd.Run()
21+
cmd = exec.Command(os.Args[0], append([]string{"clang"}, flags...)...)
22+
} else {
23+
// Compile this with an external invocation of the Clang compiler.
24+
name, err := LookupCommand("clang")
25+
if err != nil {
26+
return err
27+
}
28+
cmd = exec.Command(name, flags...)
2329
}
2430

25-
// Compile this with an external invocation of the Clang compiler.
26-
return execCommand("clang", flags...)
31+
cmd.Stdout = os.Stdout
32+
cmd.Stderr = os.Stderr
33+
34+
// 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.
37+
cmd.Env = []string{}
38+
39+
return cmd.Run()
2740
}
2841

2942
// link invokes a linker with the given name and flags.

0 commit comments

Comments
 (0)