initial draft
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package backend
|
||||
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
import "core:os/os2"
|
||||
|
||||
compile :: proc(llvm_path, output_path: string) -> bool {
|
||||
pid := os2.get_pid()
|
||||
temporary_output := fmt.tprintf("%s.brolang-tmp-%d", output_path, pid)
|
||||
defer _ = os.remove(temporary_output)
|
||||
|
||||
command := []string{
|
||||
"/usr/bin/env",
|
||||
"ZIG_LOCAL_CACHE_DIR=/tmp/brolang-zig-cache",
|
||||
"ZIG_GLOBAL_CACHE_DIR=/tmp/brolang-zig-global-cache",
|
||||
"zig",
|
||||
"cc",
|
||||
"-Wno-override-module",
|
||||
llvm_path,
|
||||
"-o",
|
||||
temporary_output,
|
||||
}
|
||||
state, stdout, stderr, err := os2.process_exec(
|
||||
os2.Process_Desc{command=command},
|
||||
context.allocator,
|
||||
)
|
||||
defer delete(stdout)
|
||||
defer delete(stderr)
|
||||
if len(stdout) > 0 {
|
||||
fmt.print(string(stdout))
|
||||
}
|
||||
if len(stderr) > 0 {
|
||||
fmt.eprint(string(stderr))
|
||||
}
|
||||
if err != nil || state.exit_code != 0 {
|
||||
if err != nil {
|
||||
fmt.eprintln("failed to execute zig cc:", err)
|
||||
}
|
||||
return false
|
||||
}
|
||||
if rename_err := os2.rename(temporary_output, output_path); rename_err != nil {
|
||||
fmt.eprintln("failed to atomically replace output:", rename_err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user