Skip to content

Deduplicate @executable_path rpaths on macos #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
19 changes: 16 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ pub fn build(b: *std.Build) void {
}
}

/// Adding the same rpath multiple times will cause dynamic library
/// loading to fail on macOS 15.4 and later. Therefore, only add the
/// `@executable_path` rpath if it does not already exist.
fn addExecutablePathRPath(module: *std.Build.Module) void {
for (module.rpaths.items) |rpath| {
if (rpath == .special and std.mem.eql(u8, rpath.special, "@executable_path")) {
return;
}
}

module.addRPathSpecial("@executable_path");
}

pub fn link_SDL2(compile_step: *std.Build.Step.Compile) void {
switch (compile_step.rootModuleTarget().os.tag) {
.windows => {
Expand All @@ -92,7 +105,7 @@ pub fn link_SDL2(compile_step: *std.Build.Step.Compile) void {
},
.macos => {
compile_step.linkFramework("SDL2");
compile_step.root_module.addRPathSpecial("@executable_path");
addExecutablePathRPath(compile_step.root_module);
},
else => {},
}
Expand All @@ -109,7 +122,7 @@ pub fn link_SDL2_ttf(compile_step: *std.Build.Step.Compile) void {
},
.macos => {
compile_step.linkFramework("SDL2_ttf");
compile_step.root_module.addRPathSpecial("@executable_path");
addExecutablePathRPath(compile_step.root_module);
},
else => {},
}
Expand All @@ -126,7 +139,7 @@ pub fn link_SDL2_image(compile_step: *std.Build.Step.Compile) void {
},
.macos => {
compile_step.linkFramework("SDL2_image");
compile_step.root_module.addRPathSpecial("@executable_path");
addExecutablePathRPath(compile_step.root_module);
},
else => {},
}
Expand Down