| author | |
| committer | |
| log | 67b4de33d2729fdb21337e5a0e05f6273bce23ba |
| tree | 2f79dc7eed0d993e82f777b3f90817731c2d5314 |
| parent | 764205ac13cc340ff6dcce74667c32dafe24e510 |
| signature |
closes #2024
there's a new cli option `--main-pkg-path` which you can use to choose
a different root package directory besides the one inferred from the
root source file
and a corresponding build.zig API:
foo.setMainPkgPath(path)17 files changed, 133 insertions(+), 60 deletions(-)
CMakeLists.txt+1-1| ... | @@ -606,7 +606,6 @@ set(ZIG_STD_FILES | ... | @@ -606,7 +606,6 @@ set(ZIG_STD_FILES |
| 606 | "os/windows/ntdll.zig" | 606 | "os/windows/ntdll.zig" |
| 607 | "os/windows/ole32.zig" | 607 | "os/windows/ole32.zig" |
| 608 | "os/windows/shell32.zig" | 608 | "os/windows/shell32.zig" |
| 609 | "os/windows/tls.zig" | ||
| 610 | "os/windows/util.zig" | 609 | "os/windows/util.zig" |
| 611 | "os/zen.zig" | 610 | "os/zen.zig" |
| 612 | "pdb.zig" | 611 | "pdb.zig" |
| ... | @@ -617,6 +616,7 @@ set(ZIG_STD_FILES | ... | @@ -617,6 +616,7 @@ set(ZIG_STD_FILES |
| 617 | "sort.zig" | 616 | "sort.zig" |
| 618 | "special/bootstrap.zig" | 617 | "special/bootstrap.zig" |
| 619 | "special/bootstrap_lib.zig" | 618 | "special/bootstrap_lib.zig" |
| 619 | "special/bootstrap_windows_tls.zig" | ||
| 620 | "special/build_runner.zig" | 620 | "special/build_runner.zig" |
| 621 | "special/builtin.zig" | 621 | "special/builtin.zig" |
| 622 | "special/compiler_rt/addXf3.zig" | 622 | "special/compiler_rt/addXf3.zig" |
src/analyze.cpp+3| ... | @@ -4502,6 +4502,9 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu | ... | @@ -4502,6 +4502,9 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu |
| 4502 | 4502 | ||
| 4503 | Buf *pkg_root_src_dir = &package->root_src_dir; | 4503 | Buf *pkg_root_src_dir = &package->root_src_dir; |
| 4504 | Buf resolved_root_src_dir = os_path_resolve(&pkg_root_src_dir, 1); | 4504 | Buf resolved_root_src_dir = os_path_resolve(&pkg_root_src_dir, 1); |
| 4505 | |||
| 4506 | assert(buf_starts_with_buf(resolved_path, &resolved_root_src_dir)); | ||
| 4507 | |||
| 4505 | Buf namespace_name = BUF_INIT; | 4508 | Buf namespace_name = BUF_INIT; |
| 4506 | buf_init_from_buf(&namespace_name, &package->pkg_path); | 4509 | buf_init_from_buf(&namespace_name, &package->pkg_path); |
| 4507 | if (source_kind == SourceKindNonRoot) { | 4510 | if (source_kind == SourceKindNonRoot) { |
src/codegen.cpp+28-9| ... | @@ -88,8 +88,8 @@ static const char *symbols_that_llvm_depends_on[] = { | ... | @@ -88,8 +88,8 @@ static const char *symbols_that_llvm_depends_on[] = { |
| 88 | // TODO probably all of compiler-rt needs to go here | 88 | // TODO probably all of compiler-rt needs to go here |
| 89 | }; | 89 | }; |
| 90 | 90 | ||
| 91 | CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode, | 91 | CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget *target, |
| 92 | Buf *zig_lib_dir, Buf *override_std_dir, ZigLibCInstallation *libc) | 92 | OutType out_type, BuildMode build_mode, Buf *zig_lib_dir, Buf *override_std_dir, ZigLibCInstallation *libc) |
| 93 | { | 93 | { |
| 94 | CodeGen *g = allocate<CodeGen>(1); | 94 | CodeGen *g = allocate<CodeGen>(1); |
| 95 | 95 | ||
| ... | @@ -133,16 +133,35 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out | ... | @@ -133,16 +133,35 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | if (root_src_path) { | 135 | if (root_src_path) { |
| 136 | Buf *src_basename = buf_alloc(); | 136 | Buf *root_pkg_path; |
| 137 | Buf *src_dir = buf_alloc(); | 137 | Buf *rel_root_src_path; |
| 138 | os_path_split(root_src_path, src_dir, src_basename); | 138 | if (main_pkg_path == nullptr) { |
| 139 | Buf *src_basename = buf_alloc(); | ||
| 140 | Buf *src_dir = buf_alloc(); | ||
| 141 | os_path_split(root_src_path, src_dir, src_basename); | ||
| 142 | |||
| 143 | if (buf_len(src_basename) == 0) { | ||
| 144 | fprintf(stderr, "Invalid root source path: %s\n", buf_ptr(root_src_path)); | ||
| 145 | exit(1); | ||
| 146 | } | ||
| 147 | root_pkg_path = src_dir; | ||
| 148 | rel_root_src_path = src_basename; | ||
| 149 | } else { | ||
| 150 | Buf resolved_root_src_path = os_path_resolve(&root_src_path, 1); | ||
| 151 | Buf resolved_main_pkg_path = os_path_resolve(&main_pkg_path, 1); | ||
| 139 | 152 | ||
| 140 | if (buf_len(src_basename) == 0) { | 153 | if (!buf_starts_with_buf(&resolved_root_src_path, &resolved_main_pkg_path)) { |
| 141 | fprintf(stderr, "Invalid root source path: %s\n", buf_ptr(root_src_path)); | 154 | fprintf(stderr, "Root source path '%s' outside main package path '%s'", |
| 142 | exit(1); | 155 | buf_ptr(root_src_path), buf_ptr(main_pkg_path)); |
| 156 | exit(1); | ||
| 157 | } | ||
| 158 | root_pkg_path = main_pkg_path; | ||
| 159 | rel_root_src_path = buf_create_from_mem( | ||
| 160 | buf_ptr(&resolved_root_src_path) + buf_len(&resolved_main_pkg_path) + 1, | ||
| 161 | buf_len(&resolved_root_src_path) - buf_len(&resolved_main_pkg_path) - 1); | ||
| 143 | } | 162 | } |
| 144 | 163 | ||
| 145 | g->root_package = new_package(buf_ptr(src_dir), buf_ptr(src_basename), ""); | 164 | g->root_package = new_package(buf_ptr(root_pkg_path), buf_ptr(rel_root_src_path), ""); |
| 146 | g->std_package = new_package(buf_ptr(g->zig_std_dir), "index.zig", "std"); | 165 | g->std_package = new_package(buf_ptr(g->zig_std_dir), "index.zig", "std"); |
| 147 | g->root_package->package_table.put(buf_create_from_str("std"), g->std_package); | 166 | g->root_package->package_table.put(buf_create_from_str("std"), g->std_package); |
| 148 | } else { | 167 | } else { |
src/codegen.hpp+2-2| ... | @@ -15,8 +15,8 @@ | ... | @@ -15,8 +15,8 @@ |
| 15 | 15 | ||
| 16 | #include <stdio.h> | 16 | #include <stdio.h> |
| 17 | 17 | ||
| 18 | CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode, | 18 | CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget *target, |
| 19 | Buf *zig_lib_dir, Buf *override_std_dir, ZigLibCInstallation *libc); | 19 | OutType out_type, BuildMode build_mode, Buf *zig_lib_dir, Buf *override_std_dir, ZigLibCInstallation *libc); |
| 20 | 20 | ||
| 21 | void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len); | 21 | void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len); |
| 22 | void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len); | 22 | void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len); |
src/ir.cpp+12| ... | @@ -17026,6 +17026,18 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio | ... | @@ -17026,6 +17026,18 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio |
| 17026 | return ir_const_type(ira, &import_instruction->base, import_entry->value); | 17026 | return ir_const_type(ira, &import_instruction->base, import_entry->value); |
| 17027 | } | 17027 | } |
| 17028 | 17028 | ||
| 17029 | if (source_kind == SourceKindNonRoot) { | ||
| 17030 | ZigPackage *cur_scope_pkg = scope_package(import_instruction->base.scope); | ||
| 17031 | Buf *pkg_root_src_dir = &cur_scope_pkg->root_src_dir; | ||
| 17032 | Buf resolved_root_src_dir = os_path_resolve(&pkg_root_src_dir, 1); | ||
| 17033 | if (!buf_starts_with_buf(resolved_path, &resolved_root_src_dir)) { | ||
| 17034 | ir_add_error_node(ira, source_node, | ||
| 17035 | buf_sprintf("import of file outside package path: '%s'", | ||
| 17036 | buf_ptr(import_target_path))); | ||
| 17037 | return ira->codegen->invalid_instruction; | ||
| 17038 | } | ||
| 17039 | } | ||
| 17040 | |||
| 17029 | if ((err = file_fetch(ira->codegen, resolved_path, import_code))) { | 17041 | if ((err = file_fetch(ira->codegen, resolved_path, import_code))) { |
| 17030 | if (err == ErrorFileNotFound) { | 17042 | if (err == ErrorFileNotFound) { |
| 17031 | ir_add_error_node(ira, source_node, | 17043 | ir_add_error_node(ira, source_node, |
src/link.cpp+1-1| ... | @@ -41,7 +41,7 @@ static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path) | ... | @@ -41,7 +41,7 @@ static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path) |
| 41 | child_out_type = OutTypeObj; | 41 | child_out_type = OutTypeObj; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | CodeGen *child_gen = codegen_create(full_path, parent_gen->zig_target, child_out_type, | 44 | CodeGen *child_gen = codegen_create(nullptr, full_path, parent_gen->zig_target, child_out_type, |
| 45 | parent_gen->build_mode, parent_gen->zig_lib_dir, parent_gen->zig_std_dir, | 45 | parent_gen->build_mode, parent_gen->zig_lib_dir, parent_gen->zig_std_dir, |
| 46 | parent_gen->libc); | 46 | parent_gen->libc); |
| 47 | 47 |
src/main.cpp+12-9| ... | @@ -63,6 +63,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) { | ... | @@ -63,6 +63,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) { |
| 63 | " --output-lib [file] override import library path\n" | 63 | " --output-lib [file] override import library path\n" |
| 64 | " --pkg-begin [name] [path] make pkg available to import and push current pkg\n" | 64 | " --pkg-begin [name] [path] make pkg available to import and push current pkg\n" |
| 65 | " --pkg-end pop current pkg\n" | 65 | " --pkg-end pop current pkg\n" |
| 66 | " --main-pkg-path set the directory of the root package\n" | ||
| 66 | " --release-fast build with optimizations on and safety off\n" | 67 | " --release-fast build with optimizations on and safety off\n" |
| 67 | " --release-safe build with optimizations on and safety on\n" | 68 | " --release-safe build with optimizations on and safety on\n" |
| 68 | " --release-small build with size optimizations on and safety off\n" | 69 | " --release-small build with size optimizations on and safety off\n" |
| ... | @@ -438,6 +439,7 @@ int main(int argc, char **argv) { | ... | @@ -438,6 +439,7 @@ int main(int argc, char **argv) { |
| 438 | TargetSubsystem subsystem = TargetSubsystemAuto; | 439 | TargetSubsystem subsystem = TargetSubsystemAuto; |
| 439 | bool is_single_threaded = false; | 440 | bool is_single_threaded = false; |
| 440 | Buf *override_std_dir = nullptr; | 441 | Buf *override_std_dir = nullptr; |
| 442 | Buf *main_pkg_path = nullptr; | ||
| 441 | ValgrindSupport valgrind_support = ValgrindSupportAuto; | 443 | ValgrindSupport valgrind_support = ValgrindSupportAuto; |
| 442 | 444 | ||
| 443 | if (argc >= 2 && strcmp(argv[1], "build") == 0) { | 445 | if (argc >= 2 && strcmp(argv[1], "build") == 0) { |
| ... | @@ -476,8 +478,8 @@ int main(int argc, char **argv) { | ... | @@ -476,8 +478,8 @@ int main(int argc, char **argv) { |
| 476 | 478 | ||
| 477 | ZigTarget target; | 479 | ZigTarget target; |
| 478 | get_native_target(&target); | 480 | get_native_target(&target); |
| 479 | CodeGen *g = codegen_create(build_runner_path, &target, OutTypeExe, BuildModeDebug, get_zig_lib_dir(), | 481 | CodeGen *g = codegen_create(main_pkg_path, build_runner_path, &target, OutTypeExe, |
| 480 | override_std_dir, nullptr); | 482 | BuildModeDebug, get_zig_lib_dir(), override_std_dir, nullptr); |
| 481 | g->valgrind_support = valgrind_support; | 483 | g->valgrind_support = valgrind_support; |
| 482 | g->enable_time_report = timing_info; | 484 | g->enable_time_report = timing_info; |
| 483 | buf_init_from_str(&g->cache_dir, cache_dir ? cache_dir : default_zig_cache_name); | 485 | buf_init_from_str(&g->cache_dir, cache_dir ? cache_dir : default_zig_cache_name); |
| ... | @@ -567,8 +569,8 @@ int main(int argc, char **argv) { | ... | @@ -567,8 +569,8 @@ int main(int argc, char **argv) { |
| 567 | get_native_target(&target); | 569 | get_native_target(&target); |
| 568 | Buf *fmt_runner_path = buf_alloc(); | 570 | Buf *fmt_runner_path = buf_alloc(); |
| 569 | os_path_join(get_zig_special_dir(), buf_create_from_str("fmt_runner.zig"), fmt_runner_path); | 571 | os_path_join(get_zig_special_dir(), buf_create_from_str("fmt_runner.zig"), fmt_runner_path); |
| 570 | CodeGen *g = codegen_create(fmt_runner_path, &target, OutTypeExe, BuildModeDebug, get_zig_lib_dir(), | 572 | CodeGen *g = codegen_create(main_pkg_path, fmt_runner_path, &target, OutTypeExe, |
| 571 | nullptr, nullptr); | 573 | BuildModeDebug, get_zig_lib_dir(), nullptr, nullptr); |
| 572 | buf_init_from_str(&g->cache_dir, cache_dir ? cache_dir : default_zig_cache_name); | 574 | buf_init_from_str(&g->cache_dir, cache_dir ? cache_dir : default_zig_cache_name); |
| 573 | g->valgrind_support = valgrind_support; | 575 | g->valgrind_support = valgrind_support; |
| 574 | g->is_single_threaded = true; | 576 | g->is_single_threaded = true; |
| ... | @@ -729,6 +731,8 @@ int main(int argc, char **argv) { | ... | @@ -729,6 +731,8 @@ int main(int argc, char **argv) { |
| 729 | llvm_argv.append(argv[i]); | 731 | llvm_argv.append(argv[i]); |
| 730 | } else if (strcmp(arg, "--override-std-dir") == 0) { | 732 | } else if (strcmp(arg, "--override-std-dir") == 0) { |
| 731 | override_std_dir = buf_create_from_str(argv[i]); | 733 | override_std_dir = buf_create_from_str(argv[i]); |
| 734 | } else if (strcmp(arg, "--main-pkg-path") == 0) { | ||
| 735 | main_pkg_path = buf_create_from_str(argv[i]); | ||
| 732 | } else if (strcmp(arg, "--library-path") == 0 || strcmp(arg, "-L") == 0) { | 736 | } else if (strcmp(arg, "--library-path") == 0 || strcmp(arg, "-L") == 0) { |
| 733 | lib_dirs.append(argv[i]); | 737 | lib_dirs.append(argv[i]); |
| 734 | } else if (strcmp(arg, "--library") == 0) { | 738 | } else if (strcmp(arg, "--library") == 0) { |
| ... | @@ -908,8 +912,8 @@ int main(int argc, char **argv) { | ... | @@ -908,8 +912,8 @@ int main(int argc, char **argv) { |
| 908 | return EXIT_SUCCESS; | 912 | return EXIT_SUCCESS; |
| 909 | } | 913 | } |
| 910 | case CmdBuiltin: { | 914 | case CmdBuiltin: { |
| 911 | CodeGen *g = codegen_create(nullptr, &target, out_type, build_mode, get_zig_lib_dir(), override_std_dir, | 915 | CodeGen *g = codegen_create(main_pkg_path, nullptr, &target, |
| 912 | nullptr); | 916 | out_type, build_mode, get_zig_lib_dir(), override_std_dir, nullptr); |
| 913 | g->valgrind_support = valgrind_support; | 917 | g->valgrind_support = valgrind_support; |
| 914 | g->is_single_threaded = is_single_threaded; | 918 | g->is_single_threaded = is_single_threaded; |
| 915 | Buf *builtin_source = codegen_generate_builtin_source(g); | 919 | Buf *builtin_source = codegen_generate_builtin_source(g); |
| ... | @@ -1012,8 +1016,8 @@ int main(int argc, char **argv) { | ... | @@ -1012,8 +1016,8 @@ int main(int argc, char **argv) { |
| 1012 | return EXIT_FAILURE; | 1016 | return EXIT_FAILURE; |
| 1013 | } | 1017 | } |
| 1014 | } | 1018 | } |
| 1015 | CodeGen *g = codegen_create(zig_root_source_file, &target, out_type, build_mode, get_zig_lib_dir(), | 1019 | CodeGen *g = codegen_create(main_pkg_path, zig_root_source_file, &target, out_type, build_mode, |
| 1016 | override_std_dir, libc); | 1020 | get_zig_lib_dir(), override_std_dir, libc); |
| 1017 | g->valgrind_support = valgrind_support; | 1021 | g->valgrind_support = valgrind_support; |
| 1018 | g->subsystem = subsystem; | 1022 | g->subsystem = subsystem; |
| 1019 | 1023 | ||
| ... | @@ -1096,7 +1100,6 @@ int main(int argc, char **argv) { | ... | @@ -1096,7 +1100,6 @@ int main(int argc, char **argv) { |
| 1096 | if (out_file_lib != nullptr && out_type == OutTypeLib && !is_static) | 1100 | if (out_file_lib != nullptr && out_type == OutTypeLib && !is_static) |
| 1097 | codegen_set_output_lib_path(g, buf_create_from_str(out_file_lib)); | 1101 | codegen_set_output_lib_path(g, buf_create_from_str(out_file_lib)); |
| 1098 | 1102 | ||
| 1099 | |||
| 1100 | add_package(g, cur_pkg, g->root_package); | 1103 | add_package(g, cur_pkg, g->root_package); |
| 1101 | 1104 | ||
| 1102 | if (cmd == CmdBuild || cmd == CmdRun || cmd == CmdTest) { | 1105 | if (cmd == CmdBuild || cmd == CmdRun || cmd == CmdTest) { |
std/build.zig+11| ... | @@ -859,6 +859,7 @@ pub const LibExeObjStep = struct { | ... | @@ -859,6 +859,7 @@ pub const LibExeObjStep = struct { |
| 859 | verbose_cc: bool, | 859 | verbose_cc: bool, |
| 860 | c_std: Builder.CStd, | 860 | c_std: Builder.CStd, |
| 861 | override_std_dir: ?[]const u8, | 861 | override_std_dir: ?[]const u8, |
| 862 | main_pkg_path: ?[]const u8, | ||
| 862 | exec_cmd_args: ?[]const ?[]const u8, | 863 | exec_cmd_args: ?[]const ?[]const u8, |
| 863 | name_prefix: []const u8, | 864 | name_prefix: []const u8, |
| 864 | filter: ?[]const u8, | 865 | filter: ?[]const u8, |
| ... | @@ -950,6 +951,7 @@ pub const LibExeObjStep = struct { | ... | @@ -950,6 +951,7 @@ pub const LibExeObjStep = struct { |
| 950 | .c_std = Builder.CStd.C99, | 951 | .c_std = Builder.CStd.C99, |
| 951 | .system_linker_hack = false, | 952 | .system_linker_hack = false, |
| 952 | .override_std_dir = null, | 953 | .override_std_dir = null, |
| 954 | .main_pkg_path = null, | ||
| 953 | .exec_cmd_args = null, | 955 | .exec_cmd_args = null, |
| 954 | .name_prefix = "", | 956 | .name_prefix = "", |
| 955 | .filter = null, | 957 | .filter = null, |
| ... | @@ -1098,6 +1100,10 @@ pub const LibExeObjStep = struct { | ... | @@ -1098,6 +1100,10 @@ pub const LibExeObjStep = struct { |
| 1098 | self.override_std_dir = dir_path; | 1100 | self.override_std_dir = dir_path; |
| 1099 | } | 1101 | } |
| 1100 | 1102 | ||
| 1103 | pub fn setMainPkgPath(self: *LibExeObjStep, dir_path: []const u8) void { | ||
| 1104 | self.main_pkg_path = dir_path; | ||
| 1105 | } | ||
| 1106 | |||
| 1101 | pub fn setOutputPath(self: *LibExeObjStep, file_path: []const u8) void { | 1107 | pub fn setOutputPath(self: *LibExeObjStep, file_path: []const u8) void { |
| 1102 | self.output_path = file_path; | 1108 | self.output_path = file_path; |
| 1103 | 1109 | ||
| ... | @@ -1424,6 +1430,11 @@ pub const LibExeObjStep = struct { | ... | @@ -1424,6 +1430,11 @@ pub const LibExeObjStep = struct { |
| 1424 | try zig_args.append(builder.pathFromRoot(dir)); | 1430 | try zig_args.append(builder.pathFromRoot(dir)); |
| 1425 | } | 1431 | } |
| 1426 | 1432 | ||
| 1433 | if (self.main_pkg_path) |dir| { | ||
| 1434 | try zig_args.append("--main-pkg-path"); | ||
| 1435 | try zig_args.append(builder.pathFromRoot(dir)); | ||
| 1436 | } | ||
| 1437 | |||
| 1427 | try builder.spawnChild(zig_args.toSliceConst()); | 1438 | try builder.spawnChild(zig_args.toSliceConst()); |
| 1428 | 1439 | ||
| 1429 | if (self.kind == Kind.Lib and !self.static and self.target.wantSharedLibSymLinks()) { | 1440 | if (self.kind == Kind.Lib and !self.static and self.target.wantSharedLibSymLinks()) { |
std/os/windows/tls.zig deleted-36| ... | @@ -1,36 +0,0 @@ | ||
| 1 | const std = @import("../../index.zig"); | ||
| 2 | |||
| 3 | export var _tls_index: u32 = std.os.windows.TLS_OUT_OF_INDEXES; | ||
| 4 | export var _tls_start: u8 linksection(".tls") = 0; | ||
| 5 | export var _tls_end: u8 linksection(".tls$ZZZ") = 0; | ||
| 6 | export var __xl_a: std.os.windows.PIMAGE_TLS_CALLBACK linksection(".CRT$XLA") = null; | ||
| 7 | export var __xl_z: std.os.windows.PIMAGE_TLS_CALLBACK linksection(".CRT$XLZ") = null; | ||
| 8 | |||
| 9 | // TODO this is how I would like it to be expressed | ||
| 10 | // TODO also note, ReactOS has a +1 on StartAddressOfRawData and AddressOfCallBacks. Investigate | ||
| 11 | // why they do that. | ||
| 12 | //export const _tls_used linksection(".rdata$T") = std.os.windows.IMAGE_TLS_DIRECTORY { | ||
| 13 | // .StartAddressOfRawData = @ptrToInt(&_tls_start), | ||
| 14 | // .EndAddressOfRawData = @ptrToInt(&_tls_end), | ||
| 15 | // .AddressOfIndex = @ptrToInt(&_tls_index), | ||
| 16 | // .AddressOfCallBacks = @ptrToInt(__xl_a), | ||
| 17 | // .SizeOfZeroFill = 0, | ||
| 18 | // .Characteristics = 0, | ||
| 19 | //}; | ||
| 20 | // This is the workaround because we can't do @ptrToInt at comptime like that. | ||
| 21 | pub const IMAGE_TLS_DIRECTORY = extern struct { | ||
| 22 | StartAddressOfRawData: *c_void, | ||
| 23 | EndAddressOfRawData: *c_void, | ||
| 24 | AddressOfIndex: *c_void, | ||
| 25 | AddressOfCallBacks: *c_void, | ||
| 26 | SizeOfZeroFill: u32, | ||
| 27 | Characteristics: u32, | ||
| 28 | }; | ||
| 29 | export const _tls_used linksection(".rdata$T") = IMAGE_TLS_DIRECTORY { | ||
| 30 | .StartAddressOfRawData = &_tls_start, | ||
| 31 | .EndAddressOfRawData = &_tls_end, | ||
| 32 | .AddressOfIndex = &_tls_index, | ||
| 33 | .AddressOfCallBacks = &__xl_a, | ||
| 34 | .SizeOfZeroFill = 0, | ||
| 35 | .Characteristics = 0, | ||
| 36 | }; | ||
std/special/bootstrap.zig+1-1| ... | @@ -46,7 +46,7 @@ nakedcc fn _start() noreturn { | ... | @@ -46,7 +46,7 @@ nakedcc fn _start() noreturn { |
| 46 | extern fn WinMainCRTStartup() noreturn { | 46 | extern fn WinMainCRTStartup() noreturn { |
| 47 | @setAlignStack(16); | 47 | @setAlignStack(16); |
| 48 | if (!builtin.single_threaded) { | 48 | if (!builtin.single_threaded) { |
| 49 | _ = @import("../os/windows/tls.zig"); | 49 | _ = @import("bootstrap_windows_tls.zig"); |
| 50 | } | 50 | } |
| 51 | std.os.windows.ExitProcess(callMain()); | 51 | std.os.windows.ExitProcess(callMain()); |
| 52 | } | 52 | } |
std/special/bootstrap_windows_tls.zig created+36| ... | @@ -0,0 +1,36 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | export var _tls_index: u32 = std.os.windows.TLS_OUT_OF_INDEXES; | ||
| 4 | export var _tls_start: u8 linksection(".tls") = 0; | ||
| 5 | export var _tls_end: u8 linksection(".tls$ZZZ") = 0; | ||
| 6 | export var __xl_a: std.os.windows.PIMAGE_TLS_CALLBACK linksection(".CRT$XLA") = null; | ||
| 7 | export var __xl_z: std.os.windows.PIMAGE_TLS_CALLBACK linksection(".CRT$XLZ") = null; | ||
| 8 | |||
| 9 | // TODO this is how I would like it to be expressed | ||
| 10 | // TODO also note, ReactOS has a +1 on StartAddressOfRawData and AddressOfCallBacks. Investigate | ||
| 11 | // why they do that. | ||
| 12 | //export const _tls_used linksection(".rdata$T") = std.os.windows.IMAGE_TLS_DIRECTORY { | ||
| 13 | // .StartAddressOfRawData = @ptrToInt(&_tls_start), | ||
| 14 | // .EndAddressOfRawData = @ptrToInt(&_tls_end), | ||
| 15 | // .AddressOfIndex = @ptrToInt(&_tls_index), | ||
| 16 | // .AddressOfCallBacks = @ptrToInt(__xl_a), | ||
| 17 | // .SizeOfZeroFill = 0, | ||
| 18 | // .Characteristics = 0, | ||
| 19 | //}; | ||
| 20 | // This is the workaround because we can't do @ptrToInt at comptime like that. | ||
| 21 | pub const IMAGE_TLS_DIRECTORY = extern struct { | ||
| 22 | StartAddressOfRawData: *c_void, | ||
| 23 | EndAddressOfRawData: *c_void, | ||
| 24 | AddressOfIndex: *c_void, | ||
| 25 | AddressOfCallBacks: *c_void, | ||
| 26 | SizeOfZeroFill: u32, | ||
| 27 | Characteristics: u32, | ||
| 28 | }; | ||
| 29 | export const _tls_used linksection(".rdata$T") = IMAGE_TLS_DIRECTORY{ | ||
| 30 | .StartAddressOfRawData = &_tls_start, | ||
| 31 | .EndAddressOfRawData = &_tls_end, | ||
| 32 | .AddressOfIndex = &_tls_index, | ||
| 33 | .AddressOfCallBacks = &__xl_a, | ||
| 34 | .SizeOfZeroFill = 0, | ||
| 35 | .Characteristics = 0, | ||
| 36 | }; | ||
std/special/builtin.zig+1-1| ... | @@ -134,7 +134,7 @@ nakedcc fn clone() void { | ... | @@ -134,7 +134,7 @@ nakedcc fn clone() void { |
| 134 | } | 134 | } |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | const math = @import("../math/index.zig"); | 137 | const math = std.math; |
| 138 | 138 | ||
| 139 | export fn fmodf(x: f32, y: f32) f32 { | 139 | export fn fmodf(x: f32, y: f32) f32 { |
| 140 | return generic_fmod(f32, x, y); | 140 | return generic_fmod(f32, x, y); |
test/build_examples.zig+1| ... | @@ -7,6 +7,7 @@ pub fn addCases(cases: *tests.BuildExamplesContext) void { | ... | @@ -7,6 +7,7 @@ pub fn addCases(cases: *tests.BuildExamplesContext) void { |
| 7 | cases.addC("example/hello_world/hello_libc.zig"); | 7 | cases.addC("example/hello_world/hello_libc.zig"); |
| 8 | cases.add("example/cat/main.zig"); | 8 | cases.add("example/cat/main.zig"); |
| 9 | cases.add("example/guess_number/main.zig"); | 9 | cases.add("example/guess_number/main.zig"); |
| 10 | cases.addBuildFile("test/standalone/main_pkg_path/build.zig"); | ||
| 10 | cases.addBuildFile("example/shared_library/build.zig"); | 11 | cases.addBuildFile("example/shared_library/build.zig"); |
| 11 | cases.addBuildFile("example/mix_o_files/build.zig"); | 12 | cases.addBuildFile("example/mix_o_files/build.zig"); |
| 12 | if (builtin.os != builtin.Os.macosx) { | 13 | if (builtin.os != builtin.Os.macosx) { |
test/compile_errors.zig+9| ... | @@ -2,6 +2,15 @@ const tests = @import("tests.zig"); | ... | @@ -2,6 +2,15 @@ const tests = @import("tests.zig"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.add( | ||
| 6 | "import outside package path", | ||
| 7 | \\comptime{ | ||
| 8 | \\ _ = @import("../a.zig"); | ||
| 9 | \\} | ||
| 10 | , | ||
| 11 | "tmp.zig:2:9: error: import of file outside package path: '../a.zig'", | ||
| 12 | ); | ||
| 13 | |||
| 5 | cases.add( | 14 | cases.add( |
| 6 | "bogus compile var", | 15 | "bogus compile var", |
| 7 | \\const x = @import("builtin").bogus; | 16 | \\const x = @import("builtin").bogus; |
test/standalone/main_pkg_path/a/test.zig created+5| ... | @@ -0,0 +1,5 @@ | ||
| 1 | const b = @import("../b.zig"); | ||
| 2 | |||
| 3 | test "main pkg path" { | ||
| 4 | b.foo(); | ||
| 5 | } | ||
test/standalone/main_pkg_path/b.zig created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | pub fn foo() void {} | ||
test/standalone/main_pkg_path/build.zig created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | const Builder = @import("std").build.Builder; | ||
| 2 | |||
| 3 | pub fn build(b: *Builder) void { | ||
| 4 | const test_exe = b.addTest("a/test.zig"); | ||
| 5 | test_exe.setMainPkgPath("."); | ||
| 6 | |||
| 7 | const test_step = b.step("test", "Test the program"); | ||
| 8 | test_step.dependOn(&test_exe.step); | ||
| 9 | } | ||