From 9688e6e6208910b3e8dce5a6b93ea743fd46a575 Mon Sep 17 00:00:00 2001 From: Eric Joldasov Date: Tue, 16 Jun 2026 19:33:01 +0500 Subject: [PATCH] Resolve relative install directories against install prefix This fixes a regression introduced on the master branch in commit 0505318efe0d2757a344dded9ae1607f948f7511 (PR https://codeberg.org/ziglang/zig/pulls/35428). In Zig 0.16 and earlier, overriding install sub-directories (such as `--prefix-lib-dir`) with a relative path correctly resolved them against the "install prefix". The mentioned PR changed this behavior (though this was not mentioned in its description), causing relative path overrides to resolve against the "current working directory" instead. This commit restores the old behavior and brings the logic back in line with existing build system conventions (CMake, Autotools, Meson): * Absolute paths are used as-is. * Relative paths are resolved relative to the install prefix path, rather than CWD. Ecosystem context: https://github.com/mesonbuild/meson/pull/9903 Signed-off-by: Eric Joldasov --- lib/compiler/Maker.zig | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/compiler/Maker.zig b/lib/compiler/Maker.zig index 6cbe61a1b3509d633c48e083cdc6fdf853d306c9..b36f6e4e7da2388d368b6d1684c893f362c57a32 100644 --- a/lib/compiler/Maker.zig +++ b/lib/compiler/Maker.zig @@ -648,20 +648,31 @@ pub fn main(init: process.Init.Minimal) !void { .sub_path = "zig-out", }; - const install_lib_path: Path = if (override_lib_dir) |cwd_relative| .{ - .root_dir = .cwd(), - .sub_path = cwd_relative, - } else try install_prefix_path.join(arena, "lib"); + // These three overrides are meant to be relative to the install prefix, + // not current working directory, unless absolute paths are used. + const install_lib_path: Path = if (override_lib_dir) |lib_dir| + if (Dir.path.isAbsolute(lib_dir)) .{ + .root_dir = .cwd(), + .sub_path = lib_dir, + } else try install_prefix_path.join(arena, lib_dir) + else + try install_prefix_path.join(arena, "lib"); - const install_bin_path: Path = if (override_bin_dir) |cwd_relative| .{ - .root_dir = .cwd(), - .sub_path = cwd_relative, - } else try install_prefix_path.join(arena, "bin"); + const install_bin_path: Path = if (override_bin_dir) |bin_dir| + if (Dir.path.isAbsolute(bin_dir)) .{ + .root_dir = .cwd(), + .sub_path = bin_dir, + } else try install_prefix_path.join(arena, bin_dir) + else + try install_prefix_path.join(arena, "bin"); - const install_include_path: Path = if (override_include_dir) |cwd_relative| .{ - .root_dir = .cwd(), - .sub_path = cwd_relative, - } else try install_prefix_path.join(arena, "include"); + const install_include_path: Path = if (override_include_dir) |include_dir| + if (Dir.path.isAbsolute(include_dir)) .{ + .root_dir = .cwd(), + .sub_path = include_dir, + } else try install_prefix_path.join(arena, include_dir) + else + try install_prefix_path.join(arena, "include"); const now = Io.Clock.Timestamp.now(io, .awake); -- 2.54.0