| author | |
| committer | |
| log | 87bc97daefc8b5d8b665ea2fb2b6c232b80344bc |
| tree | edf82e24345f0049fb930cdec36aa299b42c3ca5 |
| parent | e1c47d6fe88bb1d79a4484e07d21f126ca9f1003 |
closes #24812 files changed, 86 insertions(+), 57 deletions(-)
CMakeLists.txt+1-2| ... | @@ -202,6 +202,7 @@ install(TARGETS zig DESTINATION bin) | ... | @@ -202,6 +202,7 @@ install(TARGETS zig DESTINATION bin) |
| 202 | install(FILES ${C_HEADERS} DESTINATION ${C_HEADERS_DEST}) | 202 | install(FILES ${C_HEADERS} DESTINATION ${C_HEADERS_DEST}) |
| 203 | 203 | ||
| 204 | install(FILES "${CMAKE_SOURCE_DIR}/std/bootstrap.zig" DESTINATION "${ZIG_STD_DEST}") | 204 | install(FILES "${CMAKE_SOURCE_DIR}/std/bootstrap.zig" DESTINATION "${ZIG_STD_DEST}") |
| 205 | install(FILES "${CMAKE_SOURCE_DIR}/std/build.zig" DESTINATION "${ZIG_STD_DEST}") | ||
| 205 | install(FILES "${CMAKE_SOURCE_DIR}/std/builtin.zig" DESTINATION "${ZIG_STD_DEST}") | 206 | install(FILES "${CMAKE_SOURCE_DIR}/std/builtin.zig" DESTINATION "${ZIG_STD_DEST}") |
| 206 | install(FILES "${CMAKE_SOURCE_DIR}/std/compiler_rt.zig" DESTINATION "${ZIG_STD_DEST}") | 207 | install(FILES "${CMAKE_SOURCE_DIR}/std/compiler_rt.zig" DESTINATION "${ZIG_STD_DEST}") |
| 207 | install(FILES "${CMAKE_SOURCE_DIR}/std/cstr.zig" DESTINATION "${ZIG_STD_DEST}") | 208 | install(FILES "${CMAKE_SOURCE_DIR}/std/cstr.zig" DESTINATION "${ZIG_STD_DEST}") |
| ... | @@ -230,8 +231,6 @@ install(FILES "${CMAKE_SOURCE_DIR}/std/rand.zig" DESTINATION "${ZIG_STD_DEST}") | ... | @@ -230,8 +231,6 @@ install(FILES "${CMAKE_SOURCE_DIR}/std/rand.zig" DESTINATION "${ZIG_STD_DEST}") |
| 230 | install(FILES "${CMAKE_SOURCE_DIR}/std/rand_test.zig" DESTINATION "${ZIG_STD_DEST}") | 231 | install(FILES "${CMAKE_SOURCE_DIR}/std/rand_test.zig" DESTINATION "${ZIG_STD_DEST}") |
| 231 | install(FILES "${CMAKE_SOURCE_DIR}/std/sort.zig" DESTINATION "${ZIG_STD_DEST}") | 232 | install(FILES "${CMAKE_SOURCE_DIR}/std/sort.zig" DESTINATION "${ZIG_STD_DEST}") |
| 232 | install(FILES "${CMAKE_SOURCE_DIR}/std/test_runner.zig" DESTINATION "${ZIG_STD_DEST}") | 233 | install(FILES "${CMAKE_SOURCE_DIR}/std/test_runner.zig" DESTINATION "${ZIG_STD_DEST}") |
| 233 | install(FILES "${CMAKE_SOURCE_DIR}/std/test_runner_libc.zig" DESTINATION "${ZIG_STD_DEST}") | ||
| 234 | install(FILES "${CMAKE_SOURCE_DIR}/std/test_runner_nolibc.zig" DESTINATION "${ZIG_STD_DEST}") | ||
| 235 | 234 | ||
| 236 | add_executable(run_tests ${TEST_SOURCES}) | 235 | add_executable(run_tests ${TEST_SOURCES}) |
| 237 | target_link_libraries(run_tests) | 236 | target_link_libraries(run_tests) |
src/all_types.hpp+3-2| ... | @@ -1291,6 +1291,7 @@ struct CodeGen { | ... | @@ -1291,6 +1291,7 @@ struct CodeGen { |
| 1291 | HashMap<GenericFnTypeId *, FnTableEntry *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table; | 1291 | HashMap<GenericFnTypeId *, FnTableEntry *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table; |
| 1292 | HashMap<Scope *, IrInstruction *, fn_eval_hash, fn_eval_eql> memoized_fn_eval_table; | 1292 | HashMap<Scope *, IrInstruction *, fn_eval_hash, fn_eval_eql> memoized_fn_eval_table; |
| 1293 | HashMap<ZigLLVMFnKey, LLVMValueRef, zig_llvm_fn_key_hash, zig_llvm_fn_key_eql> llvm_fn_table; | 1293 | HashMap<ZigLLVMFnKey, LLVMValueRef, zig_llvm_fn_key_hash, zig_llvm_fn_key_eql> llvm_fn_table; |
| 1294 | HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> compile_vars; | ||
| 1294 | 1295 | ||
| 1295 | ZigList<ImportTableEntry *> import_queue; | 1296 | ZigList<ImportTableEntry *> import_queue; |
| 1296 | size_t import_queue_index; | 1297 | size_t import_queue_index; |
| ... | @@ -1346,8 +1347,8 @@ struct CodeGen { | ... | @@ -1346,8 +1347,8 @@ struct CodeGen { |
| 1346 | bool is_static; | 1347 | bool is_static; |
| 1347 | bool strip_debug_symbols; | 1348 | bool strip_debug_symbols; |
| 1348 | bool want_h_file; | 1349 | bool want_h_file; |
| 1349 | bool have_exported_main; | 1350 | bool have_pub_main; |
| 1350 | bool have_exported_panic; | 1351 | bool have_pub_panic; |
| 1351 | bool link_libc; | 1352 | bool link_libc; |
| 1352 | Buf *libc_lib_dir; | 1353 | Buf *libc_lib_dir; |
| 1353 | Buf *libc_static_lib_dir; | 1354 | Buf *libc_static_lib_dir; |
src/analyze.cpp+2-2| ... | @@ -2878,9 +2878,9 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, | ... | @@ -2878,9 +2878,9 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, |
| 2878 | 2878 | ||
| 2879 | if (is_pub) { | 2879 | if (is_pub) { |
| 2880 | if (buf_eql_str(proto_name, "main")) { | 2880 | if (buf_eql_str(proto_name, "main")) { |
| 2881 | g->have_exported_main = true; | 2881 | g->have_pub_main = true; |
| 2882 | } else if (buf_eql_str(proto_name, "panic")) { | 2882 | } else if (buf_eql_str(proto_name, "panic")) { |
| 2883 | g->have_exported_panic = true; | 2883 | g->have_pub_panic = true; |
| 2884 | } | 2884 | } |
| 2885 | } | 2885 | } |
| 2886 | } | 2886 | } |
src/codegen.cpp+36-7| ... | @@ -66,6 +66,7 @@ CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target) { | ... | @@ -66,6 +66,7 @@ CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target) { |
| 66 | g->generic_table.init(16); | 66 | g->generic_table.init(16); |
| 67 | g->llvm_fn_table.init(16); | 67 | g->llvm_fn_table.init(16); |
| 68 | g->memoized_fn_eval_table.init(16); | 68 | g->memoized_fn_eval_table.init(16); |
| 69 | g->compile_vars.init(16); | ||
| 69 | g->is_release_build = false; | 70 | g->is_release_build = false; |
| 70 | g->is_test_build = false; | 71 | g->is_test_build = false; |
| 71 | g->want_h_file = true; | 72 | g->want_h_file = true; |
| ... | @@ -191,9 +192,8 @@ void codegen_add_rpath(CodeGen *g, const char *name) { | ... | @@ -191,9 +192,8 @@ void codegen_add_rpath(CodeGen *g, const char *name) { |
| 191 | void codegen_add_link_lib(CodeGen *g, const char *lib) { | 192 | void codegen_add_link_lib(CodeGen *g, const char *lib) { |
| 192 | if (strcmp(lib, "c") == 0) { | 193 | if (strcmp(lib, "c") == 0) { |
| 193 | g->link_libc = true; | 194 | g->link_libc = true; |
| 194 | } else { | ||
| 195 | g->link_libs.append(buf_create_from_str(lib)); | ||
| 196 | } | 195 | } |
| 196 | g->link_libs.append(buf_create_from_str(lib)); | ||
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | void codegen_add_framework(CodeGen *g, const char *framework) { | 199 | void codegen_add_framework(CodeGen *g, const char *framework) { |
| ... | @@ -4057,6 +4057,36 @@ static void define_builtin_fns(CodeGen *g) { | ... | @@ -4057,6 +4057,36 @@ static void define_builtin_fns(CodeGen *g) { |
| 4057 | create_builtin_fn(g, BuiltinFnIdSetGlobalSection, "setGlobalSection", 2); | 4057 | create_builtin_fn(g, BuiltinFnIdSetGlobalSection, "setGlobalSection", 2); |
| 4058 | } | 4058 | } |
| 4059 | 4059 | ||
| 4060 | static void add_compile_var(CodeGen *g, const char *name, ConstExprValue *value) { | ||
| 4061 | g->compile_vars.put_unique(buf_create_from_str(name), value); | ||
| 4062 | } | ||
| 4063 | |||
| 4064 | static void define_builtin_compile_vars(CodeGen *g) { | ||
| 4065 | add_compile_var(g, "is_big_endian", create_const_bool(g, g->is_big_endian)); | ||
| 4066 | add_compile_var(g, "is_release", create_const_bool(g, g->is_release_build)); | ||
| 4067 | add_compile_var(g, "is_test", create_const_bool(g, g->is_test_build)); | ||
| 4068 | add_compile_var(g, "os", create_const_enum_tag(g->builtin_types.entry_os_enum, g->target_os_index)); | ||
| 4069 | add_compile_var(g, "arch", create_const_enum_tag(g->builtin_types.entry_arch_enum, g->target_arch_index)); | ||
| 4070 | add_compile_var(g, "environ", create_const_enum_tag(g->builtin_types.entry_environ_enum, g->target_environ_index)); | ||
| 4071 | add_compile_var(g, "object_format", create_const_enum_tag( | ||
| 4072 | g->builtin_types.entry_oformat_enum, g->target_oformat_index)); | ||
| 4073 | |||
| 4074 | { | ||
| 4075 | TypeTableEntry *str_type = get_slice_type(g, g->builtin_types.entry_u8, true); | ||
| 4076 | ConstExprValue *const_val = allocate<ConstExprValue>(1); | ||
| 4077 | const_val->special = ConstValSpecialStatic; | ||
| 4078 | const_val->type = get_array_type(g, str_type, g->link_libs.length); | ||
| 4079 | const_val->data.x_array.elements = allocate<ConstExprValue>(g->link_libs.length); | ||
| 4080 | for (size_t i = 0; i < g->link_libs.length; i += 1) { | ||
| 4081 | Buf *link_lib_buf = g->link_libs.at(i); | ||
| 4082 | ConstExprValue *array_val = create_const_str_lit(g, link_lib_buf); | ||
| 4083 | init_const_slice(g, &const_val->data.x_array.elements[i], array_val, 0, buf_len(link_lib_buf), true); | ||
| 4084 | } | ||
| 4085 | |||
| 4086 | add_compile_var(g, "link_libs", const_val); | ||
| 4087 | } | ||
| 4088 | } | ||
| 4089 | |||
| 4060 | static void init(CodeGen *g, Buf *source_path) { | 4090 | static void init(CodeGen *g, Buf *source_path) { |
| 4061 | g->module = LLVMModuleCreateWithName(buf_ptr(source_path)); | 4091 | g->module = LLVMModuleCreateWithName(buf_ptr(source_path)); |
| 4062 | 4092 | ||
| ... | @@ -4120,6 +4150,7 @@ static void init(CodeGen *g, Buf *source_path) { | ... | @@ -4120,6 +4150,7 @@ static void init(CodeGen *g, Buf *source_path) { |
| 4120 | 4150 | ||
| 4121 | define_builtin_types(g); | 4151 | define_builtin_types(g); |
| 4122 | define_builtin_fns(g); | 4152 | define_builtin_fns(g); |
| 4153 | define_builtin_compile_vars(g); | ||
| 4123 | 4154 | ||
| 4124 | g->invalid_instruction = allocate<IrInstruction>(1); | 4155 | g->invalid_instruction = allocate<IrInstruction>(1); |
| 4125 | g->invalid_instruction->value.type = g->builtin_types.entry_invalid; | 4156 | g->invalid_instruction->value.type = g->builtin_types.entry_invalid; |
| ... | @@ -4209,12 +4240,10 @@ void codegen_add_root_code(CodeGen *g, Buf *src_dir, Buf *src_basename, Buf *sou | ... | @@ -4209,12 +4240,10 @@ void codegen_add_root_code(CodeGen *g, Buf *src_dir, Buf *src_basename, Buf *sou |
| 4209 | assert(g->root_out_name); | 4240 | assert(g->root_out_name); |
| 4210 | assert(g->out_type != OutTypeUnknown); | 4241 | assert(g->out_type != OutTypeUnknown); |
| 4211 | 4242 | ||
| 4212 | if (!g->link_libc && !g->is_test_build) { | 4243 | if (!g->is_test_build && g->have_pub_main && (g->out_type == OutTypeObj || g->out_type == OutTypeExe)) { |
| 4213 | if (g->have_exported_main && (g->out_type == OutTypeObj || g->out_type == OutTypeExe)) { | 4244 | g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g), "bootstrap.zig"); |
| 4214 | g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g), "bootstrap.zig"); | ||
| 4215 | } | ||
| 4216 | } | 4245 | } |
| 4217 | if (!g->have_exported_panic) { | 4246 | if (!g->have_pub_panic) { |
| 4218 | g->panic_package = create_panic_pkg(g); | 4247 | g->panic_package = create_panic_pkg(g); |
| 4219 | add_special_code(g, g->panic_package, "panic.zig"); | 4248 | add_special_code(g, g->panic_package, "panic.zig"); |
| 4220 | } | 4249 | } |
src/ir.cpp+4-21| ... | @@ -9869,27 +9869,10 @@ static TypeTableEntry *ir_analyze_instruction_compile_var(IrAnalyze *ira, | ... | @@ -9869,27 +9869,10 @@ static TypeTableEntry *ir_analyze_instruction_compile_var(IrAnalyze *ira, |
| 9869 | return ira->codegen->builtin_types.entry_invalid; | 9869 | return ira->codegen->builtin_types.entry_invalid; |
| 9870 | 9870 | ||
| 9871 | ConstExprValue *out_val = ir_build_const_from(ira, &compile_var_instruction->base); | 9871 | ConstExprValue *out_val = ir_build_const_from(ira, &compile_var_instruction->base); |
| 9872 | if (buf_eql_str(var_name, "is_big_endian")) { | 9872 | auto entry = ira->codegen->compile_vars.maybe_get(var_name); |
| 9873 | out_val->data.x_bool = ira->codegen->is_big_endian; | 9873 | if (entry) { |
| 9874 | return ira->codegen->builtin_types.entry_bool; | 9874 | *out_val = *entry->value; |
| 9875 | } else if (buf_eql_str(var_name, "is_release")) { | 9875 | return out_val->type; |
| 9876 | out_val->data.x_bool = ira->codegen->is_release_build; | ||
| 9877 | return ira->codegen->builtin_types.entry_bool; | ||
| 9878 | } else if (buf_eql_str(var_name, "is_test")) { | ||
| 9879 | out_val->data.x_bool = ira->codegen->is_test_build; | ||
| 9880 | return ira->codegen->builtin_types.entry_bool; | ||
| 9881 | } else if (buf_eql_str(var_name, "os")) { | ||
| 9882 | out_val->data.x_enum.tag = ira->codegen->target_os_index; | ||
| 9883 | return ira->codegen->builtin_types.entry_os_enum; | ||
| 9884 | } else if (buf_eql_str(var_name, "arch")) { | ||
| 9885 | out_val->data.x_enum.tag = ira->codegen->target_arch_index; | ||
| 9886 | return ira->codegen->builtin_types.entry_arch_enum; | ||
| 9887 | } else if (buf_eql_str(var_name, "environ")) { | ||
| 9888 | out_val->data.x_enum.tag = ira->codegen->target_environ_index; | ||
| 9889 | return ira->codegen->builtin_types.entry_environ_enum; | ||
| 9890 | } else if (buf_eql_str(var_name, "object_format")) { | ||
| 9891 | out_val->data.x_enum.tag = ira->codegen->target_oformat_index; | ||
| 9892 | return ira->codegen->builtin_types.entry_oformat_enum; | ||
| 9893 | } else { | 9876 | } else { |
| 9894 | ir_add_error_node(ira, name_value->source_node, | 9877 | ir_add_error_node(ira, name_value->source_node, |
| 9895 | buf_sprintf("unrecognized compile variable: '%s'", buf_ptr(var_name))); | 9878 | buf_sprintf("unrecognized compile variable: '%s'", buf_ptr(var_name))); |
src/link.cpp+21-6| ... | @@ -47,6 +47,12 @@ static Buf *build_o(CodeGen *parent_gen, const char *oname) { | ... | @@ -47,6 +47,12 @@ static Buf *build_o(CodeGen *parent_gen, const char *oname) { |
| 47 | ZigTarget *child_target = parent_gen->is_native_target ? nullptr : &parent_gen->zig_target; | 47 | ZigTarget *child_target = parent_gen->is_native_target ? nullptr : &parent_gen->zig_target; |
| 48 | CodeGen *child_gen = codegen_create(std_dir_path, child_target); | 48 | CodeGen *child_gen = codegen_create(std_dir_path, child_target); |
| 49 | child_gen->link_libc = parent_gen->link_libc; | 49 | child_gen->link_libc = parent_gen->link_libc; |
| 50 | |||
| 51 | child_gen->link_libs.resize(parent_gen->link_libs.length); | ||
| 52 | for (size_t i = 0; i < parent_gen->link_libs.length; i += 1) { | ||
| 53 | child_gen->link_libs.items[i] = parent_gen->link_libs.items[i]; | ||
| 54 | } | ||
| 55 | |||
| 50 | child_gen->want_h_file = false; | 56 | child_gen->want_h_file = false; |
| 51 | 57 | ||
| 52 | codegen_set_is_release(child_gen, parent_gen->is_release_build); | 58 | codegen_set_is_release(child_gen, parent_gen->is_release_build); |
| ... | @@ -223,6 +229,9 @@ static void construct_linker_job_elf(LinkJob *lj) { | ... | @@ -223,6 +229,9 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 223 | const char *lib_dir = g->lib_dirs.at(i); | 229 | const char *lib_dir = g->lib_dirs.at(i); |
| 224 | for (size_t i = 0; i < g->link_libs.length; i += 1) { | 230 | for (size_t i = 0; i < g->link_libs.length; i += 1) { |
| 225 | Buf *link_lib = g->link_libs.at(i); | 231 | Buf *link_lib = g->link_libs.at(i); |
| 232 | if (buf_eql_str(link_lib, "c")) { | ||
| 233 | continue; | ||
| 234 | } | ||
| 226 | bool does_exist; | 235 | bool does_exist; |
| 227 | Buf *test_path = buf_sprintf("%s/lib%s.so", lib_dir, buf_ptr(link_lib)); | 236 | Buf *test_path = buf_sprintf("%s/lib%s.so", lib_dir, buf_ptr(link_lib)); |
| 228 | if (os_file_exists(test_path, &does_exist) != ErrorNone) { | 237 | if (os_file_exists(test_path, &does_exist) != ErrorNone) { |
| ... | @@ -267,8 +276,7 @@ static void construct_linker_job_elf(LinkJob *lj) { | ... | @@ -267,8 +276,7 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 267 | lj->args.append((const char *)buf_ptr(&lj->out_file_o)); | 276 | lj->args.append((const char *)buf_ptr(&lj->out_file_o)); |
| 268 | 277 | ||
| 269 | if (g->is_test_build) { | 278 | if (g->is_test_build) { |
| 270 | const char *test_runner_name = g->link_libc ? "test_runner_libc" : "test_runner_nolibc"; | 279 | Buf *test_runner_o_path = build_o(g, "test_runner"); |
| 271 | Buf *test_runner_o_path = build_o(g, test_runner_name); | ||
| 272 | lj->args.append(buf_ptr(test_runner_o_path)); | 280 | lj->args.append(buf_ptr(test_runner_o_path)); |
| 273 | } | 281 | } |
| 274 | 282 | ||
| ... | @@ -282,6 +290,9 @@ static void construct_linker_job_elf(LinkJob *lj) { | ... | @@ -282,6 +290,9 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 282 | 290 | ||
| 283 | for (size_t i = 0; i < g->link_libs.length; i += 1) { | 291 | for (size_t i = 0; i < g->link_libs.length; i += 1) { |
| 284 | Buf *link_lib = g->link_libs.at(i); | 292 | Buf *link_lib = g->link_libs.at(i); |
| 293 | if (buf_eql_str(link_lib, "c")) { | ||
| 294 | continue; | ||
| 295 | } | ||
| 285 | Buf *arg; | 296 | Buf *arg; |
| 286 | if (buf_starts_with_str(link_lib, "/") || buf_ends_with_str(link_lib, ".a") || | 297 | if (buf_starts_with_str(link_lib, "/") || buf_ends_with_str(link_lib, ".a") || |
| 287 | buf_ends_with_str(link_lib, ".so")) | 298 | buf_ends_with_str(link_lib, ".so")) |
| ... | @@ -408,8 +419,7 @@ static void construct_linker_job_coff(LinkJob *lj) { | ... | @@ -408,8 +419,7 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 408 | lj->args.append((const char *)buf_ptr(&lj->out_file_o)); | 419 | lj->args.append((const char *)buf_ptr(&lj->out_file_o)); |
| 409 | 420 | ||
| 410 | if (g->is_test_build) { | 421 | if (g->is_test_build) { |
| 411 | const char *test_runner_name = g->link_libc ? "test_runner_libc" : "test_runner_nolibc"; | 422 | Buf *test_runner_o_path = build_o(g, "test_runner"); |
| 412 | Buf *test_runner_o_path = build_o(g, test_runner_name); | ||
| 413 | lj->args.append(buf_ptr(test_runner_o_path)); | 423 | lj->args.append(buf_ptr(test_runner_o_path)); |
| 414 | } | 424 | } |
| 415 | 425 | ||
| ... | @@ -424,6 +434,9 @@ static void construct_linker_job_coff(LinkJob *lj) { | ... | @@ -424,6 +434,9 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 424 | 434 | ||
| 425 | for (size_t i = 0; i < g->link_libs.length; i += 1) { | 435 | for (size_t i = 0; i < g->link_libs.length; i += 1) { |
| 426 | Buf *link_lib = g->link_libs.at(i); | 436 | Buf *link_lib = g->link_libs.at(i); |
| 437 | if (buf_eql_str(link_lib, "c")) { | ||
| 438 | continue; | ||
| 439 | } | ||
| 427 | Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib)); | 440 | Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib)); |
| 428 | lj->args.append(buf_ptr(arg)); | 441 | lj->args.append(buf_ptr(arg)); |
| 429 | } | 442 | } |
| ... | @@ -685,13 +698,15 @@ static void construct_linker_job_macho(LinkJob *lj) { | ... | @@ -685,13 +698,15 @@ static void construct_linker_job_macho(LinkJob *lj) { |
| 685 | lj->args.append((const char *)buf_ptr(&lj->out_file_o)); | 698 | lj->args.append((const char *)buf_ptr(&lj->out_file_o)); |
| 686 | 699 | ||
| 687 | if (g->is_test_build) { | 700 | if (g->is_test_build) { |
| 688 | const char *test_runner_name = g->link_libc ? "test_runner_libc" : "test_runner_nolibc"; | 701 | Buf *test_runner_o_path = build_o(g, "test_runner"); |
| 689 | Buf *test_runner_o_path = build_o(g, test_runner_name); | ||
| 690 | lj->args.append(buf_ptr(test_runner_o_path)); | 702 | lj->args.append(buf_ptr(test_runner_o_path)); |
| 691 | } | 703 | } |
| 692 | 704 | ||
| 693 | for (size_t i = 0; i < g->link_libs.length; i += 1) { | 705 | for (size_t i = 0; i < g->link_libs.length; i += 1) { |
| 694 | Buf *link_lib = g->link_libs.at(i); | 706 | Buf *link_lib = g->link_libs.at(i); |
| 707 | if (buf_eql_str(link_lib, "c")) { | ||
| 708 | continue; | ||
| 709 | } | ||
| 695 | Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib)); | 710 | Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib)); |
| 696 | lj->args.append(buf_ptr(arg)); | 711 | lj->args.append(buf_ptr(arg)); |
| 697 | } | 712 | } |
std/bootstrap.zig+4-5| ... | @@ -1,17 +1,16 @@ | ... | @@ -1,17 +1,16 @@ |
| 1 | // This file is in a package which has the root source file exposed as "@root". | 1 | // This file is in a package which has the root source file exposed as "@root". |
| 2 | // It is included in the compilation unit when exporting an executable. | ||
| 2 | 3 | ||
| 3 | const root = @import("@root"); | 4 | const root = @import("@root"); |
| 4 | const std = @import("std"); | 5 | const std = @import("std"); |
| 5 | 6 | ||
| 6 | const want_start_symbol = switch(@compileVar("os")) { | 7 | const want_main_symbol = std.build.linkingLibrary("c"); |
| 7 | Os.linux => true, | 8 | const want_start_symbol = !want_main_symbol; |
| 8 | else => false, | ||
| 9 | }; | ||
| 10 | const want_main_symbol = !want_start_symbol; | ||
| 11 | 9 | ||
| 12 | const exit = switch(@compileVar("os")) { | 10 | const exit = switch(@compileVar("os")) { |
| 13 | Os.linux => std.linux.exit, | 11 | Os.linux => std.linux.exit, |
| 14 | Os.darwin => std.darwin.exit, | 12 | Os.darwin => std.darwin.exit, |
| 13 | else => @compileError("Unsupported OS"), | ||
| 15 | }; | 14 | }; |
| 16 | 15 | ||
| 17 | var argc: usize = undefined; | 16 | var argc: usize = undefined; |
std/build.zig created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | const mem = @import("mem.zig"); | ||
| 2 | |||
| 3 | pub fn linkingLibrary(lib_name: []const u8) -> bool { | ||
| 4 | // TODO shouldn't need this if | ||
| 5 | if (@compileVar("link_libs").len != 0) { | ||
| 6 | for (@compileVar("link_libs")) |link_lib| { | ||
| 7 | if (mem.eql(u8, link_lib, lib_name)) { | ||
| 8 | return true; | ||
| 9 | } | ||
| 10 | } | ||
| 11 | } | ||
| 12 | return false; | ||
| 13 | } | ||
std/index.zig+1| ... | @@ -1,3 +1,4 @@ | ... | @@ -1,3 +1,4 @@ |
| 1 | pub const build = @import("build.zig"); | ||
| 1 | pub const cstr = @import("cstr.zig"); | 2 | pub const cstr = @import("cstr.zig"); |
| 2 | pub const debug = @import("debug.zig"); | 3 | pub const debug = @import("debug.zig"); |
| 3 | pub const fmt = @import("fmt.zig"); | 4 | pub const fmt = @import("fmt.zig"); |
std/test_runner.zig+1-1| ... | @@ -7,7 +7,7 @@ const TestFn = struct { | ... | @@ -7,7 +7,7 @@ const TestFn = struct { |
| 7 | 7 | ||
| 8 | extern var zig_test_fn_list: []TestFn; | 8 | extern var zig_test_fn_list: []TestFn; |
| 9 | 9 | ||
| 10 | pub fn runTests() -> %void { | 10 | pub fn main(args: [][]u8) -> %void { |
| 11 | for (zig_test_fn_list) |testFn, i| { | 11 | for (zig_test_fn_list) |testFn, i| { |
| 12 | %%io.stderr.printf("Test {}/{} {}...", i + 1, zig_test_fn_list.len, testFn.name); | 12 | %%io.stderr.printf("Test {}/{} {}...", i + 1, zig_test_fn_list.len, testFn.name); |
| 13 | 13 |
std/test_runner_libc.zig deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | const test_runner = @import("test_runner.zig"); | ||
| 2 | |||
| 3 | export fn main(argc: c_int, argv: &&u8) -> c_int { | ||
| 4 | test_runner.runTests() %% return -1; | ||
| 5 | return 0; | ||
| 6 | } | ||
std/test_runner_nolibc.zig deleted-5| ... | @@ -1,5 +0,0 @@ | ||
| 1 | const test_runner = @import("test_runner.zig"); | ||
| 2 | |||
| 3 | pub fn main(args: [][]u8) -> %void { | ||
| 4 | return test_runner.runTests(); | ||
| 5 | } | ||