Skip to content

Commit

Permalink
Merge pull request #513 from Pyrolistical/zsdl-use-cwd-over-rpath-on-…
Browse files Browse the repository at this point in the history
…windows

[zsdl] handle windows case for #467 by setting cwd instead of rpath
  • Loading branch information
hazeycode committed Mar 2, 2024
2 parents f104298 + cb3d10b commit e3dc04f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
4 changes: 2 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ fn tests(
test_step.dependOn(zphysics.runTests(b, optimize, target));
test_step.dependOn(zpool.runTests(b, optimize, target));

// TODO(hazeycode): Fix tests linking SDL on Windows and macOS
// TODO(hazeycode): Fix tests linking SDL on macOS
switch (target.result.os.tag) {
.windows, .macos => {},
.macos => {},
else => test_step.dependOn(zsdl.runTests(b, optimize, target)),
}

Expand Down
25 changes: 20 additions & 5 deletions libs/zsdl/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Run zsdl tests");
test_step.dependOn(runTests(b, optimize, target));

const version_check_step = b.step("version-check", "checks runtime library version is the same as the compiled version");
version_check_step.dependOn(testStep("src/sdl2_version_check.zig", b, "zsdl-sdl2-version-check", target, optimize, .{
.api_version = .sdl2,
.enable_ttf = true,
}));

_ = package(b, target, optimize, .{
.options = .{
.api_version = b.option(ApiVersion, "api_version", "Select an SDL API version") orelse .sdl2,
Expand All @@ -227,13 +233,13 @@ pub fn runTests(
const step = b.allocator.create(std.Build.Step) catch @panic("OOM");
step.* = std.Build.Step.init(.{ .id = .custom, .name = "zsdl-tests", .owner = b });

step.dependOn(testStep(b, "zsdl-tests-sdl2", target, optimize, .{
step.dependOn(testStep("src/zsdl.zig", b, "zsdl-tests-sdl2", target, optimize, .{
.api_version = .sdl2,
.enable_ttf = true,
}));

// TODO: link SDL3 libs on all platforms
// step.dependOn(testStep(b, "zsdl-tests-sdl3", target, optimize, .{
// step.dependOn(testStep("src/zsdl.zig", b, "zsdl-tests-sdl3", target, optimize, .{
// .api_version = .sdl3,
// .enable_ttf = true,
// }));
Expand All @@ -242,6 +248,7 @@ pub fn runTests(
}

fn testStep(
comptime test_entry: []const u8,
b: *std.Build,
name: []const u8,
target: std.Build.ResolvedTarget,
Expand All @@ -250,14 +257,22 @@ fn testStep(
) *std.Build.Step {
const tests = b.addTest(.{
.name = name,
.root_source_file = .{ .path = thisDir() ++ "/src/zsdl.zig" },
.root_source_file = .{ .path = thisDir() ++ "/" ++ test_entry },
.target = target,
.optimize = optimize,
});
const pkg = package(b, target, optimize, .{ .options = options });
pkg.link(tests);
tests.addRPath(.{ .path = b.getInstallPath(.bin, "") });
return &b.addRunArtifact(tests).step;
var test_run = b.addRunArtifact(tests);
switch (target.result.os.tag) {
.windows => test_run.setCwd(.{
.path = b.getInstallPath(.bin, ""),
}),
else => tests.addRPath(.{
.path = b.getInstallPath(.bin, ""),
}),
}
return &test_run.step;
}

inline fn thisDir() []const u8 {
Expand Down
6 changes: 6 additions & 0 deletions libs/zsdl/src/sdl2_version_check.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const std = @import("std");
const sdl2 = @import("sdl2.zig");

test "compiled version should be same as linked version" {
try std.testing.expectEqual(sdl2.VERSION, sdl2.getVersion());
}

0 comments on commit e3dc04f

Please sign in to comment.