clang.Cmd.CheckLinkArgs compiles to temp file and remove
This commit is contained in:
@@ -105,16 +105,33 @@ func (p *Cmd) Exec(args ...string) error {
|
|||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Cmd) CheckLinkArgs(cmdArgs []string) error {
|
func (p *Cmd) CheckLinkArgs(cmdArgs []string, wasm bool) error {
|
||||||
nul := "/dev/null"
|
// Create a temporary file with appropriate extension
|
||||||
if runtime.GOOS == "windows" {
|
extension := ""
|
||||||
nul = "NUL"
|
if wasm {
|
||||||
|
extension = ".wasm"
|
||||||
|
} else if runtime.GOOS == "windows" {
|
||||||
|
extension = ".exe"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmpFile, err := os.CreateTemp("", "llgo_check*"+extension)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create temporary file: %w", err)
|
||||||
|
}
|
||||||
|
tmpFile.Close()
|
||||||
|
tmpPath := tmpFile.Name()
|
||||||
|
|
||||||
|
// Make sure to delete the temporary file when done
|
||||||
|
defer os.Remove(tmpPath)
|
||||||
|
|
||||||
|
// Set up compilation arguments
|
||||||
args := append([]string{}, cmdArgs...)
|
args := append([]string{}, cmdArgs...)
|
||||||
args = append(args, []string{"-x", "c", "-o", nul, "-"}...)
|
args = append(args, []string{"-x", "c", "-o", tmpPath, "-"}...)
|
||||||
src := "int main() {return 0;}"
|
src := "int main() {return 0;}"
|
||||||
srcIn := strings.NewReader(src)
|
srcIn := strings.NewReader(src)
|
||||||
p.Stdin = srcIn
|
p.Stdin = srcIn
|
||||||
|
|
||||||
|
// Execute the command
|
||||||
return p.execWithFlags([]string{"LDFLAGS", "CCFLAGS"}, args...)
|
return p.execWithFlags([]string{"LDFLAGS", "CCFLAGS"}, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user