diff --git a/bootstrap/Compilation.zig b/bootstrap/Compilation.zig index 0fc8add..001851e 100644 --- a/bootstrap/Compilation.zig +++ b/bootstrap/Compilation.zig @@ -49,7 +49,7 @@ const SliceField = enum { const length_field_name = @tagName(SliceField.length); -const Optimization = enum{ +const Optimization = enum { none, debug_prefer_fast, debug_prefer_size, @@ -2769,6 +2769,7 @@ const Arch = enum { const Os = enum { linux, macos, + windows, }; const Abi = enum { @@ -2795,6 +2796,11 @@ pub fn buildExecutable(context: *const Context, arguments: []const []const u8, o os = .macos; abi = .none; }, + .windows => { + arch = .x86_64; + os = .windows; + abi = .gnu; + }, else => unreachable, } @@ -2983,6 +2989,7 @@ pub fn buildExecutable(context: *const Context, arguments: []const []const u8, o .link_libc = switch (os) { .linux => link_libc, .macos => true, + .windows => link_libc, // .windows => link_libc, // else => unreachable, }, @@ -3066,7 +3073,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, return_ write(.panic, "\nPANIC: ") catch {}; write(.panic, message) catch {}; write(.panic, "\n") catch {}; - @breakpoint(); + if (@import("builtin").os.tag != .windows) @breakpoint(); std.posix.abort(); }, } @@ -3277,7 +3284,7 @@ pub const Type = union(enum) { polymorphic: Type.Polymorphic, pub const @"usize" = _usize; - pub const @"ssize" = _ssize; + pub const ssize = _ssize; pub const Polymorphic = struct { parameters: []const Token.Index, @@ -8787,7 +8794,6 @@ pub const Builder = struct { const phi = &unit.instructions.get(builder.return_phi).phi; - switch (return_type.*) { .void => unreachable, .noreturn => unreachable, @@ -9651,7 +9657,7 @@ pub const Builder = struct { .runtime = block_i, }, .type = if (type_expect == .none or type_expect.type == .void) .void else b: { - assert(unit.basic_blocks.get( builder.current_basic_block).terminated); + assert(unit.basic_blocks.get(builder.current_basic_block).terminated); break :b .noreturn; }, }; @@ -13219,7 +13225,7 @@ pub const Builder = struct { switch (boolean_value) { .bool => |case_boolean| { if (case_boolean == boolean) { - const v = try builder.resolveRuntimeValue(unit, context, Type.Expect{ .type = .void }, case_node.right, .right); + const v = try builder.resolveRuntimeValue(unit, context, Type.Expect{ .type = .void }, case_node.right, .right); switch (v.type) { .void, .noreturn => break, else => @panic("Unexpected type"), @@ -13535,7 +13541,7 @@ pub const Builder = struct { _ = try builder.resolveRuntimeValue(unit, context, Type.Expect{ .type = .void }, body_node_index, .right); const else_node_index = for_expressions.right; - if (else_node_index != .null) { + if (else_node_index != .null) { unreachable; } @@ -15003,7 +15009,7 @@ pub const Builder = struct { .fields = fields, .type = return_type_index, }); - + break :b V{ .type = return_type_index, .value = .{ @@ -16724,5 +16730,3 @@ pub fn write(kind: LogKind, string: []const u8) !void { try std.io.getStdOut().writeAll(string); } } - - diff --git a/bootstrap/backend/llvm.zig b/bootstrap/backend/llvm.zig index e04a9fc..12489d0 100644 --- a/bootstrap/backend/llvm.zig +++ b/bootstrap/backend/llvm.zig @@ -53,7 +53,7 @@ pub const LLVM = struct { tag_count: c_uint = 0, inside_branch: bool = false, - pub const x86_64 = struct{ + pub const x86_64 = struct { pub const initializeTarget = bindings.LLVMInitializeX86Target; pub const initializeTargetInfo = bindings.LLVMInitializeX86TargetInfo; pub const initializeTargetMC = bindings.LLVMInitializeX86TargetMC; @@ -61,7 +61,7 @@ pub const LLVM = struct { pub const initializeAsmParser = bindings.LLVMInitializeX86AsmParser; }; - pub const aarch64 = struct{ + pub const aarch64 = struct { pub const initializeTarget = bindings.LLVMInitializeAArch64Target; pub const initializeTargetInfo = bindings.LLVMInitializeAArch64TargetInfo; pub const initializeTargetMC = bindings.LLVMInitializeAArch64TargetMC; @@ -499,7 +499,7 @@ pub const LLVM = struct { aggressive = 3, }; - pub const OptimizationLevel = extern struct{ + pub const OptimizationLevel = extern struct { speed_level: c_uint, size_level: c_uint, }; @@ -2116,7 +2116,7 @@ pub const LLVM = struct { switch (abi_ty.*) { .@"struct" => |struct_index| switch (unit.structs.get(struct_index).kind) { .raw_error_union => |err_union_base_type| { - const field_types = [2]Compilation.Type.Index{err_union_base_type, .bool }; + const field_types = [2]Compilation.Type.Index{ err_union_base_type, .bool }; for (field_types, constant_struct.fields) |field_type_index, field_value| { const constant = try llvm.emitComptimeRightValue(unit, context, field_value, field_type_index); field_values.append_with_capacity(constant); @@ -2363,7 +2363,6 @@ pub const LLVM = struct { .function_definition => {}, else => |t| @panic(@tagName(t)), } - } }; @@ -3247,13 +3246,14 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo arch.initializeTargetMC(); arch.initializeAsmPrinter(); arch.initializeAsmParser(); - } + }, } // TODO: proper target selection const target_triple = switch (unit.descriptor.os) { .linux => "x86_64-linux-none", .macos => "aarch64-apple-macosx-none", + .windows => "x86_64-windows-gnu", }; const cpu = "generic"; const features = ""; diff --git a/build.zig b/build.zig index d698be6..32c6b2f 100644 --- a/build.zig +++ b/build.zig @@ -23,12 +23,13 @@ pub fn build(b: *std.Build) !void { const self_hosted_ci = b.option(bool, "self_hosted_ci", "This option enables the self-hosted CI behavior") orelse false; const third_party_ci = b.option(bool, "third_party_ci", "This option enables the third-party CI behavior") orelse false; const is_ci = self_hosted_ci or third_party_ci; - const print_stack_trace = b.option(bool, "print_stack_trace", "This option enables printing stack traces inside the compiler") orelse is_ci or os == .macos; + const print_stack_trace = b.option(bool, "print_stack_trace", "This option enables printing stack traces inside the compiler") orelse is_ci or os == .macos or os == .windows; const native_target = b.resolveTargetQuery(.{}); const optimization = b.standardOptimizeOption(.{}); const use_debug = b.option(bool, "use_debug", "This option enables the LLVM debug build in the development PC") orelse false; const static = b.option(bool, "static", "This option enables the compiler to be built statically") orelse switch (@import("builtin").os.tag) { else => use_debug, + .windows => true, .macos => true, }; const compiler_options = b.addOptions(); @@ -42,7 +43,17 @@ pub fn build(b: *std.Build) !void { .single_threaded = true, }); - var target_query = b.standardTargetOptionsQueryOnly(.{}); + var target_query = b.standardTargetOptionsQueryOnly(switch (@import("builtin").os.tag) { + else => .{}, + .windows => .{ + .default_target = .{ + .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v3 }, + .cpu_arch = .x86_64, + .os_tag = .windows, + .abi = .gnu, + }, + }, + }); const abi = b.option(std.Target.Abi, "abi", "This option modifies the ABI used for the compiler") orelse if (static) switch (target_query.os_tag orelse @import("builtin").os.tag) { else => target_query.abi, .linux => b: { @@ -62,6 +73,7 @@ pub fn build(b: *std.Build) !void { break :b if (std.mem.eql(u8, value, "arch") or std.mem.eql(u8, value, "endeavouros")) .musl else target_query.abi; }, } else target_query.abi; + target_query.abi = abi; const target = b.resolveTargetQuery(target_query); @@ -107,7 +119,7 @@ pub fn build(b: *std.Build) !void { compiler.want_lto = false; compiler.linkLibC(); - if (target.result.os.tag == .windows) compiler.linkage = .dynamic; + //if (target.result.os.tag == .windows) compiler.linkage = .dynamic; const zstd = if (target.result.os.tag == .windows) "zstd.lib" else "libzstd.a";