Skip to content

Commit

Permalink
test-link: add -Denable-symlinks-windows to opt-in to using symlinks
Browse files Browse the repository at this point in the history
Adds a way for standalone tests to declare they need symlinks, and these
tests won't be run on windows unless -Denable-symlinks-windows is set
  • Loading branch information
kcbanner committed Nov 26, 2022
1 parent 30eb2a1 commit 57bc61a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
4 changes: 3 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub fn build(b: *Builder) !void {
"Whether LLVM has the experimental target arc enabled",
) orelse false;
const enable_macos_sdk = b.option(bool, "enable-macos-sdk", "Run tests requiring presence of macOS SDK and frameworks") orelse false;
const enable_symlinks_windows = b.option(bool, "enable-symlinks-windows", "Enable using symlinks on Windows. If this is not set, hardlinks are used.") orelse false;
const config_h_path_option = b.option([]const u8, "config_h", "Path to the generated config.h");

if (!skip_install_lib_files) {
Expand Down Expand Up @@ -519,9 +520,10 @@ pub fn build(b: *Builder) !void {
b.enable_rosetta,
b.enable_wasmtime,
b.enable_wine,
enable_symlinks_windows,
));
test_step.dependOn(tests.addCAbiTests(b, skip_non_native));
test_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk, skip_stage2_tests));
test_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk, skip_stage2_tests, enable_symlinks_windows));
test_step.dependOn(tests.addStackTraceTests(b, test_filter, modes));
test_step.dependOn(tests.addCliTests(b, test_filter, modes));
test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes));
Expand Down
3 changes: 2 additions & 1 deletion ci/windows/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ Write-Output " zig build test docs..."
& "$ZIGINSTALLDIR\bin\zig.exe" build test docs `
--search-prefix "$ZIGPREFIXPATH" `
-Dstatic-llvm `
-Dskip-non-native
-Dskip-non-native `
-Denable-symlinks-windows
CheckLastExitCode

# Produce the experimental std lib documentation.
Expand Down
21 changes: 20 additions & 1 deletion test/link.zig
Original file line number Diff line number Diff line change
Expand Up @@ -82,83 +82,102 @@ fn addMachOCases(cases: *tests.StandaloneContext) void {
cases.addBuildFile("test/link/macho/bugs/13056/build.zig", .{
.build_modes = true,
.requires_macos_sdk = true,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/bugs/13457/build.zig", .{
.build_modes = true,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/dead_strip/build.zig", .{
.build_modes = false,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/dead_strip_dylibs/build.zig", .{
.build_modes = true,
.requires_macos_sdk = true,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/dylib/build.zig", .{
.build_modes = true,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/empty/build.zig", .{
.build_modes = true,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/entry/build.zig", .{
.build_modes = true,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/headerpad/build.zig", .{
.build_modes = true,
.requires_macos_sdk = true,
});
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/linksection/build.zig", .{
.build_modes = true,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/needed_framework/build.zig", .{
.build_modes = true,
.requires_macos_sdk = true,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/needed_library/build.zig", .{
.build_modes = true,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/objc/build.zig", .{
.build_modes = true,
.requires_macos_sdk = true,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/objcpp/build.zig", .{
.build_modes = true,
.requires_macos_sdk = true,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/pagezero/build.zig", .{
.build_modes = false,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/search_strategy/build.zig", .{
.build_modes = true,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/stack_size/build.zig", .{
.build_modes = true,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/tls/build.zig", .{
.build_modes = true,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/weak_library/build.zig", .{
.build_modes = true,
.requires_symlinks = true,
});

cases.addBuildFile("test/link/macho/weak_framework/build.zig", .{
.build_modes = true,
.requires_macos_sdk = true,
.requires_symlinks = true,
});
}
7 changes: 7 additions & 0 deletions test/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ pub fn addStandaloneTests(
enable_rosetta: bool,
enable_wasmtime: bool,
enable_wine: bool,
enable_symlinks_windows: bool,
) *build.Step {
const cases = b.allocator.create(StandaloneContext) catch unreachable;
cases.* = StandaloneContext{
Expand All @@ -522,6 +523,7 @@ pub fn addStandaloneTests(
.enable_rosetta = enable_rosetta,
.enable_wasmtime = enable_wasmtime,
.enable_wine = enable_wine,
.enable_symlinks_windows = enable_symlinks_windows,
};

standalone.addCases(cases);
Expand All @@ -535,6 +537,7 @@ pub fn addLinkTests(
modes: []const Mode,
enable_macos_sdk: bool,
omit_stage2: bool,
enable_symlinks_windows: bool,
) *build.Step {
const cases = b.allocator.create(StandaloneContext) catch unreachable;
cases.* = StandaloneContext{
Expand All @@ -547,6 +550,7 @@ pub fn addLinkTests(
.enable_macos_sdk = enable_macos_sdk,
.target = .{},
.omit_stage2 = omit_stage2,
.enable_symlinks_windows = enable_symlinks_windows,
};
link.addCases(cases);
return cases.step;
Expand Down Expand Up @@ -1022,6 +1026,7 @@ pub const StandaloneContext = struct {
enable_rosetta: bool = false,
enable_wasmtime: bool = false,
enable_wine: bool = false,
enable_symlinks_windows: bool,

pub fn addC(self: *StandaloneContext, root_src: []const u8) void {
self.addAllArgs(root_src, true);
Expand All @@ -1037,11 +1042,13 @@ pub const StandaloneContext = struct {
requires_macos_sdk: bool = false,
requires_stage2: bool = false,
use_emulation: bool = false,
requires_symlinks: bool = false,
}) void {
const b = self.b;

if (features.requires_macos_sdk and !self.enable_macos_sdk) return;
if (features.requires_stage2 and self.omit_stage2) return;
if (features.requires_symlinks and !self.enable_symlinks_windows and builtin.os.tag == .windows) return;

const annotated_case_name = b.fmt("build {s}", .{build_file});
if (self.test_filter) |filter| {
Expand Down

0 comments on commit 57bc61a

Please sign in to comment.