Skip to content

Commit

Permalink
build: add cxx library path to rpath if its not a native path
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan200101 committed Dec 2, 2023
1 parent f306d2a commit d4328e4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,28 @@ fn addCxxKnownPath(
}
exe.addObjectFile(.{ .cwd_relative = path_unpadded });

const resolved_path = fs.realpathAlloc(b.allocator, path_unpadded) catch path_unpadded;

if (std.mem.lastIndexOfScalar(u8, resolved_path, '/')) |path_end| {
const obj_dir = resolved_path[0..path_end];

const add_obj_dir = blk: {
const native_paths = NativePaths.detect(b.allocator, exe.target_info) catch {
break :blk true;
};

for (native_paths.lib_dirs.items) |lib_dir| {
if (mem.eql(u8, lib_dir, obj_dir))
break :blk false;
}

break :blk true;
};

if (add_obj_dir)
exe.addLibraryPath(.{ .cwd_relative = obj_dir });
}

// TODO a way to integrate with system c++ include files here
// c++ -E -Wp,-v -xc++ /dev/null
if (need_cpp_includes) {
Expand Down

0 comments on commit d4328e4

Please sign in to comment.