Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions src/msvcup.zig
Original file line number Diff line number Diff line change
Expand Up @@ -809,10 +809,22 @@ fn installAutoenvArch(
}
}

// cleanup this file from an old version of msvcup
out_dir.deleteFile("toolchain.cmake") catch |err| switch (err) {
error.FileNotFound => {},
else => |e| return e,
};

{
const cmake = generateToolchainCmake(scratch, unique_pkgs, target_cpu, .native) catch |e| oom(e);
defer scratch.free(cmake);
try updateFile(out_dir, "toolchain-native.cmake", cmake);
}

{
const cmake = generateToolchainCmake(scratch, unique_pkgs, target_cpu) catch |e| oom(e);
const cmake = generateToolchainCmake(scratch, unique_pkgs, target_cpu, .cross) catch |e| oom(e);
defer scratch.free(cmake);
try updateFile(out_dir, "toolchain.cmake", cmake);
try updateFile(out_dir, "toolchain-cross.cmake", cmake);
}

{
Expand Down Expand Up @@ -1276,19 +1288,27 @@ fn generateToolchainCmake(
allocator: std.mem.Allocator,
unique_pkgs: *const UniquePackages,
target_cpu: Arch,
variant: enum { native, cross },
) error{OutOfMemory}![]u8 {
var content: std.ArrayListUnmanaged(u8) = .{};
defer content.deinit(allocator);
const writer = content.writer(allocator);

try writer.writeAll("set(CMAKE_SYSTEM_NAME Windows)\n");
if (switch (target_cpu) {
.x64 => "AMD64",
.x86 => "X86",
.arm => null,
.arm64 => "ARM64",
}) |processor| {
try writer.print("set(CMAKE_SYSTEM_PROCESSOR {s})\n", .{processor});
switch (variant) {
.native => {},
.cross => {
try writer.writeAll("# settings CMAKE_SYSTEM_NAME and/or CMAKE_SYSTEM_PROCESSOR in a\n");
try writer.writeAll("# toolchain file also sets CMAKE_CROSSCOMPILING to TRUE\n");
try writer.writeAll("set(CMAKE_SYSTEM_NAME Windows)\n");
if (switch (target_cpu) {
.x64 => "AMD64",
.x86 => "X86",
.arm => null,
.arm64 => "ARM64",
}) |processor| {
try writer.print("set(CMAKE_SYSTEM_PROCESSOR {s})\n", .{processor});
}
},
}

if (unique_pkgs.msvc != null) {
Expand Down