Commit 021155db5b

Andrew Kelley <superjoe30@gmail.com>
2017-08-30 23:01:14
successfully cross-building behavior tests for windows
1 parent 41da9fd
Changed files (4)
src/codegen.cpp
@@ -4914,6 +4914,12 @@ static void define_builtin_compile_vars(CodeGen *g) {
 static void init(CodeGen *g) {
     if (g->module)
         return;
+
+    if (g->is_test_build) {
+        g->windows_subsystem_windows = false;
+        g->windows_subsystem_console = true;
+    }
+
     assert(g->root_out_name);
     g->module = LLVMModuleCreateWithName(buf_ptr(g->root_out_name));
 
src/ir_print.cpp
@@ -934,7 +934,11 @@ static void ir_print_set_eval_branch_quota(IrPrint *irp, IrInstructionSetEvalBra
 
 static void ir_print_align_cast(IrPrint *irp, IrInstructionAlignCast *instruction) {
     fprintf(irp->f, "@alignCast(");
-    ir_print_other_instruction(irp, instruction->align_bytes);
+    if (instruction->align_bytes == nullptr) {
+        fprintf(irp->f, "null");
+    } else {
+        ir_print_other_instruction(irp, instruction->align_bytes);
+    }
     fprintf(irp->f, ",");
     ir_print_other_instruction(irp, instruction->target);
     fprintf(irp->f, ")");
src/link.cpp
@@ -336,6 +336,16 @@ static bool is_target_cyg_mingw(const ZigTarget *target) {
         (target->os == ZigLLVM_Win32 && target->env_type == ZigLLVM_GNU);
 }
 
+static void coff_append_machine_arg(CodeGen *g, ZigList<const char *> *list) {
+    if (g->zig_target.arch.arch == ZigLLVM_x86) {
+        list->append("-MACHINE:X86");
+    } else if (g->zig_target.arch.arch == ZigLLVM_x86_64) {
+        list->append("-MACHINE:X64");
+    } else if (g->zig_target.arch.arch == ZigLLVM_arm) {
+        list->append("-MACHINE:ARM");
+    }
+}
+
 static void construct_linker_job_coff(LinkJob *lj) {
     CodeGen *g = lj->codegen;
 
@@ -345,13 +355,7 @@ static void construct_linker_job_coff(LinkJob *lj) {
 
     lj->args.append("-NOLOGO");
 
-    if (g->zig_target.arch.arch == ZigLLVM_x86) {
-        lj->args.append("-MACHINE:X86");
-    } else if (g->zig_target.arch.arch == ZigLLVM_x86_64) {
-        lj->args.append("-MACHINE:X64");
-    } else if (g->zig_target.arch.arch == ZigLLVM_arm) {
-        lj->args.append("-MACHINE:ARM");
-    }
+    coff_append_machine_arg(g, &lj->args);
 
     if (g->windows_subsystem_windows) {
         lj->args.append("/SUBSYSTEM:windows");
@@ -453,6 +457,8 @@ static void construct_linker_job_coff(LinkJob *lj) {
 
         ZigList<const char *> args = {0};
         args.append("link");
+
+        coff_append_machine_arg(g, &args);
         args.append(buf_ptr(buf_sprintf("-DEF:%s", buf_ptr(def_path))));
         args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(all_lib_path))));
         Buf diag = BUF_INIT;
std/os/index.zig
@@ -210,7 +210,7 @@ pub fn windowsIsTty(handle: windows.HANDLE) -> bool {
 
 pub fn windowsIsCygwinPty(handle: windows.HANDLE) -> bool {
     const size = @sizeOf(windows.FILE_NAME_INFO);
-    var name_info_bytes = []u8{0} ** (size + windows.MAX_PATH);
+    var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH);
 
     if (!windows.GetFileInformationByHandleEx(handle, windows.FileNameInfo,
         @ptrCast(&c_void, &name_info_bytes[0]), u32(name_info_bytes.len)))