| author | |
| committer | |
| log | 7af59c76e40d185ed1a8962c2d5fd0f88680d5a7 |
| tree | fbd8eeaf799fbea424a546b0ae199ce91a7e70ad |
| parent | 5824b15249c8fb42aba5ca347d7dc702a4a00a9f |
8 files changed, 54 insertions(+), 48 deletions(-)
README.md+6-6| ... | ... | @@ -70,13 +70,13 @@ compromises backward compatibility. |
| 70 | 70 | |
| 71 | 71 | ### Debug / Development Build |
| 72 | 72 | |
| 73 | If you have gcc or clang installed, you can find out what `ZIG_LIBC_DIR` should | |
| 74 | be set to (example below). | |
| 73 | If you have gcc or clang installed, you can find out what `ZIG_LIBC_LIB_DIR` should | |
| 74 | be set to (example below). `ZIG_LIBC_INCLUDE_DIR` likely can be set to `/usr/include`. | |
| 75 | 75 | |
| 76 | 76 | ``` |
| 77 | 77 | mkdir build |
| 78 | 78 | cd build |
| 79 | cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_DIR=$(dirname $(dirname $(cc -print-file-name=crt1.o))) | |
| 79 | cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_LIB_DIR=$(dirname $(cc -print-file-name=crt1.o)) -DZIG_LIBC_INCLUDE_DIR=/usr/include | |
| 80 | 80 | make |
| 81 | 81 | make install |
| 82 | 82 | ./run_tests |
| ... | ... | @@ -84,13 +84,13 @@ make install |
| 84 | 84 | |
| 85 | 85 | ### Release / Install Build |
| 86 | 86 | |
| 87 | Once installed, `ZIG_LIBC_DIR` can be overridden by the `--libc-path` parameter | |
| 88 | to the zig binary. | |
| 87 | Once installed, `ZIG_LIBC_LIB_DIR` and `ZIG_LIBC_INCLUDE_DIR` can be overridden | |
| 88 | by the `--libc-lib-dir` and `--libc-include-dir` parameters to the zig binary. | |
| 89 | 89 | |
| 90 | 90 | ``` |
| 91 | 91 | mkdir build |
| 92 | 92 | cd build |
| 93 | cmake .. -DCMAKE_BUILD_TYPE=Release -DZIG_LIBC_DIR=path/to/libc/dir | |
| 93 | cmake .. -DCMAKE_BUILD_TYPE=Release -DZIG_LIBC_LIB_DIR=/some/path -DZIG_LIBC_INCLUDE_DIR=/some/path | |
| 94 | 94 | make |
| 95 | 95 | sudo make install |
| 96 | 96 | ``` |
src/all_types.hpp+2-3| ... | ... | @@ -1062,9 +1062,8 @@ struct CodeGen { |
| 1062 | 1062 | bool strip_debug_symbols; |
| 1063 | 1063 | bool have_exported_main; |
| 1064 | 1064 | bool link_libc; |
| 1065 | Buf *libc_path; | |
| 1066 | Buf *libc_lib_path; | |
| 1067 | Buf *libc_include_path; | |
| 1065 | Buf *libc_lib_dir; | |
| 1066 | Buf *libc_include_dir; | |
| 1068 | 1067 | CodeGenBuildType build_type; |
| 1069 | 1068 | LLVMTargetMachineRef target_machine; |
| 1070 | 1069 | LLVMZigDIFile *dummy_di_file; |
src/analyze.cpp+5-13| ... | ... | @@ -5486,20 +5486,12 @@ bool handle_is_ptr(TypeTableEntry *type_entry) { |
| 5486 | 5486 | } |
| 5487 | 5487 | |
| 5488 | 5488 | void find_libc_path(CodeGen *g) { |
| 5489 | if (!g->libc_path || buf_len(g->libc_path) == 0) { | |
| 5490 | g->libc_path = buf_create_from_str(ZIG_LIBC_DIR); | |
| 5491 | if (!g->libc_path || buf_len(g->libc_path) == 0) { | |
| 5492 | // later we can handle this better by reporting an error via the normal mechanism | |
| 5493 | zig_panic("Unable to determine libc path. You can use `--libc-path`"); | |
| 5494 | } | |
| 5495 | } | |
| 5496 | if (!g->libc_lib_path) { | |
| 5497 | g->libc_lib_path = buf_alloc(); | |
| 5498 | os_path_join(g->libc_path, buf_create_from_str("lib"), g->libc_lib_path); | |
| 5489 | // later we can handle this better by reporting an error via the normal mechanism | |
| 5490 | if (!g->libc_lib_dir || buf_len(g->libc_lib_dir) == 0) { | |
| 5491 | zig_panic("Unable to determine libc lib path. probably need to reconfigure"); | |
| 5499 | 5492 | } |
| 5500 | if (!g->libc_include_path) { | |
| 5501 | g->libc_include_path = buf_alloc(); | |
| 5502 | os_path_join(g->libc_path, buf_create_from_str("include"), g->libc_include_path); | |
| 5493 | if (!g->libc_include_dir || buf_len(g->libc_include_dir) == 0) { | |
| 5494 | zig_panic("Unable to determine libc include path. probably need to reconfigure"); | |
| 5503 | 5495 | } |
| 5504 | 5496 | } |
| 5505 | 5497 |
src/codegen.cpp+10-3| ... | ... | @@ -33,6 +33,9 @@ CodeGen *codegen_create(Buf *root_source_dir) { |
| 33 | 33 | g->next_error_index = 1; |
| 34 | 34 | g->error_value_count = 1; |
| 35 | 35 | |
| 36 | g->libc_lib_dir = buf_create_from_str(ZIG_LIBC_LIB_DIR); | |
| 37 | g->libc_include_dir = buf_create_from_str(ZIG_LIBC_INCLUDE_DIR); | |
| 38 | ||
| 36 | 39 | return g; |
| 37 | 40 | } |
| 38 | 41 | |
| ... | ... | @@ -69,8 +72,12 @@ void codegen_set_out_name(CodeGen *g, Buf *out_name) { |
| 69 | 72 | g->root_out_name = out_name; |
| 70 | 73 | } |
| 71 | 74 | |
| 72 | void codegen_set_libc_path(CodeGen *g, Buf *libc_path) { | |
| 73 | g->libc_path = libc_path; | |
| 75 | void codegen_set_libc_lib_dir(CodeGen *g, Buf *libc_lib_dir) { | |
| 76 | g->libc_lib_dir = libc_lib_dir; | |
| 77 | } | |
| 78 | ||
| 79 | void codegen_set_libc_include_dir(CodeGen *g, Buf *libc_include_dir) { | |
| 80 | g->libc_include_dir = libc_include_dir; | |
| 74 | 81 | } |
| 75 | 82 | |
| 76 | 83 | void codegen_add_lib_dir(CodeGen *g, const char *dir) { |
| ... | ... | @@ -3710,7 +3717,7 @@ static void generate_h_file(CodeGen *g) { |
| 3710 | 3717 | |
| 3711 | 3718 | static const char *get_libc_file(CodeGen *g, const char *file) { |
| 3712 | 3719 | Buf *out_buf = buf_alloc(); |
| 3713 | os_path_join(g->libc_lib_path, buf_create_from_str(file), out_buf); | |
| 3720 | os_path_join(g->libc_lib_dir, buf_create_from_str(file), out_buf); | |
| 3714 | 3721 | return buf_ptr(out_buf); |
| 3715 | 3722 | } |
| 3716 | 3723 |
src/codegen.hpp+2-1| ... | ... | @@ -23,7 +23,8 @@ void codegen_set_verbose(CodeGen *codegen, bool verbose); |
| 23 | 23 | void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color); |
| 24 | 24 | void codegen_set_out_type(CodeGen *codegen, OutType out_type); |
| 25 | 25 | void codegen_set_out_name(CodeGen *codegen, Buf *out_name); |
| 26 | void codegen_set_libc_path(CodeGen *codegen, Buf *libc_path); | |
| 26 | void codegen_set_libc_lib_dir(CodeGen *codegen, Buf *libc_lib_dir); | |
| 27 | void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir); | |
| 27 | 28 | void codegen_add_lib_dir(CodeGen *codegen, const char *dir); |
| 28 | 29 | |
| 29 | 30 | void codegen_add_root_code(CodeGen *g, Buf *source_dir, Buf *source_basename, Buf *source_code); |
src/config.h.in+2-1| ... | ... | @@ -8,7 +8,8 @@ |
| 8 | 8 | |
| 9 | 9 | #define ZIG_HEADERS_DIR "@CMAKE_INSTALL_PREFIX@/@C_HEADERS_DEST@" |
| 10 | 10 | #define ZIG_STD_DIR "@CMAKE_INSTALL_PREFIX@/@ZIG_STD_DEST@" |
| 11 | #define ZIG_LIBC_DIR "@ZIG_LIBC_DIR@" | |
| 11 | #define ZIG_LIBC_INCLUDE_DIR "@ZIG_LIBC_INCLUDE_DIR@" | |
| 12 | #define ZIG_LIBC_LIB_DIR "@ZIG_LIBC_LIB_DIR@" | |
| 12 | 13 | |
| 13 | 14 | #cmakedefine ZIG_LLVM_OLD_CXX_ABI |
| 14 | 15 |
src/main.cpp+26-20| ... | ... | @@ -16,22 +16,23 @@ |
| 16 | 16 | static int usage(const char *arg0) { |
| 17 | 17 | fprintf(stderr, "Usage: %s [command] [options]\n" |
| 18 | 18 | "Commands:\n" |
| 19 | " build create executable, object, or library from target\n" | |
| 20 | " version print version number and exit\n" | |
| 21 | " parseh convert a c header file to zig extern declarations\n" | |
| 19 | " build create executable, object, or library from target\n" | |
| 20 | " version print version number and exit\n" | |
| 21 | " parseh convert a c header file to zig extern declarations\n" | |
| 22 | 22 | "Options:\n" |
| 23 | " --release build with optimizations on and debug protection off\n" | |
| 24 | " --static output will be statically linked\n" | |
| 25 | " --strip exclude debug symbols\n" | |
| 26 | " --export [exe|lib|obj] override output type\n" | |
| 27 | " --name [name] override output name\n" | |
| 28 | " --output [file] override destination path\n" | |
| 29 | " --verbose turn on compiler debug output\n" | |
| 30 | " --color [auto|off|on] enable or disable colored error messages\n" | |
| 31 | " --libc-path [path] set the C compiler data path\n" | |
| 32 | " -isystem [dir] add additional search path for other .h files\n" | |
| 33 | " -dirafter [dir] same as -isystem but do it last\n" | |
| 34 | " --library-path [dir] add a directory to the library search path\n" | |
| 23 | " --release build with optimizations on and debug protection off\n" | |
| 24 | " --static output will be statically linked\n" | |
| 25 | " --strip exclude debug symbols\n" | |
| 26 | " --export [exe|lib|obj] override output type\n" | |
| 27 | " --name [name] override output name\n" | |
| 28 | " --output [file] override destination path\n" | |
| 29 | " --verbose turn on compiler debug output\n" | |
| 30 | " --color [auto|off|on] enable or disable colored error messages\n" | |
| 31 | " --libc-lib-dir [path] set the C compiler data path\n" | |
| 32 | " --libc-include-dir [path] set the C compiler data path\n" | |
| 33 | " -isystem [dir] add additional search path for other .h files\n" | |
| 34 | " -dirafter [dir] same as -isystem but do it last\n" | |
| 35 | " --library-path [dir] add a directory to the library search path\n" | |
| 35 | 36 | , arg0); |
| 36 | 37 | return EXIT_FAILURE; |
| 37 | 38 | } |
| ... | ... | @@ -55,7 +56,8 @@ int main(int argc, char **argv) { |
| 55 | 56 | const char *out_name = nullptr; |
| 56 | 57 | bool verbose = false; |
| 57 | 58 | ErrColor color = ErrColorAuto; |
| 58 | const char *libc_path = nullptr; | |
| 59 | const char *libc_lib_dir = nullptr; | |
| 60 | const char *libc_include_dir = nullptr; | |
| 59 | 61 | ZigList<const char *> clang_argv = {0}; |
| 60 | 62 | ZigList<const char *> lib_dirs = {0}; |
| 61 | 63 | int err; |
| ... | ... | @@ -102,8 +104,10 @@ int main(int argc, char **argv) { |
| 102 | 104 | } |
| 103 | 105 | } else if (strcmp(arg, "--name") == 0) { |
| 104 | 106 | out_name = argv[i]; |
| 105 | } else if (strcmp(arg, "--libc-path") == 0) { | |
| 106 | libc_path = argv[i]; | |
| 107 | } else if (strcmp(arg, "--libc-lib-dir") == 0) { | |
| 108 | libc_lib_dir = argv[i]; | |
| 109 | } else if (strcmp(arg, "--libc-include-dir") == 0) { | |
| 110 | libc_include_dir = argv[i]; | |
| 107 | 111 | } else if (strcmp(arg, "-isystem") == 0) { |
| 108 | 112 | clang_argv.append("-isystem"); |
| 109 | 113 | clang_argv.append(argv[i]); |
| ... | ... | @@ -182,8 +186,10 @@ int main(int argc, char **argv) { |
| 182 | 186 | codegen_set_out_type(g, out_type); |
| 183 | 187 | if (out_name) |
| 184 | 188 | codegen_set_out_name(g, buf_create_from_str(out_name)); |
| 185 | if (libc_path) | |
| 186 | codegen_set_libc_path(g, buf_create_from_str(libc_path)); | |
| 189 | if (libc_lib_dir) | |
| 190 | codegen_set_libc_lib_dir(g, buf_create_from_str(libc_lib_dir)); | |
| 191 | if (libc_include_dir) | |
| 192 | codegen_set_libc_include_dir(g, buf_create_from_str(libc_include_dir)); | |
| 187 | 193 | codegen_set_verbose(g, verbose); |
| 188 | 194 | codegen_set_errmsg_color(g, color); |
| 189 | 195 |
src/parseh.cpp+1-1| ... | ... | @@ -1413,7 +1413,7 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch |
| 1413 | 1413 | clang_argv.append(ZIG_HEADERS_DIR); |
| 1414 | 1414 | |
| 1415 | 1415 | clang_argv.append("-isystem"); |
| 1416 | clang_argv.append(buf_ptr(codegen->libc_include_path)); | |
| 1416 | clang_argv.append(buf_ptr(codegen->libc_include_dir)); | |
| 1417 | 1417 | |
| 1418 | 1418 | for (int i = 0; i < codegen->clang_argv_len; i += 1) { |
| 1419 | 1419 | clang_argv.append(codegen->clang_argv[i]); |