authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-27 18:38:28-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-27 18:38:28-04:00
logfe2d89007b2013bed4a12446fa74a124a9721dbb
tree2609c4e6a5c0bcf22839a901237846b395933336
parent0a0c11685fd8faf73392d88dbdee7c744cc83386
parent3ed6acd2d20de0a2a08ddf6549fb06a66687d96a
signaturelock-open Commit is signed but in an unrecognized format.

Merge branch 'root-import' of https://github.com/emekoi/zig into emekoi-root-import


1 files changed, 16 insertions(+), 7 deletions(-)

src/codegen.cpp+16-7
...@@ -180,6 +180,8 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget...@@ -180,6 +180,8 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget
180 g->root_package = new_package(".", "", "");180 g->root_package = new_package(".", "", "");
181 }181 }
182182
183 g->root_package->package_table.put(buf_create_from_str("@root"), g->root_package);
184
183 g->zig_std_special_dir = buf_alloc();185 g->zig_std_special_dir = buf_alloc();
184 os_path_join(g->zig_std_dir, buf_sprintf("special"), g->zig_std_special_dir);186 os_path_join(g->zig_std_dir, buf_sprintf("special"), g->zig_std_special_dir);
185187
...@@ -8520,10 +8522,8 @@ static ZigType *add_special_code(CodeGen *g, ZigPackage *package, const char *ba...@@ -8520,10 +8522,8 @@ static ZigType *add_special_code(CodeGen *g, ZigPackage *package, const char *ba
8520 return add_source_file(g, package, resolved_path, import_code, SourceKindPkgMain);8522 return add_source_file(g, package, resolved_path, import_code, SourceKindPkgMain);
8521}8523}
85228524
8523static ZigPackage *create_bootstrap_pkg(CodeGen *g, ZigPackage *pkg_with_main) {8525static ZigPackage *create_bootstrap_pkg(CodeGen *g) {
8524 ZigPackage *package = codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "bootstrap.zig", "std.special");8526 return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "bootstrap.zig", "std.special");
8525 package->package_table.put(buf_create_from_str("@root"), pkg_with_main);
8526 return package;
8527}8527}
85288528
8529static ZigPackage *create_test_runner_pkg(CodeGen *g) {8529static ZigPackage *create_test_runner_pkg(CodeGen *g) {
...@@ -8647,12 +8647,12 @@ static void gen_root_source(CodeGen *g) {...@@ -8647,12 +8647,12 @@ static void gen_root_source(CodeGen *g) {
8647 !g->have_c_main && !g->have_winmain && !g->have_winmain_crt_startup &&8647 !g->have_c_main && !g->have_winmain && !g->have_winmain_crt_startup &&
8648 ((g->have_pub_main && g->out_type == OutTypeObj) || g->out_type == OutTypeExe))8648 ((g->have_pub_main && g->out_type == OutTypeObj) || g->out_type == OutTypeExe))
8649 {8649 {
8650 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->root_package), "bootstrap.zig");8650 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g), "bootstrap.zig");
8651 }8651 }
8652 if (g->zig_target->os == OsWindows && !g->have_dllmain_crt_startup &&8652 if (g->zig_target->os == OsWindows && !g->have_dllmain_crt_startup &&
8653 g->out_type == OutTypeLib && g->is_dynamic)8653 g->out_type == OutTypeLib && g->is_dynamic)
8654 {8654 {
8655 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->root_package), "bootstrap_lib.zig");8655 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g), "bootstrap_lib.zig");
8656 }8656 }
86578657
8658 if (!g->error_during_imports) {8658 if (!g->error_during_imports) {
...@@ -8660,7 +8660,7 @@ static void gen_root_source(CodeGen *g) {...@@ -8660,7 +8660,7 @@ static void gen_root_source(CodeGen *g) {
8660 }8660 }
8661 if (g->is_test_build) {8661 if (g->is_test_build) {
8662 create_test_compile_var_and_add_test_runner(g);8662 create_test_compile_var_and_add_test_runner(g);
8663 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->test_runner_package), "bootstrap.zig");8663 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g), "bootstrap.zig");
86648664
8665 if (!g->error_during_imports) {8665 if (!g->error_during_imports) {
8666 semantic_analyze(g);8666 semantic_analyze(g);
...@@ -9389,6 +9389,8 @@ static void add_cache_pkg(CodeGen *g, CacheHash *ch, ZigPackage *pkg) {...@@ -9389,6 +9389,8 @@ static void add_cache_pkg(CodeGen *g, CacheHash *ch, ZigPackage *pkg) {
9389 // TODO: I think we need a more sophisticated detection of9389 // TODO: I think we need a more sophisticated detection of
9390 // packages we have already seen9390 // packages we have already seen
9391 if (entry->value != pkg) {9391 if (entry->value != pkg) {
9392 auto root = pkg->package_table.maybe_get(buf_create_from_str("@root"));
9393 if (root != nullptr && entry->value == root->value) continue;
9392 cache_buf(ch, entry->key);9394 cache_buf(ch, entry->key);
9393 add_cache_pkg(g, ch, entry->value);9395 add_cache_pkg(g, ch, entry->value);
9394 }9396 }
...@@ -9645,6 +9647,13 @@ ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const c...@@ -9645,6 +9647,13 @@ ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const c
9645 if (g->std_package != nullptr) {9647 if (g->std_package != nullptr) {
9646 assert(g->compile_var_package != nullptr);9648 assert(g->compile_var_package != nullptr);
9647 pkg->package_table.put(buf_create_from_str("std"), g->std_package);9649 pkg->package_table.put(buf_create_from_str("std"), g->std_package);
9650
9651 if (g->is_test_build) {
9652 pkg->package_table.put(buf_create_from_str("@root"), g->test_runner_package);
9653 } else {
9654 pkg->package_table.put(buf_create_from_str("@root"), g->root_package);
9655 }
9656
9648 pkg->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);9657 pkg->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
9649 }9658 }
9650 return pkg;9659 return pkg;