Some Windows improvements

This commit is contained in:
David Gonzalez Martin 2024-04-15 09:23:58 -06:00
parent 1e7248ab0a
commit 23399c5ea6
3 changed files with 35 additions and 19 deletions

View File

@ -2769,6 +2769,7 @@ const Arch = enum {
const Os = enum { const Os = enum {
linux, linux,
macos, macos,
windows,
}; };
const Abi = enum { const Abi = enum {
@ -2795,6 +2796,11 @@ pub fn buildExecutable(context: *const Context, arguments: []const []const u8, o
os = .macos; os = .macos;
abi = .none; abi = .none;
}, },
.windows => {
arch = .x86_64;
os = .windows;
abi = .gnu;
},
else => unreachable, else => unreachable,
} }
@ -2983,6 +2989,7 @@ pub fn buildExecutable(context: *const Context, arguments: []const []const u8, o
.link_libc = switch (os) { .link_libc = switch (os) {
.linux => link_libc, .linux => link_libc,
.macos => true, .macos => true,
.windows => link_libc,
// .windows => link_libc, // .windows => link_libc,
// else => unreachable, // else => unreachable,
}, },
@ -3066,7 +3073,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, return_
write(.panic, "\nPANIC: ") catch {}; write(.panic, "\nPANIC: ") catch {};
write(.panic, message) catch {}; write(.panic, message) catch {};
write(.panic, "\n") catch {}; write(.panic, "\n") catch {};
@breakpoint(); if (@import("builtin").os.tag != .windows) @breakpoint();
std.posix.abort(); std.posix.abort();
}, },
} }
@ -3277,7 +3284,7 @@ pub const Type = union(enum) {
polymorphic: Type.Polymorphic, polymorphic: Type.Polymorphic,
pub const @"usize" = _usize; pub const @"usize" = _usize;
pub const @"ssize" = _ssize; pub const ssize = _ssize;
pub const Polymorphic = struct { pub const Polymorphic = struct {
parameters: []const Token.Index, parameters: []const Token.Index,
@ -8787,7 +8794,6 @@ pub const Builder = struct {
const phi = &unit.instructions.get(builder.return_phi).phi; const phi = &unit.instructions.get(builder.return_phi).phi;
switch (return_type.*) { switch (return_type.*) {
.void => unreachable, .void => unreachable,
.noreturn => unreachable, .noreturn => unreachable,
@ -16724,5 +16730,3 @@ pub fn write(kind: LogKind, string: []const u8) !void {
try std.io.getStdOut().writeAll(string); try std.io.getStdOut().writeAll(string);
} }
} }

View File

@ -2363,7 +2363,6 @@ pub const LLVM = struct {
.function_definition => {}, .function_definition => {},
else => |t| @panic(@tagName(t)), else => |t| @panic(@tagName(t)),
} }
} }
}; };
@ -3247,13 +3246,14 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo
arch.initializeTargetMC(); arch.initializeTargetMC();
arch.initializeAsmPrinter(); arch.initializeAsmPrinter();
arch.initializeAsmParser(); arch.initializeAsmParser();
} },
} }
// TODO: proper target selection // TODO: proper target selection
const target_triple = switch (unit.descriptor.os) { const target_triple = switch (unit.descriptor.os) {
.linux => "x86_64-linux-none", .linux => "x86_64-linux-none",
.macos => "aarch64-apple-macosx-none", .macos => "aarch64-apple-macosx-none",
.windows => "x86_64-windows-gnu",
}; };
const cpu = "generic"; const cpu = "generic";
const features = ""; const features = "";

View File

@ -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 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 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 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 native_target = b.resolveTargetQuery(.{});
const optimization = b.standardOptimizeOption(.{}); 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 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) { const static = b.option(bool, "static", "This option enables the compiler to be built statically") orelse switch (@import("builtin").os.tag) {
else => use_debug, else => use_debug,
.windows => true,
.macos => true, .macos => true,
}; };
const compiler_options = b.addOptions(); const compiler_options = b.addOptions();
@ -42,7 +43,17 @@ pub fn build(b: *std.Build) !void {
.single_threaded = true, .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) { 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, else => target_query.abi,
.linux => b: { .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; 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; } else target_query.abi;
target_query.abi = abi; target_query.abi = abi;
const target = b.resolveTargetQuery(target_query); const target = b.resolveTargetQuery(target_query);
@ -107,7 +119,7 @@ pub fn build(b: *std.Build) !void {
compiler.want_lto = false; compiler.want_lto = false;
compiler.linkLibC(); 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"; const zstd = if (target.result.os.tag == .windows) "zstd.lib" else "libzstd.a";