Browse Source

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.
pull/1239/merge
Ayke van Laethem 4 weeks ago
committed by Ron Evans
parent
commit
c6acaa981d
  1. 12
      builder/commands.go
  2. 25
      builder/tools.go

12
builder/commands.go

@ -3,7 +3,6 @@ package builder
import (
"errors"
"fmt"
"os"
"os/exec"
"runtime"
"strings"
@ -76,14 +75,3 @@ func LookupCommand(name string) (string, error) {
}
return "", errors.New("none of these commands were found in your $PATH: " + strings.Join(commands[name], " "))
}
func execCommand(name string, args ...string) error {
name, err := LookupCommand(name)
if err != nil {
return err
}
cmd := exec.Command(name, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}

25
builder/tools.go

@ -14,16 +14,29 @@ import (
// runCCompiler invokes a C compiler with the given arguments.
func runCCompiler(flags ...string) error {
// Find the right command to run Clang.
var cmd *exec.Cmd
if hasBuiltinTools {
// Compile this with the internal Clang compiler.
cmd := exec.Command(os.Args[0], append([]string{"clang"}, flags...)...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
cmd = exec.Command(os.Args[0], append([]string{"clang"}, flags...)...)
} else {
// Compile this with an external invocation of the Clang compiler.
name, err := LookupCommand("clang")
if err != nil {
return err
}
cmd = exec.Command(name, flags...)
}
// Compile this with an external invocation of the Clang compiler.
return execCommand("clang", flags...)
cmd.Stdout = os.Stdout
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.
cmd.Env = []string{}
return cmd.Run()
}
// link invokes a linker with the given name and flags.

Loading…
Cancel
Save