diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-05-15 21:47:15 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-05-15 21:50:56 -0400 |
| commit | 6b36b756eb4b4c26b98d405310680ebe5679d111 (patch) | |
| tree | 372ff21670a553664b443e08aae5601187d51bf4 /src/os.cpp | |
| parent | b64e6cb8130ca0ef7deca2191a8312edc7f2ce41 (diff) | |
| download | zig-6b36b756eb4b4c26b98d405310680ebe5679d111.tar.gz zig-6b36b756eb4b4c26b98d405310680ebe5679d111.zip | |
fix static builds of zig from requiring c compiler
to be installed when linking libc.
When zig links against libc, it requires a dynamic linker path.
Usually this can be determined based on the architecture and operating
system components of the target. However on some systems this is not
correct; because of this zig checks its own dynamic linker.
When zig is statically linked, this information is not available, and so
it resorts to using cc -print-filename=foo to find the dynamic linker
path.
Before this commit, Zig incorrectly exited with an error if there was
no c compiler installed. Now, Zig falls back to the dynamic linker
determined based on the arch and os when no C compiler can be found.
Diffstat (limited to 'src/os.cpp')
| -rw-r--r-- | src/os.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/os.cpp b/src/os.cpp index 83c67d5818..8ab5007d80 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -791,6 +791,7 @@ static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args, int stdin_pipe[2]; int stdout_pipe[2]; int stderr_pipe[2]; + int err_pipe[2]; int err; if ((err = pipe(stdin_pipe))) @@ -799,6 +800,8 @@ static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args, zig_panic("pipe failed"); if ((err = pipe(stderr_pipe))) zig_panic("pipe failed"); + if ((err = pipe(err_pipe))) + zig_panic("pipe failed"); pid_t pid = fork(); if (pid == -1) @@ -821,11 +824,12 @@ static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args, argv[i + 1] = args.at(i); } execvp(exe, const_cast<char * const *>(argv)); + Error report_err = ErrorUnexpected; if (errno == ENOENT) { - return ErrorFileNotFound; - } else { - zig_panic("execvp failed: %s", strerror(errno)); + report_err = ErrorFileNotFound; } + write(err_pipe[1], &report_err, sizeof(Error)); + exit(1); } else { // parent close(stdin_pipe[0]); @@ -847,7 +851,13 @@ static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args, if (err1) return err1; if (err2) return err2; - return ErrorNone; + + Error child_err = ErrorNone; + write(err_pipe[1], &child_err, sizeof(Error)); + close(err_pipe[1]); + read(err_pipe[0], &child_err, sizeof(Error)); + close(err_pipe[0]); + return child_err; } } #endif |
