| author | |
| committer | |
| log | 0975e37b162478a0d35c1f4bab9a2d0fb51aa203 |
| tree | 5be68a8cb4e25329926297ccd7ca3df11722e7da |
| parent | 0227becb564088db4b5598d7253038c92f11b6c2 |
see #4634 files changed, 33 insertions(+), 23 deletions(-)
src/codegen.cpp+5-9| ... | @@ -55,11 +55,14 @@ static PackageTableEntry *new_package(const char *root_src_dir, const char *root | ... | @@ -55,11 +55,14 @@ static PackageTableEntry *new_package(const char *root_src_dir, const char *root |
| 55 | return entry; | 55 | return entry; |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode) { | 58 | CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode, |
| 59 | Buf *zig_std_dir) | ||
| 60 | { | ||
| 59 | CodeGen *g = allocate<CodeGen>(1); | 61 | CodeGen *g = allocate<CodeGen>(1); |
| 60 | 62 | ||
| 61 | codegen_add_time_event(g, "Initialize"); | 63 | codegen_add_time_event(g, "Initialize"); |
| 62 | 64 | ||
| 65 | g->zig_std_dir = zig_std_dir; | ||
| 63 | g->build_mode = build_mode; | 66 | g->build_mode = build_mode; |
| 64 | g->out_type = out_type; | 67 | g->out_type = out_type; |
| 65 | g->import_table.init(32); | 68 | g->import_table.init(32); |
| ... | @@ -87,12 +90,11 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out | ... | @@ -87,12 +90,11 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out |
| 87 | os_path_split(root_src_path, src_dir, src_basename); | 90 | os_path_split(root_src_path, src_dir, src_basename); |
| 88 | 91 | ||
| 89 | g->root_package = new_package(buf_ptr(src_dir), buf_ptr(src_basename)); | 92 | g->root_package = new_package(buf_ptr(src_dir), buf_ptr(src_basename)); |
| 90 | g->std_package = new_package(ZIG_STD_DIR, "index.zig"); | 93 | g->std_package = new_package(buf_ptr(g->zig_std_dir), "index.zig"); |
| 91 | g->root_package->package_table.put(buf_create_from_str("std"), g->std_package); | 94 | g->root_package->package_table.put(buf_create_from_str("std"), g->std_package); |
| 92 | } else { | 95 | } else { |
| 93 | g->root_package = new_package(".", ""); | 96 | g->root_package = new_package(".", ""); |
| 94 | } | 97 | } |
| 95 | g->zig_std_dir = buf_create_from_str(ZIG_STD_DIR); | ||
| 96 | 98 | ||
| 97 | g->zig_std_special_dir = buf_alloc(); | 99 | g->zig_std_special_dir = buf_alloc(); |
| 98 | os_path_join(g->zig_std_dir, buf_sprintf("special"), g->zig_std_special_dir); | 100 | os_path_join(g->zig_std_dir, buf_sprintf("special"), g->zig_std_special_dir); |
| ... | @@ -215,12 +217,6 @@ void codegen_set_libc_include_dir(CodeGen *g, Buf *libc_include_dir) { | ... | @@ -215,12 +217,6 @@ void codegen_set_libc_include_dir(CodeGen *g, Buf *libc_include_dir) { |
| 215 | g->libc_include_dir = libc_include_dir; | 217 | g->libc_include_dir = libc_include_dir; |
| 216 | } | 218 | } |
| 217 | 219 | ||
| 218 | void codegen_set_zig_std_dir(CodeGen *g, Buf *zig_std_dir) { | ||
| 219 | g->zig_std_dir = zig_std_dir; | ||
| 220 | |||
| 221 | g->std_package->root_src_dir = *zig_std_dir; | ||
| 222 | } | ||
| 223 | |||
| 224 | void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker) { | 220 | void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker) { |
| 225 | g->dynamic_linker = dynamic_linker; | 221 | g->dynamic_linker = dynamic_linker; |
| 226 | } | 222 | } |
src/codegen.hpp+2-2| ... | @@ -14,7 +14,8 @@ | ... | @@ -14,7 +14,8 @@ |
| 14 | 14 | ||
| 15 | #include <stdio.h> | 15 | #include <stdio.h> |
| 16 | 16 | ||
| 17 | CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode); | 17 | CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode, |
| 18 | Buf *zig_std_dir); | ||
| 18 | 19 | ||
| 19 | void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len); | 20 | void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len); |
| 20 | void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len); | 21 | void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len); |
| ... | @@ -29,7 +30,6 @@ void codegen_set_out_name(CodeGen *codegen, Buf *out_name); | ... | @@ -29,7 +30,6 @@ void codegen_set_out_name(CodeGen *codegen, Buf *out_name); |
| 29 | void codegen_set_libc_lib_dir(CodeGen *codegen, Buf *libc_lib_dir); | 30 | void codegen_set_libc_lib_dir(CodeGen *codegen, Buf *libc_lib_dir); |
| 30 | void codegen_set_libc_static_lib_dir(CodeGen *g, Buf *libc_static_lib_dir); | 31 | void codegen_set_libc_static_lib_dir(CodeGen *g, Buf *libc_static_lib_dir); |
| 31 | void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir); | 32 | void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir); |
| 32 | void codegen_set_zig_std_dir(CodeGen *codegen, Buf *zig_std_dir); | ||
| 33 | void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker); | 33 | void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker); |
| 34 | void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole); | 34 | void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole); |
| 35 | void codegen_set_windows_unicode(CodeGen *g, bool municode); | 35 | void codegen_set_windows_unicode(CodeGen *g, bool municode); |
src/link.cpp+2-1| ... | @@ -33,7 +33,8 @@ static const char *get_libc_static_file(CodeGen *g, const char *file) { | ... | @@ -33,7 +33,8 @@ static const char *get_libc_static_file(CodeGen *g, const char *file) { |
| 33 | 33 | ||
| 34 | static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) { | 34 | static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) { |
| 35 | ZigTarget *child_target = parent_gen->is_native_target ? nullptr : &parent_gen->zig_target; | 35 | ZigTarget *child_target = parent_gen->is_native_target ? nullptr : &parent_gen->zig_target; |
| 36 | CodeGen *child_gen = codegen_create(full_path, child_target, OutTypeObj, parent_gen->build_mode); | 36 | CodeGen *child_gen = codegen_create(full_path, child_target, OutTypeObj, parent_gen->build_mode, |
| 37 | parent_gen->zig_std_dir); | ||
| 37 | 38 | ||
| 38 | child_gen->want_h_file = false; | 39 | child_gen->want_h_file = false; |
| 39 | child_gen->verbose_link = parent_gen->verbose_link; | 40 | child_gen->verbose_link = parent_gen->verbose_link; |
src/main.cpp+24-11| ... | @@ -232,13 +232,6 @@ int main(int argc, char **argv) { | ... | @@ -232,13 +232,6 @@ int main(int argc, char **argv) { |
| 232 | 232 | ||
| 233 | init_all_targets(); | 233 | init_all_targets(); |
| 234 | 234 | ||
| 235 | Buf *zig_std_dir = buf_create_from_str(ZIG_STD_DIR); | ||
| 236 | Buf *special_dir = buf_alloc(); | ||
| 237 | os_path_join(zig_std_dir, buf_sprintf("special"), special_dir); | ||
| 238 | |||
| 239 | Buf *build_runner_path = buf_alloc(); | ||
| 240 | os_path_join(special_dir, buf_create_from_str("build_runner.zig"), build_runner_path); | ||
| 241 | |||
| 242 | ZigList<const char *> args = {0}; | 235 | ZigList<const char *> args = {0}; |
| 243 | args.append(zig_exe_path); | 236 | args.append(zig_exe_path); |
| 244 | args.append(NULL); // placeholder | 237 | args.append(NULL); // placeholder |
| ... | @@ -255,12 +248,29 @@ int main(int argc, char **argv) { | ... | @@ -255,12 +248,29 @@ int main(int argc, char **argv) { |
| 255 | } else if (i + 1 < argc && strcmp(argv[i], "--cache-dir") == 0) { | 248 | } else if (i + 1 < argc && strcmp(argv[i], "--cache-dir") == 0) { |
| 256 | cache_dir = argv[i + 1]; | 249 | cache_dir = argv[i + 1]; |
| 257 | i += 1; | 250 | i += 1; |
| 251 | } else if (i + 1 < argc && strcmp(argv[i], "--zig-std-dir") == 0) { | ||
| 252 | args.append(argv[i]); | ||
| 253 | i += 1; | ||
| 254 | zig_std_dir = argv[i]; | ||
| 255 | args.append(zig_std_dir); | ||
| 258 | } else { | 256 | } else { |
| 259 | args.append(argv[i]); | 257 | args.append(argv[i]); |
| 260 | } | 258 | } |
| 261 | } | 259 | } |
| 262 | 260 | ||
| 263 | CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug); | 261 | if (zig_std_dir == nullptr) { |
| 262 | zig_std_dir = ZIG_STD_DIR; | ||
| 263 | } | ||
| 264 | Buf *zig_std_dir_buf = buf_create_from_str(zig_std_dir); | ||
| 265 | |||
| 266 | Buf *special_dir = buf_alloc(); | ||
| 267 | os_path_join(zig_std_dir_buf, buf_sprintf("special"), special_dir); | ||
| 268 | |||
| 269 | Buf *build_runner_path = buf_alloc(); | ||
| 270 | os_path_join(special_dir, buf_create_from_str("build_runner.zig"), build_runner_path); | ||
| 271 | |||
| 272 | |||
| 273 | CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_std_dir_buf); | ||
| 264 | codegen_set_out_name(g, buf_create_from_str("build")); | 274 | codegen_set_out_name(g, buf_create_from_str("build")); |
| 265 | codegen_set_verbose(g, verbose); | 275 | codegen_set_verbose(g, verbose); |
| 266 | 276 | ||
| ... | @@ -609,7 +619,12 @@ int main(int argc, char **argv) { | ... | @@ -609,7 +619,12 @@ int main(int argc, char **argv) { |
| 609 | buf_create_from_str((cache_dir == nullptr) ? default_zig_cache_name : cache_dir), | 619 | buf_create_from_str((cache_dir == nullptr) ? default_zig_cache_name : cache_dir), |
| 610 | full_cache_dir); | 620 | full_cache_dir); |
| 611 | 621 | ||
| 612 | CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode); | 622 | if (zig_std_dir == nullptr) { |
| 623 | zig_std_dir = ZIG_STD_DIR; | ||
| 624 | } | ||
| 625 | |||
| 626 | CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, | ||
| 627 | buf_create_from_str(zig_std_dir)); | ||
| 613 | codegen_set_out_name(g, buf_out_name); | 628 | codegen_set_out_name(g, buf_out_name); |
| 614 | codegen_set_lib_version(g, ver_major, ver_minor, ver_patch); | 629 | codegen_set_lib_version(g, ver_major, ver_minor, ver_patch); |
| 615 | codegen_set_is_test(g, cmd == CmdTest); | 630 | codegen_set_is_test(g, cmd == CmdTest); |
| ... | @@ -628,8 +643,6 @@ int main(int argc, char **argv) { | ... | @@ -628,8 +643,6 @@ int main(int argc, char **argv) { |
| 628 | codegen_set_libc_static_lib_dir(g, buf_create_from_str(libc_static_lib_dir)); | 643 | codegen_set_libc_static_lib_dir(g, buf_create_from_str(libc_static_lib_dir)); |
| 629 | if (libc_include_dir) | 644 | if (libc_include_dir) |
| 630 | codegen_set_libc_include_dir(g, buf_create_from_str(libc_include_dir)); | 645 | codegen_set_libc_include_dir(g, buf_create_from_str(libc_include_dir)); |
| 631 | if (zig_std_dir) | ||
| 632 | codegen_set_zig_std_dir(g, buf_create_from_str(zig_std_dir)); | ||
| 633 | if (dynamic_linker) | 646 | if (dynamic_linker) |
| 634 | codegen_set_dynamic_linker(g, buf_create_from_str(dynamic_linker)); | 647 | codegen_set_dynamic_linker(g, buf_create_from_str(dynamic_linker)); |
| 635 | codegen_set_verbose(g, verbose); | 648 | codegen_set_verbose(g, verbose); |