authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-15 21:47:15-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-15 21:50:56-04:00
log6b36b756eb4b4c26b98d405310680ebe5679d111
tree372ff21670a553664b443e08aae5601187d51bf4
parentb64e6cb8130ca0ef7deca2191a8312edc7f2ce41
signaturelock-open Commit is signed but in an unrecognized format.

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.

6 files changed, 20 insertions(+), 5 deletions(-)

src/codegen.cpp+1-1
......@@ -8121,7 +8121,7 @@ static void detect_dynamic_linker(CodeGen *g) {
81218121 for (size_t i = 0; possible_ld_names[i] != NULL; i += 1) {
81228122 const char *lib_name = possible_ld_names[i];
81238123 if ((err = zig_libc_cc_print_file_name(lib_name, result, false, true))) {
8124 if (err != ErrorCCompilerCannotFindFile) {
8124 if (err != ErrorCCompilerCannotFindFile && err != ErrorNoCCompilerInstalled) {
81258125 fprintf(stderr, "Unable to detect native dynamic linker: %s\n", err_str(err));
81268126 exit(1);
81278127 }
src/error.cpp+1
......@@ -54,6 +54,7 @@ const char *err_str(Error err) {
5454 case ErrorOperationAborted: return "operation aborted";
5555 case ErrorBrokenPipe: return "broken pipe";
5656 case ErrorNoSpaceLeft: return "no space left";
57 case ErrorNoCCompilerInstalled: return "no C compiler installed";
5758 }
5859 return "(invalid error)";
5960}
src/libc_installation.cpp+2
......@@ -283,6 +283,8 @@ Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want_dirnam
283283 Buf *out_stdout = buf_alloc();
284284 Error err;
285285 if ((err = os_exec_process(cc_exe, args, &term, out_stderr, out_stdout))) {
286 if (err == ErrorFileNotFound)
287 return ErrorNoCCompilerInstalled;
286288 if (verbose) {
287289 fprintf(stderr, "unable to determine libc library path: executing '%s': %s\n", cc_exe, err_str(err));
288290 }
src/link.cpp+1
......@@ -34,6 +34,7 @@ static CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, Ou
3434 child_gen->verbose_cimport = parent_gen->verbose_cimport;
3535 child_gen->verbose_cc = parent_gen->verbose_cc;
3636 child_gen->llvm_argv = parent_gen->llvm_argv;
37 child_gen->dynamic_linker_path = parent_gen->dynamic_linker_path;
3738
3839 codegen_set_strip(child_gen, parent_gen->strip_debug_symbols);
3940 child_gen->want_pic = parent_gen->have_pic ? WantPICEnabled : WantPICDisabled;
src/os.cpp+14-4
......@@ -791,6 +791,7 @@ static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args,
791791 int stdin_pipe[2];
792792 int stdout_pipe[2];
793793 int stderr_pipe[2];
794 int err_pipe[2];
794795
795796 int err;
796797 if ((err = pipe(stdin_pipe)))
......@@ -799,6 +800,8 @@ static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args,
799800 zig_panic("pipe failed");
800801 if ((err = pipe(stderr_pipe)))
801802 zig_panic("pipe failed");
803 if ((err = pipe(err_pipe)))
804 zig_panic("pipe failed");
802805
803806 pid_t pid = fork();
804807 if (pid == -1)
......@@ -821,11 +824,12 @@ static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args,
821824 argv[i + 1] = args.at(i);
822825 }
823826 execvp(exe, const_cast<char * const *>(argv));
827 Error report_err = ErrorUnexpected;
824828 if (errno == ENOENT) {
825 return ErrorFileNotFound;
826 } else {
827 zig_panic("execvp failed: %s", strerror(errno));
829 report_err = ErrorFileNotFound;
828830 }
831 write(err_pipe[1], &report_err, sizeof(Error));
832 exit(1);
829833 } else {
830834 // parent
831835 close(stdin_pipe[0]);
......@@ -847,7 +851,13 @@ static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args,
847851
848852 if (err1) return err1;
849853 if (err2) return err2;
850 return ErrorNone;
854
855 Error child_err = ErrorNone;
856 write(err_pipe[1], &child_err, sizeof(Error));
857 close(err_pipe[1]);
858 read(err_pipe[0], &child_err, sizeof(Error));
859 close(err_pipe[0]);
860 return child_err;
851861 }
852862}
853863#endif
src/userland.h+1
......@@ -56,6 +56,7 @@ enum Error {
5656 ErrorCacheUnavailable,
5757 ErrorPathTooLong,
5858 ErrorCCompilerCannotFindFile,
59 ErrorNoCCompilerInstalled,
5960 ErrorReadingDepFile,
6061 ErrorInvalidDepFile,
6162 ErrorMissingArchitecture,