From 6ca702b67d9765d434f91f55290ef67e3d844697 Mon Sep 17 00:00:00 2001 From: archbirdplus <53286705+archbirdplus@users.noreply.github.com> Date: Mon, 17 Jun 2024 23:56:08 -0700 Subject: [PATCH] Link Cubyz more correctly. (#461) * Do not add cubyz_deps rpath. * link deps as object file; add macos rpaths --- build.zig | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/build.zig b/build.zig index 3a3035c1..501db0ba 100644 --- a/build.zig +++ b/build.zig @@ -27,6 +27,10 @@ pub fn build(b: *std.Build) !void { .windows => "gnu", else => "none", }}); + const artifactName = switch(t.os.tag) { + .windows => b.fmt("{s}.lib", .{depsLib}), + else => b.fmt("lib{s}.a", .{depsLib}), + }; var depsName: []const u8 = b.fmt("cubyz_deps_{s}_{s}", .{@tagName(t.cpu.arch), @tagName(t.os.tag)}); const useLocalDeps = b.option(bool, "local", "Use local cubyz_deps") orelse false; @@ -47,10 +51,8 @@ pub fn build(b: *std.Build) !void { return; }; - exe.addLibraryPath(libsDeps.path("lib")); exe.addIncludePath(headersDeps.path("include")); - exe.linkSystemLibrary(depsLib); - exe.addRPath(libsDeps.path("lib")); // TODO: Maybe move the library next to the executable, to make this more portable? + exe.addObjectFile(libsDeps.path("lib").path(b, artifactName)); if(t.os.tag == .windows) { exe.linkSystemLibrary("ole32"); @@ -72,10 +74,9 @@ pub fn build(b: *std.Build) !void { exe.linkFramework("IOKit"); exe.linkFramework("Cocoa"); exe.linkFramework("QuartzCore"); - exe.linkSystemLibrary("X11"); - exe.addLibraryPath(b.path("/usr/local/GL/lib")); - exe.addLibraryPath(b.path("/opt/X11/lib")); - exe.addRPath(b.path("../Library")); + exe.addRPath(.{.cwd_relative = "/usr/local/GL/lib"}); + exe.root_module.addRPathSpecial("@executable_path/../Library"); + exe.addRPath(.{.cwd_relative = "/opt/X11/lib"}); } else { std.log.err("Unsupported target: {}\n", .{t.os.tag}); }