From ba78ae0ae73ac38a2bb32c618cd145b4d2f9602e Mon Sep 17 00:00:00 2001 From: Sahnvour Date: Sun, 30 Sep 2018 22:59:45 +0200 Subject: [PATCH] Fixes --emit asm on windows and makes C header file generation explicit. (#1612) * build: only do codegen_link when emitting an actual binary. Fixes #1371 * build: only output C header file when explicitely asked to --- src/all_types.hpp | 1 - src/codegen.cpp | 16 ++-------------- src/link.cpp | 2 +- src/main.cpp | 4 ++-- 4 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/all_types.hpp b/src/all_types.hpp index 89c117ce82..30d941354a 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1713,7 +1713,6 @@ struct CodeGen { uint32_t target_environ_index; uint32_t target_oformat_index; bool is_big_endian; - bool want_h_file; bool have_pub_main; bool have_c_main; bool have_winmain; diff --git a/src/codegen.cpp b/src/codegen.cpp index 70310641c4..de69b53388 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -118,7 +118,6 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out g->string_literals_table.init(16); g->type_info_cache.init(32); g->is_test_build = false; - g->want_h_file = (out_type == OutTypeObj || out_type == OutTypeLib); buf_resize(&g->global_asm, 0); for (size_t i = 0; i < array_length(symbols_that_llvm_depends_on); i += 1) { @@ -8127,17 +8126,6 @@ static void resolve_out_paths(CodeGen *g) { } else { zig_unreachable(); } - - if (g->want_h_file && !g->out_h_path) { - assert(g->root_out_name); - Buf *h_basename = buf_sprintf("%s.h", buf_ptr(g->root_out_name)); - if (g->enable_cache) { - g->out_h_path = buf_alloc(); - os_path_join(&g->artifact_dir, h_basename, g->out_h_path); - } else { - g->out_h_path = h_basename; - } - } } @@ -8193,11 +8181,11 @@ void codegen_build_and_link(CodeGen *g) { codegen_add_time_event(g, "LLVM Emit Output"); zig_llvm_emit_output(g); - if (g->want_h_file) { + if (g->out_h_path != nullptr) { codegen_add_time_event(g, "Generate .h"); gen_h_file(g); } - if (g->out_type != OutTypeObj) { + if (g->out_type != OutTypeObj && g->emit_file_type == EmitFileTypeBinary) { codegen_link(g); } } diff --git a/src/link.cpp b/src/link.cpp index aa0edde61b..a280c31f74 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -34,7 +34,7 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) CodeGen *child_gen = codegen_create(full_path, child_target, OutTypeObj, parent_gen->build_mode, parent_gen->zig_lib_dir); - child_gen->want_h_file = false; + child_gen->out_h_path = nullptr; child_gen->verbose_tokenize = parent_gen->verbose_tokenize; child_gen->verbose_ast = parent_gen->verbose_ast; child_gen->verbose_link = parent_gen->verbose_link; diff --git a/src/main.cpp b/src/main.cpp index 5c1e107362..f9df802cb3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,7 +52,7 @@ static int print_full_usage(const char *arg0) { " --libc-include-dir [path] directory where libc stdlib.h resides\n" " --name [name] override output name\n" " --output [file] override destination path\n" - " --output-h [file] override generated header file path\n" + " --output-h [file] generate header file\n" " --pkg-begin [name] [path] make pkg available to import and push current pkg\n" " --pkg-end pop current pkg\n" " --release-fast build with optimizations on and safety off\n" @@ -926,7 +926,7 @@ int main(int argc, char **argv) { if (out_file) codegen_set_output_path(g, buf_create_from_str(out_file)); - if (out_file_h) + if (out_file_h != nullptr && (out_type == OutTypeObj || out_type == OutTypeLib)) codegen_set_output_h_path(g, buf_create_from_str(out_file_h));