authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-14 11:00:37-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-14 11:01:01-04:00
log27253f09b6586ca602ebc64e21e48f5afa3464d9
treea418075c7c76cb05d39cfe9d95cd37fc3ec1e5a0
parent63a970a548c1973a216d9cf5109138451a0d214a
signature Commit is signed but in an unrecognized format.

organize how the single threaded option is passed around


3 files changed, 31 insertions(+), 11 deletions(-)

src/all_types.hpp+1
...@@ -1856,6 +1856,7 @@ struct CodeGen {...@@ -1856,6 +1856,7 @@ struct CodeGen {
1856 bool strip_debug_symbols;1856 bool strip_debug_symbols;
1857 bool is_test_build;1857 bool is_test_build;
1858 bool is_single_threaded;1858 bool is_single_threaded;
1859 bool want_single_threaded;
1859 bool linker_rdynamic;1860 bool linker_rdynamic;
1860 bool each_lib_rpath;1861 bool each_lib_rpath;
1861 bool is_dummy_so;1862 bool is_dummy_so;
src/codegen.cpp+25-2
...@@ -7337,9 +7337,26 @@ static bool detect_pic(CodeGen *g) {...@@ -7337,9 +7337,26 @@ static bool detect_pic(CodeGen *g) {
7337 zig_unreachable();7337 zig_unreachable();
7338}7338}
73397339
7340static bool detect_single_threaded(CodeGen *g) {
7341 if (g->want_single_threaded)
7342 return true;
7343 if (target_is_single_threaded(g->zig_target)) {
7344 return true;
7345 }
7346 return false;
7347}
7348
7349static bool detect_err_ret_tracing(CodeGen *g) {
7350 return !target_is_wasm(g->zig_target) &&
7351 g->build_mode != BuildModeFastRelease &&
7352 g->build_mode != BuildModeSmallRelease;
7353}
7354
7340Buf *codegen_generate_builtin_source(CodeGen *g) {7355Buf *codegen_generate_builtin_source(CodeGen *g) {
7341 g->have_dynamic_link = detect_dynamic_link(g);7356 g->have_dynamic_link = detect_dynamic_link(g);
7342 g->have_pic = detect_pic(g);7357 g->have_pic = detect_pic(g);
7358 g->is_single_threaded = detect_single_threaded(g);
7359 g->have_err_ret_tracing = detect_err_ret_tracing(g);
73437360
7344 Buf *contents = buf_alloc();7361 Buf *contents = buf_alloc();
73457362
...@@ -7844,6 +7861,12 @@ static void init(CodeGen *g) {...@@ -7844,6 +7861,12 @@ static void init(CodeGen *g) {
78447861
7845 g->have_dynamic_link = detect_dynamic_link(g);7862 g->have_dynamic_link = detect_dynamic_link(g);
7846 g->have_pic = detect_pic(g);7863 g->have_pic = detect_pic(g);
7864 g->is_single_threaded = detect_single_threaded(g);
7865 g->have_err_ret_tracing = detect_err_ret_tracing(g);
7866
7867 if (target_is_single_threaded(g->zig_target)) {
7868 g->is_single_threaded = true;
7869 }
78477870
7848 if (g->is_test_build) {7871 if (g->is_test_build) {
7849 g->subsystem = TargetSubsystemConsole;7872 g->subsystem = TargetSubsystemConsole;
...@@ -7953,8 +7976,6 @@ static void init(CodeGen *g) {...@@ -7953,8 +7976,6 @@ static void init(CodeGen *g) {
7953 }7976 }
7954 }7977 }
79557978
7956 g->have_err_ret_tracing = !target_is_wasm(g->zig_target) && g->build_mode != BuildModeFastRelease && g->build_mode != BuildModeSmallRelease;
7957
7958 define_builtin_fns(g);7979 define_builtin_fns(g);
7959 Error err;7980 Error err;
7960 if ((err = define_builtin_compile_vars(g))) {7981 if ((err = define_builtin_compile_vars(g))) {
...@@ -9268,6 +9289,8 @@ void codegen_build_and_link(CodeGen *g) {...@@ -9268,6 +9289,8 @@ void codegen_build_and_link(CodeGen *g) {
92689289
9269 g->have_dynamic_link = detect_dynamic_link(g);9290 g->have_dynamic_link = detect_dynamic_link(g);
9270 g->have_pic = detect_pic(g);9291 g->have_pic = detect_pic(g);
9292 g->is_single_threaded = detect_single_threaded(g);
9293 g->have_err_ret_tracing = detect_err_ret_tracing(g);
9271 detect_libc(g);9294 detect_libc(g);
9272 detect_dynamic_linker(g);9295 detect_dynamic_linker(g);
92739296
src/main.cpp+5-9
...@@ -450,7 +450,7 @@ int main(int argc, char **argv) {...@@ -450,7 +450,7 @@ int main(int argc, char **argv) {
450 int runtime_args_start = -1;450 int runtime_args_start = -1;
451 bool system_linker_hack = false;451 bool system_linker_hack = false;
452 TargetSubsystem subsystem = TargetSubsystemAuto;452 TargetSubsystem subsystem = TargetSubsystemAuto;
453 bool is_single_threaded = false;453 bool want_single_threaded = false;
454 bool disable_gen_h = false;454 bool disable_gen_h = false;
455 Buf *override_std_dir = nullptr;455 Buf *override_std_dir = nullptr;
456 Buf *main_pkg_path = nullptr;456 Buf *main_pkg_path = nullptr;
...@@ -590,7 +590,7 @@ int main(int argc, char **argv) {...@@ -590,7 +590,7 @@ int main(int argc, char **argv) {
590 CodeGen *g = codegen_create(main_pkg_path, fmt_runner_path, &target, OutTypeExe,590 CodeGen *g = codegen_create(main_pkg_path, fmt_runner_path, &target, OutTypeExe,
591 BuildModeDebug, get_zig_lib_dir(), nullptr, nullptr, cache_dir_buf);591 BuildModeDebug, get_zig_lib_dir(), nullptr, nullptr, cache_dir_buf);
592 g->valgrind_support = valgrind_support;592 g->valgrind_support = valgrind_support;
593 g->is_single_threaded = true;593 g->want_single_threaded = true;
594 codegen_set_out_name(g, buf_create_from_str("fmt"));594 codegen_set_out_name(g, buf_create_from_str("fmt"));
595 g->enable_cache = true;595 g->enable_cache = true;
596596
...@@ -671,7 +671,7 @@ int main(int argc, char **argv) {...@@ -671,7 +671,7 @@ int main(int argc, char **argv) {
671 } else if (strcmp(arg, "--system-linker-hack") == 0) {671 } else if (strcmp(arg, "--system-linker-hack") == 0) {
672 system_linker_hack = true;672 system_linker_hack = true;
673 } else if (strcmp(arg, "--single-threaded") == 0) {673 } else if (strcmp(arg, "--single-threaded") == 0) {
674 is_single_threaded = true;674 want_single_threaded = true;
675 } else if (strcmp(arg, "--disable-gen-h") == 0) {675 } else if (strcmp(arg, "--disable-gen-h") == 0) {
676 disable_gen_h = true;676 disable_gen_h = true;
677 } else if (strcmp(arg, "--test-cmd-bin") == 0) {677 } else if (strcmp(arg, "--test-cmd-bin") == 0) {
...@@ -921,10 +921,6 @@ int main(int argc, char **argv) {...@@ -921,10 +921,6 @@ int main(int argc, char **argv) {
921 }921 }
922 }922 }
923923
924 if (target_is_single_threaded(&target)) {
925 is_single_threaded = true;
926 }
927
928 if (output_dir != nullptr && enable_cache == CacheOptOn) {924 if (output_dir != nullptr && enable_cache == CacheOptOn) {
929 fprintf(stderr, "`--output-dir` is incompatible with --cache on.\n");925 fprintf(stderr, "`--output-dir` is incompatible with --cache on.\n");
930 return print_error_usage(arg0);926 return print_error_usage(arg0);
...@@ -966,7 +962,7 @@ int main(int argc, char **argv) {...@@ -966,7 +962,7 @@ int main(int argc, char **argv) {
966 out_type, build_mode, get_zig_lib_dir(), override_std_dir, nullptr, nullptr);962 out_type, build_mode, get_zig_lib_dir(), override_std_dir, nullptr, nullptr);
967 g->valgrind_support = valgrind_support;963 g->valgrind_support = valgrind_support;
968 g->want_pic = want_pic;964 g->want_pic = want_pic;
969 g->is_single_threaded = is_single_threaded;965 g->want_single_threaded = want_single_threaded;
970 Buf *builtin_source = codegen_generate_builtin_source(g);966 Buf *builtin_source = codegen_generate_builtin_source(g);
971 if (fwrite(buf_ptr(builtin_source), 1, buf_len(builtin_source), stdout) != buf_len(builtin_source)) {967 if (fwrite(buf_ptr(builtin_source), 1, buf_len(builtin_source), stdout) != buf_len(builtin_source)) {
972 fprintf(stderr, "unable to write to stdout: %s\n", strerror(ferror(stdout)));968 fprintf(stderr, "unable to write to stdout: %s\n", strerror(ferror(stdout)));
...@@ -1064,7 +1060,7 @@ int main(int argc, char **argv) {...@@ -1064,7 +1060,7 @@ int main(int argc, char **argv) {
1064 codegen_set_out_name(g, buf_out_name);1060 codegen_set_out_name(g, buf_out_name);
1065 codegen_set_lib_version(g, ver_major, ver_minor, ver_patch);1061 codegen_set_lib_version(g, ver_major, ver_minor, ver_patch);
1066 codegen_set_is_test(g, cmd == CmdTest);1062 codegen_set_is_test(g, cmd == CmdTest);
1067 g->is_single_threaded = is_single_threaded;1063 g->want_single_threaded = want_single_threaded;
1068 codegen_set_linker_script(g, linker_script);1064 codegen_set_linker_script(g, linker_script);
1069 if (each_lib_rpath)1065 if (each_lib_rpath)
1070 codegen_set_each_lib_rpath(g, each_lib_rpath);1066 codegen_set_each_lib_rpath(g, each_lib_rpath);