Some Windows fixes

This commit is contained in:
David Gonzalez Martin 2024-04-09 12:47:40 -06:00
parent 5398895e5e
commit 08ca8706b9
6 changed files with 30 additions and 13 deletions

View File

@ -475,7 +475,11 @@ pub fn compileCSourceFile(context: *const Context, arguments: []const []const u8
} else { } else {
const debug_args = true; const debug_args = true;
if (debug_args) { if (debug_args) {
const home_dir = std.posix.getenv("HOME") orelse unreachable; const home_dir = switch (@import("builtin").os.tag) {
.linux, .macos => std.posix.getenv("HOME") orelse unreachable,
.windows => try std.process.getEnvVarOwned(context.allocator, "USERPROFILE"),
else => @compileError("OS not supported"),
};
var list = UnpinnedArray(u8){}; var list = UnpinnedArray(u8){};
for (arguments) |arg| { for (arguments) |arg| {
try list.append_slice(context.my_allocator, arg); try list.append_slice(context.my_allocator, arg);
@ -572,6 +576,9 @@ pub fn compileCSourceFile(context: *const Context, arguments: []const []const u8
.macos => { .macos => {
try target_triple_buffer.append_slice(context.my_allocator, "macos-"); try target_triple_buffer.append_slice(context.my_allocator, "macos-");
}, },
.windows => {
try target_triple_buffer.append_slice(context.my_allocator, "windows-");
},
else => @compileError("OS not supported"), else => @compileError("OS not supported"),
} }
@ -647,6 +654,7 @@ pub fn compileCSourceFile(context: *const Context, arguments: []const []const u8
}, },
else => unreachable, //@compileError("ABI not supported"), else => unreachable, //@compileError("ABI not supported"),
}, },
.windows => &.{},
else => @compileError("OS not supported"), else => @compileError("OS not supported"),
}; };
@ -3230,7 +3238,7 @@ pub const Type = union(enum) {
array: Type.Array, array: Type.Array,
polymorphic: Type.Polymorphic, polymorphic: Type.Polymorphic,
pub const Polymorphic = struct{ pub const Polymorphic = struct {
parameters: []const Token.Index, parameters: []const Token.Index,
instantiations: MyHashMap(u32, *Debug.Declaration.Global) = .{}, instantiations: MyHashMap(u32, *Debug.Declaration.Global) = .{},
node: Node.Index, node: Node.Index,
@ -3243,7 +3251,7 @@ pub const Type = union(enum) {
pub fn add_instantiation(polymorphic: *Polymorphic, unit: *Unit, context: *const Context, types: []const V.Comptime, original_declaration: *Debug.Declaration.Global, type_index: Type.Index) !void { pub fn add_instantiation(polymorphic: *Polymorphic, unit: *Unit, context: *const Context, types: []const V.Comptime, original_declaration: *Debug.Declaration.Global, type_index: Type.Index) !void {
var name = UnpinnedArray(u8){}; var name = UnpinnedArray(u8){};
const original_name = unit.getIdentifier( original_declaration.declaration.name); const original_name = unit.getIdentifier(original_declaration.declaration.name);
try name.append_slice(context.my_allocator, original_name); try name.append_slice(context.my_allocator, original_name);
try name.append(context.my_allocator, '('); try name.append(context.my_allocator, '(');
@ -7627,7 +7635,7 @@ pub const Builder = struct {
}); });
const struct_type = unit.structs.get(struct_index); const struct_type = unit.structs.get(struct_index);
const struct_options = & struct_type.kind.@"struct".options; const struct_options = &struct_type.kind.@"struct".options;
var parameter_types = UnpinnedArray(Token.Index){}; var parameter_types = UnpinnedArray(Token.Index){};
@ -8838,7 +8846,7 @@ pub const Builder = struct {
const ty = unit.types.get(type_index); const ty = unit.types.get(type_index);
switch (ty.*) { switch (ty.*) {
.pointer => |_| switch (value) { .pointer => |_| switch (value) {
.@"comptime_int" => |ct_int| switch (ct_int.value) { .comptime_int => |ct_int| switch (ct_int.value) {
0 => return .null_pointer, 0 => return .null_pointer,
else => unreachable, else => unreachable,
}, },
@ -12133,7 +12141,7 @@ pub const Builder = struct {
else => |t| @panic(@tagName(t)), else => |t| @panic(@tagName(t)),
} }
} else { } else {
const id = unit.getIdentifier( struct_type.scope.scope.declarations.key_pointer[0]); const id = unit.getIdentifier(struct_type.scope.scope.declarations.key_pointer[0]);
_ = id; // autofix _ = id; // autofix
unreachable; unreachable;
} }

View File

@ -375,7 +375,7 @@ pub fn allocate_virtual_memory(size: usize, flags: packed struct {
pub fn free_virtual_memory(slice: []align(page_size) const u8) void { pub fn free_virtual_memory(slice: []align(page_size) const u8) void {
switch (os) { switch (os) {
.windows => { .windows => {
std.os.windows.VirtualFree(slice.ptr, slice.len, std.os.windows.MEM_RELEASE); std.os.windows.VirtualFree(@constCast(@ptrCast(slice.ptr)), slice.len, std.os.windows.MEM_RELEASE);
}, },
else => { else => {
std.posix.munmap(slice); std.posix.munmap(slice);

View File

@ -77,6 +77,7 @@ pub fn link(context: *const Compilation.Context, options: linker.Options) !void
try argv.append(context.my_allocator, "/usr/lib/crtn.o"); try argv.append(context.my_allocator, "/usr/lib/crtn.o");
} }
}, },
.windows => {},
else => @compileError("OS not supported"), else => @compileError("OS not supported"),
} }

View File

@ -49,15 +49,15 @@ var my_allocator = PageAllocator{};
pub fn main() !void { pub fn main() !void {
var arena_allocator = std.heap.ArenaAllocator.init(std.heap.page_allocator); var arena_allocator = std.heap.ArenaAllocator.init(std.heap.page_allocator);
const allocator = arena_allocator.allocator(); const allocator = arena_allocator.allocator();
var arg_it = std.process.ArgIterator.init(); var arg_it = try std.process.ArgIterator.initWithAllocator(allocator);
var args = library.UnpinnedArray([]const u8){}; var args = library.UnpinnedArray([]const u8){};
const context = try Compilation.createContext(allocator, &my_allocator.allocator); const context = try Compilation.createContext(allocator, &my_allocator.allocator);
while (arg_it.next()) |arg| { while (arg_it.next()) |arg| {
try args.append(context.my_allocator, arg); try args.append(context.my_allocator, arg);
} }
const arguments = args.slice(); const arguments = args.slice();
const debug_args = true; const debug_args = false;
if (debug_args) { if (debug_args and @import("builtin").os.tag != .windows) {
assert(arguments.len > 0); assert(arguments.len > 0);
const home_dir = std.posix.getenv("HOME") orelse unreachable; const home_dir = std.posix.getenv("HOME") orelse unreachable;
const timestamp = std.time.milliTimestamp(); const timestamp = std.time.milliTimestamp();

View File

@ -43,7 +43,7 @@ pub fn build(b: *std.Build) !void {
}); });
var target_query = b.standardTargetOptionsQueryOnly(.{}); var target_query = b.standardTargetOptionsQueryOnly(.{});
const abi = b.option(std.Target.Abi, "abi", "This option modifies the ABI used for the compiler") orelse if (static) switch (os) { 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: {
const os_release = try std.fs.cwd().readFileAlloc(b.allocator, "/etc/os-release", 0xffff); const os_release = try std.fs.cwd().readFileAlloc(b.allocator, "/etc/os-release", 0xffff);
@ -107,6 +107,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;
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";
@ -349,7 +350,7 @@ pub fn build(b: *std.Build) !void {
"libclangTransformer.a", "libclangTransformer.a",
}; };
if (static) { if (static or target.result.os.tag == .windows) {
if (os == .linux) compiler.linkage = .static; if (os == .linux) compiler.linkage = .static;
compiler.linkLibCpp(); compiler.linkLibCpp();
@ -448,10 +449,17 @@ pub fn build(b: *std.Build) !void {
return err; return err;
} }
}, },
.windows => {},
else => |tag| @panic(@tagName(tag)), else => |tag| @panic(@tagName(tag)),
} }
} }
if (target.result.os.tag == .windows) {
compiler.linkSystemLibrary("ole32");
compiler.linkSystemLibrary("version");
compiler.linkSystemLibrary("uuid");
}
const install_exe = b.addInstallArtifact(compiler, .{}); const install_exe = b.addInstallArtifact(compiler, .{});
b.getInstallStep().dependOn(&install_exe.step); b.getInstallStep().dependOn(&install_exe.step);
b.installDirectory(.{ b.installDirectory(.{

View File

@ -521,7 +521,7 @@ pub fn main() !void {
switch (@import("builtin").os.tag) { switch (@import("builtin").os.tag) {
.macos => {}, .macos => {},
// .macos => {}, .windows => {},
.linux => switch (@import("builtin").abi) { .linux => switch (@import("builtin").abi) {
.gnu => runCmakeTests(allocator, "test/cc_linux") catch { .gnu => runCmakeTests(allocator, "test/cc_linux") catch {
errors = true; errors = true;