Commit ba78ae0ae7

Sahnvour <Sahnvour@users.noreply.github.com>
2018-09-30 22:59:45
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
1 parent 418b2e7
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;
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);
         }
     }
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;
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));