Skip to content

Commit

Permalink
msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobly0 committed May 9, 2024
1 parent a24cfc4 commit 728a096
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ jobs:
fetch-depth: 0
- name: Build and Test
working-directory: ci
run: '& $Env:USERPROFILE\deps\zig-x86_64-windows-gnu-${{env.ci-zig-version}}\bin\zig.exe build -Dbuild-type=Debug -Dskip-non-native cmake-bootstrap tidy update-stage1'
run: '& $Env:USERPROFILE\deps\zig-x86_64-windows-gnu-${{env.ci-zig-version}}\bin\zig.exe build -Dbuild-type=Debug -Dskip-non-native cmake-bootstrap tidy update-stage1 msvc'
x86_64-windows-release:
if: github.repository_owner == 'ziglang'
runs-on: [self-hosted, Windows, x86_64]
Expand Down
127 changes: 127 additions & 0 deletions ci/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -553,5 +553,132 @@ pub fn build(b: *std.Build) void {
run_tests_with_updated_stage4.addFileArg(b.path("../test/behavior.zig"));
update_stage1_step.dependOn(&run_tests_with_updated_stage4.step);
}

if (std.zig.WindowsSdk.find(b.allocator)) |sdk| msvc: {
const win10sdk = sdk.windows10sdk orelse break :msvc;
std.debug.print("{s}\n", .{b.pathResolve(&.{
win10sdk.path,
"Include",
win10sdk.version,
"ucrt",
})});

const msvc_arch = switch (host.result.cpu.arch) {
.x86 => "x86",
.x86_64 => "x64",
.arm, .armeb, .thumb, .thumbeb => "arm",
.aarch64 => "arm64",
else => break :msvc,
};
const cl_exe = b.pathResolve(&.{
sdk.msvc_lib_dir orelse break :msvc,
"..",
"..",
"bin",
b.fmt("Host{s}", .{msvc_arch}),
msvc_arch,
b.fmt("cl{s}", .{host_exe_file_ext}),
});
const msvc_triple = triple: {
var msvc_target = host.result;
msvc_target.abi = .msvc;
break :triple msvc_target.linuxTriple(b.allocator) catch @panic("OOM");
};

const msvc_step = b.step("msvc", "Run the behavior tests compiled with MSVC");

const build_msvc_behavior_tests = std.Build.Step.Run.create(b, "build msvc behavior tests");
build_msvc_behavior_tests.step.max_rss = 213_237_760;
if (false)
build_msvc_behavior_tests.addFileArg(stage3_exe)
else
build_msvc_behavior_tests.addArg(b.cache_root.join(b.allocator, &.{
"o",
"4aeed00bc8dFaa6ee10d8a09a88bd97b",
"build",
"stage3",
"bin",
b.fmt("zig{s}", .{host_exe_file_ext}),
}) catch @panic("OOM"));
build_msvc_behavior_tests.addArgs(&.{
"test",
"-ofmt=c",
"--test-no-exec",
"-target",
msvc_triple,
"-lc",
});
build_msvc_behavior_tests.addFileArg(b.path("../test/behavior.zig"));
const behavior_msvc_source =
build_msvc_behavior_tests.addPrefixedOutputFileArg("-femit-bin=", "behavior-msvc.c");

const build_msvc_compiler_rt = std.Build.Step.Run.create(b, "build msvc compiler-rt");
build_msvc_compiler_rt.step.max_rss = 164_306_944;
if (false)
build_msvc_compiler_rt.addFileArg(stage3_exe)
else
build_msvc_compiler_rt.addArg(b.cache_root.join(b.allocator, &.{
"o",
"4aeed00bc8dFaa6ee10d8a09a88bd97b",
"build",
"stage3",
"bin",
b.fmt("zig{s}", .{host_exe_file_ext}),
}) catch @panic("OOM"));
build_msvc_compiler_rt.addArgs(&.{
"build-obj",
"-ofmt=c",
"-OReleaseSmall",
"--name",
"compiler_rt",
"-target",
msvc_triple,
"-lc",
});
build_msvc_compiler_rt.addFileArg(b.path("../lib/compiler_rt.zig"));
const compiler_rt_msvc_source =
build_msvc_compiler_rt.addPrefixedOutputFileArg("-femit-bin=", "compiler_rt-msvc.c");

const build_msvc_tests = std.Build.Step.Run.create(b, "build msvc tests");
build_msvc_tests.step.max_rss = 1;
build_msvc_tests.addArgs(&.{ cl_exe, "/W3", "/Z7" });
build_msvc_tests.addPrefixedDirectoryArg("/I", b.path("../lib"));
build_msvc_tests.addFileArg(behavior_msvc_source);
build_msvc_tests.addFileArg(compiler_rt_msvc_source);
const msvc_tests_exe = build_msvc_tests.addPrefixedOutputFileArg(
"/Fe:",
b.fmt("behavior-msvc{s}", .{host_exe_file_ext}),
);
// Link args must appear after all other args.
build_msvc_tests.addArgs(&.{
"/link",
"/nologo",
"/debug",
"/subsystem:console",
"kernel32.lib",
"ntdll.lib",
"libcmt.lib",
});
build_msvc_tests.setEnvironmentVariable("INCLUDE", std.mem.join(
b.allocator,
&.{std.fs.path.delimiter},
&.{b.pathResolve(&.{
win10sdk.path,
"Include",
win10sdk.version,
"ucrt",
})},
) catch @panic("OOM"));
if (true) build_msvc_tests.has_side_effects = true;

const run_msvc_tests = std.Build.Step.Run.create(b, "run msvc tests");
run_msvc_tests.step.max_rss = 2;
run_msvc_tests.addFileArg(msvc_tests_exe);
msvc_step.dependOn(&run_msvc_tests.step);
} else |err| switch (err) {
error.NotFound => {},

else => |e| @panic(@errorName(e)),
}
}
}

0 comments on commit 728a096

Please sign in to comment.