authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-23 00:26:12-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-23 00:26:12-04:00
logd8d45908fa6c572c661ba51132da87a3bc10c640
treebe408495a03e5253de2150ccba981de253235f87
parent1c8fee41c247ea60aebd1d8b0fdba4002701b1cf

building with mingw for windows


14 files changed, 126 insertions(+), 44 deletions(-)

CMakeLists.txt+4-1
......@@ -175,7 +175,7 @@ if(MINGW)
175175 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-error=format= -Wno-error=format -Wno-error=format-extra-args")
176176endif()
177177
178set(EXE_CFLAGS "-std=c++11 -fno-exceptions -fno-rtti -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__USE_MINGW_ANSI_STDIO -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces")
178set(EXE_CFLAGS "-std=c++11 -fno-exceptions -fno-rtti -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces")
179179set(EXE_LDFLAGS " ")
180180if(ZIG_TEST_COVERAGE)
181181 set(EXE_CFLAGS "${EXE_CFLAGS} -fprofile-arcs -ftest-coverage")
......@@ -193,6 +193,9 @@ target_link_libraries(zig LINK_PUBLIC
193193 ${LLVM_LIBRARIES}
194194 ${CMAKE_THREAD_LIBS_INIT}
195195)
196if(MINGW)
197 target_link_libraries(zig LINK_PUBLIC version)
198endif()
196199install(TARGETS zig DESTINATION bin)
197200
198201install(FILES ${C_HEADERS} DESTINATION ${C_HEADERS_DEST})
src/analyze.cpp+6-6
......@@ -573,7 +573,7 @@ TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t
573573 entry->is_copyable = false;
574574
575575 buf_resize(&entry->name, 0);
576 buf_appendf(&entry->name, "[%" PRIu64 "]%s", array_size, buf_ptr(&child_type->name));
576 buf_appendf(&entry->name, "[%" ZIG_PRI_u64 "]%s", array_size, buf_ptr(&child_type->name));
577577
578578 if (!entry->zero_bits) {
579579 entry->type_ref = child_type->type_ref ? LLVMArrayType(child_type->type_ref,
......@@ -2756,7 +2756,7 @@ void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entry, Vari
27562756 if (param_decl_node && !is_var_args) {
27572757 param_name = param_decl_node->data.param_decl.name;
27582758 } else {
2759 param_name = buf_sprintf("arg%zu", i);
2759 param_name = buf_sprintf("arg%" ZIG_PRI_usize "", i);
27602760 }
27612761
27622762 TypeTableEntry *param_type = param_info->type;
......@@ -3934,7 +3934,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
39343934 {
39353935 BigNum *bignum = &const_val->data.x_bignum;
39363936 const char *negative_str = bignum->is_negative ? "-" : "";
3937 buf_appendf(buf, "%s%llu", negative_str, bignum->data.x_uint);
3937 buf_appendf(buf, "%s%" ZIG_PRI_llu, negative_str, bignum->data.x_uint);
39383938 return;
39393939 }
39403940 case TypeTableEntryIdMetaType:
......@@ -3945,7 +3945,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
39453945 BigNum *bignum = &const_val->data.x_bignum;
39463946 assert(bignum->kind == BigNumKindInt);
39473947 const char *negative_str = bignum->is_negative ? "-" : "";
3948 buf_appendf(buf, "%s%llu", negative_str, bignum->data.x_uint);
3948 buf_appendf(buf, "%s%" ZIG_PRI_llu, negative_str, bignum->data.x_uint);
39493949 }
39503950 return;
39513951 case TypeTableEntryIdFloat:
......@@ -3983,7 +3983,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
39833983 return;
39843984 }
39853985 case ConstPtrSpecialHardCodedAddr:
3986 buf_appendf(buf, "(&%s)(%" PRIx64 ")", buf_ptr(&type_entry->data.pointer.child_type->name),
3986 buf_appendf(buf, "(&%s)(%" ZIG_PRI_x64 ")", buf_ptr(&type_entry->data.pointer.child_type->name),
39873987 const_val->data.x_ptr.data.hard_coded_addr.addr);
39883988 return;
39893989 case ConstPtrSpecialDiscard:
......@@ -4000,7 +4000,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
40004000 case TypeTableEntryIdBlock:
40014001 {
40024002 AstNode *node = const_val->data.x_block->source_node;
4003 buf_appendf(buf, "(scope:%zu:%zu)", node->line + 1, node->column + 1);
4003 buf_appendf(buf, "(scope:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", node->line + 1, node->column + 1);
40044004 return;
40054005 }
40064006 case TypeTableEntryIdArray:
src/ast_render.cpp+4-3
......@@ -5,8 +5,9 @@
55 * See http://opensource.org/licenses/MIT
66 */
77
8#include "ast_render.hpp"
98#include "analyze.hpp"
9#include "ast_render.hpp"
10#include "os.hpp"
1011
1112#include <stdio.h>
1213
......@@ -529,7 +530,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
529530 case BigNumKindInt:
530531 {
531532 const char *negative_str = node->data.number_literal.bignum->is_negative ? "-" : "";
532 fprintf(ar->f, "%s%llu", negative_str, node->data.number_literal.bignum->data.x_uint);
533 fprintf(ar->f, "%s%" ZIG_PRI_llu, negative_str, node->data.number_literal.bignum->data.x_uint);
533534 }
534535 break;
535536 case BigNumKindFloat:
......@@ -962,7 +963,7 @@ static void ast_render_tld_fn(AstRender *ar, Buf *name, TldFn *tld_fn) {
962963 if (param_info->is_noalias) {
963964 fprintf(ar->f, "noalias ");
964965 }
965 Buf *param_name = tld_fn->fn_entry->param_names ? tld_fn->fn_entry->param_names[i] : buf_sprintf("arg%zu", i);
966 Buf *param_name = tld_fn->fn_entry->param_names ? tld_fn->fn_entry->param_names[i] : buf_sprintf("arg%" ZIG_PRI_usize "", i);
966967 fprintf(ar->f, "%s: %s", buf_ptr(param_name), buf_ptr(&param_info->type->name));
967968 }
968969 if (fn_type_id->return_type->id == TypeTableEntryIdVoid) {
src/bignum.cpp+2-1
......@@ -7,6 +7,7 @@
77
88#include "bignum.hpp"
99#include "buffer.hpp"
10#include "os.hpp"
1011
1112#include <assert.h>
1213#include <math.h>
......@@ -350,7 +351,7 @@ Buf *bignum_to_buf(BigNum *bn) {
350351 return buf_sprintf("%f", bn->data.x_float);
351352 } else {
352353 const char *neg = bn->is_negative ? "-" : "";
353 return buf_sprintf("%s%llu", neg, bn->data.x_uint);
354 return buf_sprintf("%s%" ZIG_PRI_llu "", neg, bn->data.x_uint);
354355 }
355356}
356357
src/codegen.cpp+2-2
......@@ -559,7 +559,7 @@ static LLVMValueRef get_floor_ceil_fn(CodeGen *g, TypeTableEntry *type_entry, Zi
559559 }
560560
561561 char fn_name[64];
562 sprintf(fn_name, "llvm.%s.f%zu", name, type_entry->data.floating.bit_count);
562 sprintf(fn_name, "llvm.%s.f%" ZIG_PRI_usize "", name, type_entry->data.floating.bit_count);
563563 LLVMTypeRef fn_type = LLVMFunctionType(type_entry->type_ref, &type_entry->type_ref, 1, false);
564564 LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type);
565565
......@@ -2166,7 +2166,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
21662166 {
21672167 size_t index = find_asm_index(g, asm_node, asm_token);
21682168 assert(index < SIZE_MAX);
2169 buf_appendf(&llvm_template, "$%zu", index);
2169 buf_appendf(&llvm_template, "$%" ZIG_PRI_usize "", index);
21702170 break;
21712171 }
21722172 case AsmTokenIdUniqueId:
src/errmsg.cpp+4-4
......@@ -30,9 +30,9 @@ static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type)
3030
3131 if (color == ErrColorOn || (color == ErrColorAuto && os_stderr_tty())) {
3232 if (err_type == ErrTypeError) {
33 fprintf(stderr, WHITE "%s:%zu:%zu: " RED "error:" WHITE " %s" RESET "\n", path, line, col, text);
33 fprintf(stderr, WHITE "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": " RED "error:" WHITE " %s" RESET "\n", path, line, col, text);
3434 } else if (err_type == ErrTypeNote) {
35 fprintf(stderr, WHITE "%s:%zu:%zu: " CYAN "note:" WHITE " %s" RESET "\n", path, line, col, text);
35 fprintf(stderr, WHITE "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": " CYAN "note:" WHITE " %s" RESET "\n", path, line, col, text);
3636 } else {
3737 zig_unreachable();
3838 }
......@@ -44,9 +44,9 @@ static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type)
4444 fprintf(stderr, GREEN "^" RESET "\n");
4545 } else {
4646 if (err_type == ErrTypeError) {
47 fprintf(stderr, "%s:%zu:%zu: error: %s\n", path, line, col, text);
47 fprintf(stderr, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": error: %s\n", path, line, col, text);
4848 } else if (err_type == ErrTypeNote) {
49 fprintf(stderr, " %s:%zu:%zu: note: %s\n", path, line, col, text);
49 fprintf(stderr, " %s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": note: %s\n", path, line, col, text);
5050 } else {
5151 zig_unreachable();
5252 }
src/ir.cpp+11-11
......@@ -3815,7 +3815,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
38153815
38163816 if (builtin_fn->param_count != SIZE_MAX && builtin_fn->param_count != actual_param_count) {
38173817 add_node_error(irb->codegen, node,
3818 buf_sprintf("expected %zu arguments, found %zu",
3818 buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize,
38193819 builtin_fn->param_count, actual_param_count));
38203820 return irb->codegen->invalid_instruction;
38213821 }
......@@ -5810,7 +5810,7 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,
58105810 render_instance_name_recursive(irb->codegen, name, &fn_entry->fndef_scope->base, irb->exec->begin_scope);
58115811 buf_appendf(name, ")");
58125812 } else {
5813 name = buf_sprintf("(anonymous %s at %s:%zu:%zu)", container_string(kind),
5813 name = buf_sprintf("(anonymous %s at %s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", container_string(kind),
58145814 buf_ptr(node->owner->path), node->line + 1, node->column + 1);
58155815 }
58165816 }
......@@ -6681,7 +6681,7 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru
66816681
66826682 *bbc += 1;
66836683 if (*bbc > quota) {
6684 ir_add_error(ira, source_instruction, buf_sprintf("evaluation exceeded %zu backwards branches", quota));
6684 ir_add_error(ira, source_instruction, buf_sprintf("evaluation exceeded %" ZIG_PRI_usize " backwards branches", quota));
66856685 return false;
66866686 }
66876687 return true;
......@@ -7236,7 +7236,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
72367236 uint64_t index = val->data.x_bignum.data.x_uint;
72377237 if (index == 0 || index >= ira->codegen->error_decls.length) {
72387238 ir_add_error(ira, source_instr,
7239 buf_sprintf("integer value %" PRIu64 " represents no error", index));
7239 buf_sprintf("integer value %" ZIG_PRI_u64 " represents no error", index));
72407240 return ira->codegen->invalid_instruction;
72417241 }
72427242
......@@ -8949,7 +8949,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
89498949 if (fn_type_id->is_var_args) {
89508950 if (call_param_count < src_param_count) {
89518951 ErrorMsg *msg = ir_add_error_node(ira, source_node,
8952 buf_sprintf("expected at least %zu arguments, found %zu", src_param_count, call_param_count));
8952 buf_sprintf("expected at least %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize "", src_param_count, call_param_count));
89538953 if (fn_proto_node) {
89548954 add_error_note(ira->codegen, msg, fn_proto_node,
89558955 buf_sprintf("declared here"));
......@@ -8958,7 +8958,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
89588958 }
89598959 } else if (src_param_count != call_param_count) {
89608960 ErrorMsg *msg = ir_add_error_node(ira, source_node,
8961 buf_sprintf("expected %zu arguments, found %zu", src_param_count, call_param_count));
8961 buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize "", src_param_count, call_param_count));
89628962 if (fn_proto_node) {
89638963 add_error_note(ira->codegen, msg, fn_proto_node,
89648964 buf_sprintf("declared here"));
......@@ -9784,7 +9784,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
97849784 size_t len = end - start;
97859785 if (index >= len) {
97869786 ir_add_error(ira, &elem_ptr_instruction->base,
9787 buf_sprintf("index %zu outside argument list of size %zu", index, len));
9787 buf_sprintf("index %" ZIG_PRI_usize " outside argument list of size %" ZIG_PRI_usize "", index, len));
97889788 return ira->codegen->builtin_types.entry_invalid;
97899789 }
97909790 size_t abs_index = start + index;
......@@ -9818,7 +9818,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
98189818 uint64_t array_len = array_type->data.array.len;
98199819 if (index >= array_len) {
98209820 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
9821 buf_sprintf("index %" PRIu64 " outside array of size %" PRIu64,
9821 buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64,
98229822 index, array_len));
98239823 return ira->codegen->builtin_types.entry_invalid;
98249824 }
......@@ -9876,7 +9876,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
98769876 }
98779877 if (new_index >= mem_size) {
98789878 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
9879 buf_sprintf("index %" PRIu64 " outside pointer of size %zu", index, old_size));
9879 buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size));
98809880 return ira->codegen->builtin_types.entry_invalid;
98819881 }
98829882 } else if (is_slice(array_type)) {
......@@ -9885,7 +9885,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
98859885 uint64_t slice_len = len_field->data.x_bignum.data.x_uint;
98869886 if (index >= slice_len) {
98879887 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
9888 buf_sprintf("index %" PRIu64 " outside slice of size %" PRIu64,
9888 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,
98899889 index, slice_len));
98909890 return ira->codegen->builtin_types.entry_invalid;
98919891 }
......@@ -11986,7 +11986,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1198611986 size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index;
1198711987 if (ptr_field_index != field->src_index) {
1198811988 ir_add_error(ira, &instruction->base,
11989 buf_sprintf("field '%s' has index %zu but pointer value is index %zu of struct '%s'",
11989 buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'",
1199011990 buf_ptr(field->name), field->src_index,
1199111991 ptr_field_index, buf_ptr(&container_type->name)));
1199211992 return ira->codegen->builtin_types.entry_invalid;
src/ir_print.cpp+6-5
......@@ -8,6 +8,7 @@
88#include "analyze.hpp"
99#include "ir.hpp"
1010#include "ir_print.hpp"
11#include "os.hpp"
1112
1213struct IrPrint {
1314 CodeGen *codegen;
......@@ -28,7 +29,7 @@ static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction) {
2829 ir_print_indent(irp);
2930 const char *type_name = instruction->value.type ? buf_ptr(&instruction->value.type->name) : "(unknown)";
3031 const char *ref_count = ir_has_side_effects(instruction) ?
31 "-" : buf_ptr(buf_sprintf("%zu", instruction->ref_count));
32 "-" : buf_ptr(buf_sprintf("%" ZIG_PRI_usize "", instruction->ref_count));
3233 fprintf(irp->f, "#%-3zu| %-12s| %-2s| ", instruction->debug_id, type_name, ref_count);
3334}
3435
......@@ -40,7 +41,7 @@ static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) {
4041}
4142
4243static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) {
43 fprintf(irp->f, "#%zu", instruction->debug_id);
44 fprintf(irp->f, "#%" ZIG_PRI_usize "", instruction->debug_id);
4445}
4546
4647static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction) {
......@@ -52,7 +53,7 @@ static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction)
5253}
5354
5455static void ir_print_other_block(IrPrint *irp, IrBasicBlock *bb) {
55 fprintf(irp->f, "$%s_%zu", bb->name_hint, bb->debug_id);
56 fprintf(irp->f, "$%s_%" ZIG_PRI_usize "", bb->name_hint, bb->debug_id);
5657}
5758
5859static void ir_print_return(IrPrint *irp, IrInstructionReturn *return_instruction) {
......@@ -245,7 +246,7 @@ static void ir_print_container_init_list(IrPrint *irp, IrInstructionContainerIni
245246 ir_print_other_instruction(irp, instruction->container_type);
246247 fprintf(irp->f, "{");
247248 if (instruction->item_count > 50) {
248 fprintf(irp->f, "...(%zu items)...", instruction->item_count);
249 fprintf(irp->f, "...(%" ZIG_PRI_usize " items)...", instruction->item_count);
249250 } else {
250251 for (size_t i = 0; i < instruction->item_count; i += 1) {
251252 IrInstruction *item = instruction->items[i];
......@@ -1194,7 +1195,7 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si
11941195
11951196 for (size_t bb_i = 0; bb_i < executable->basic_block_list.length; bb_i += 1) {
11961197 IrBasicBlock *current_block = executable->basic_block_list.at(bb_i);
1197 fprintf(irp->f, "%s_%zu:\n", current_block->name_hint, current_block->debug_id);
1198 fprintf(irp->f, "%s_%" ZIG_PRI_usize ":\n", current_block->name_hint, current_block->debug_id);
11981199 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
11991200 IrInstruction *instruction = current_block->instruction_list.at(instr_i);
12001201 ir_print_instruction(irp, instruction);
src/link.cpp+2-2
......@@ -184,10 +184,10 @@ static void construct_linker_job_elf(LinkJob *lj) {
184184 lj->args.append("-shared");
185185
186186 if (buf_len(&lj->out_file) == 0) {
187 buf_appendf(&lj->out_file, "lib%s.so.%zu.%zu.%zu",
187 buf_appendf(&lj->out_file, "lib%s.so.%" ZIG_PRI_usize ".%" ZIG_PRI_usize ".%" ZIG_PRI_usize "",
188188 buf_ptr(g->root_out_name), g->version_major, g->version_minor, g->version_patch);
189189 }
190 soname = buf_sprintf("lib%s.so.%zu", buf_ptr(g->root_out_name), g->version_major);
190 soname = buf_sprintf("lib%s.so.%" ZIG_PRI_usize "", buf_ptr(g->root_out_name), g->version_major);
191191 }
192192
193193 lj->args.append("-o");
src/os.cpp+54-7
......@@ -10,7 +10,6 @@
1010#include "error.hpp"
1111
1212#if defined(_WIN32)
13#define ZIG_OS_WINDOWS
1413
1514#if !defined(NOMINMAX)
1615#define NOMINMAX
......@@ -38,11 +37,18 @@
3837
3938#endif
4039
40
4141#if defined(__MACH__)
4242#include <mach/clock.h>
4343#include <mach/mach.h>
4444#endif
4545
46#if defined(ZIG_OS_WINDOWS)
47static double win32_time_resolution;
48#elif defined(__MACH__)
49static clock_serv_t cclock;
50#endif
51
4652#include <stdlib.h>
4753#include <errno.h>
4854#include <time.h>
......@@ -118,16 +124,24 @@ void os_path_dirname(Buf *full_path, Buf *out_dirname) {
118124 return os_path_split(full_path, out_dirname, nullptr);
119125}
120126
127bool os_is_sep(uint8_t c) {
128#if defined(ZIG_OS_WINDOWS)
129 return c == '\\' || c == '/';
130#else
131 return c == '/';
132#endif
133}
134
121135void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename) {
122136 size_t len = buf_len(full_path);
123137 if (len != 0) {
124138 size_t last_index = len - 1;
125 if (buf_ptr(full_path)[last_index] == '/') {
139 if (os_is_sep(buf_ptr(full_path)[last_index])) {
126140 last_index -= 1;
127141 }
128142 for (size_t i = last_index;;) {
129143 uint8_t c = buf_ptr(full_path)[i];
130 if (c == '/') {
144 if (os_is_sep(c)) {
131145 if (out_dirname) {
132146 buf_init_from_mem(out_dirname, buf_ptr(full_path), i);
133147 }
......@@ -177,7 +191,7 @@ void os_path_extname(Buf *full_path, Buf *out_basename, Buf *out_extname) {
177191void os_path_join(Buf *dirname, Buf *basename, Buf *out_full_path) {
178192 buf_init_from_buf(out_full_path, dirname);
179193 uint8_t c = *(buf_ptr(out_full_path) + buf_len(out_full_path) - 1);
180 if (c != '/')
194 if (!os_is_sep(c))
181195 buf_append_char(out_full_path, '/');
182196 buf_append_buf(out_full_path, basename);
183197}
......@@ -214,7 +228,13 @@ int os_path_real(Buf *rel_path, Buf *out_abs_path) {
214228
215229bool os_path_is_absolute(Buf *path) {
216230#if defined(ZIG_OS_WINDOWS)
217#error "missing os_path_is_absolute implementation"
231 if (buf_starts_with_str(path, "/") || buf_starts_with_str(path, "\\"))
232 return true;
233
234 if (buf_len(path) >= 3 && buf_ptr(path)[1] == ':')
235 return true;
236
237 return false;
218238#elif defined(ZIG_OS_POSIX)
219239 return buf_ptr(path)[0] == '/';
220240#else
......@@ -258,7 +278,7 @@ int os_file_exists(Buf *full_path, bool *result) {
258278 *result = access(buf_ptr(full_path), F_OK) != -1;
259279 return 0;
260280#else
261 zig_panic("TODO implement os_file_exists for non-posix");
281 return GetFileAttributes(buf_ptr(full_path)) != INVALID_FILE_ATTRIBUTES;
262282#endif
263283}
264284
......@@ -465,7 +485,7 @@ static int os_exec_process_windows(const char *exe, ZigList<const char *> &args,
465485 if (!GetExitCodeProcess(piProcInfo.hProcess, &exit_code)) {
466486 zig_panic("GetExitCodeProcess failed");
467487 }
468 term->how == TerminationIdClean;
488 term->how = TerminationIdClean;
469489 term->code = exit_code;
470490
471491 CloseHandle(piProcInfo.hProcess);
......@@ -760,6 +780,18 @@ int os_make_path(Buf *path) {
760780}
761781
762782int os_make_dir(Buf *path) {
783#if defined(ZIG_OS_WINDOWS)
784 if (mkdir(buf_ptr(path)) == -1) {
785 if (errno == EEXIST)
786 return ErrorPathAlreadyExists;
787 if (errno == ENOENT)
788 return ErrorFileNotFound;
789 if (errno == EACCES)
790 return ErrorAccess;
791 return ErrorUnexpected;
792 }
793 return 0;
794#else
763795 if (mkdir(buf_ptr(path), 0755) == -1) {
764796 if (errno == EEXIST)
765797 return ErrorPathAlreadyExists;
......@@ -770,4 +802,19 @@ int os_make_dir(Buf *path) {
770802 return ErrorUnexpected;
771803 }
772804 return 0;
805#endif
806}
807
808int zig_os_init(void) {
809#if defined(ZIG_OS_WINDOWS)
810 unsigned __int64 frequency;
811 if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency)) {
812 win32_time_resolution = 1.0 / (double) frequency;
813 } else {
814 return ErrorSystemResources;
815 }
816#elif defined(__MACH__)
817 host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
818#endif
819 return 0;
773820}
src/os.hpp+14
......@@ -61,6 +61,8 @@ int os_file_exists(Buf *full_path, bool *result);
6161int os_rename(Buf *src_path, Buf *dest_path);
6262double os_get_time(void);
6363
64bool os_is_sep(uint8_t c);
65
6466#if defined(__APPLE__)
6567#define ZIG_OS_DARWIN
6668#elif defined(_WIN32)
......@@ -77,4 +79,16 @@ double os_get_time(void);
7779#define ZIG_ARCH_UNKNOWN
7880#endif
7981
82#if defined(ZIG_OS_WINDOWS)
83#define ZIG_PRI_usize "Iu"
84#define ZIG_PRI_u64 "I64u"
85#define ZIG_PRI_llu "I64u"
86#define ZIG_PRI_x64 "I64x"
87#else
88#define ZIG_PRI_usize "zu"
89#define ZIG_PRI_u64 PRIu64
90#define ZIG_PRI_llu "llu"
91#define ZIG_PRI_x64 PRIx64
92#endif
93
8094#endif
src/parseh.cpp+1-1
......@@ -628,7 +628,7 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
628628 const ParmVarDecl *param = fn_decl->getParamDecl(i);
629629 const char *name = decl_name(param);
630630 if (strlen(name) == 0) {
631 name_buf = buf_sprintf("arg%zu", i);
631 name_buf = buf_sprintf("arg%" ZIG_PRI_usize "", i);
632632 } else {
633633 name_buf = buf_create_from_str(name);
634634 }
src/target.cpp+1-1
......@@ -529,7 +529,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
529529}
530530
531531const char *target_o_file_ext(ZigTarget *target) {
532 if (target->env_type == ZigLLVM_MSVC) {
532 if (target->env_type == ZigLLVM_MSVC || target->os == ZigLLVM_Win32) {
533533 return ".obj";
534534 } else {
535535 return ".o";
std/os/path.zig+15
......@@ -81,6 +81,9 @@ pub fn resolve(allocator: &Allocator, args: ...) -> %[]u8 {
8181}
8282
8383pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {
84 if (builtin.os == builtin.Os.windows) {
85 @compileError("TODO implement os.path.resolve for windows");
86 }
8487 if (paths.len == 0)
8588 return os.getCwd(allocator);
8689
......@@ -152,6 +155,9 @@ fn testResolve(args: ...) -> []u8 {
152155}
153156
154157pub fn dirname(path: []const u8) -> []const u8 {
158 if (builtin.os == builtin.Os.windows) {
159 @compileError("TODO implement os.path.dirname for windows");
160 }
155161 if (path.len == 0)
156162 return path[0..0];
157163 var end_index: usize = path.len - 1;
......@@ -189,6 +195,9 @@ fn testDirname(input: []const u8, expected_output: []const u8) {
189195}
190196
191197pub fn basename(path: []const u8) -> []const u8 {
198 if (builtin.os == builtin.Os.windows) {
199 @compileError("TODO implement os.path.basename for windows");
200 }
192201 if (path.len == 0)
193202 return []u8{};
194203
......@@ -231,6 +240,9 @@ fn testBasename(input: []const u8, expected_output: []const u8) {
231240/// resolve to the same path (after calling ::resolve on each), a zero-length
232241/// string is returned.
233242pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u8 {
243 if (builtin.os == builtin.Os.windows) {
244 @compileError("TODO implement os.path.relative for windows");
245 }
234246 const resolved_from = %return resolve(allocator, from);
235247 defer allocator.free(resolved_from);
236248
......@@ -299,6 +311,9 @@ fn testRelative(from: []const u8, to: []const u8, expected_output: []const u8) {
299311/// extra `/` characters in ::pathname.
300312/// Caller must deallocate result.
301313pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
314 if (builtin.os == builtin.Os.windows) {
315 @compileError("TODO implement os.path.real for windows");
316 }
302317 const fd = %return os.posixOpen(pathname, posix.O_PATH|posix.O_NONBLOCK|posix.O_CLOEXEC, 0, allocator);
303318 defer os.posixClose(fd);
304319