From e35c1ea68e6e33a81038d445842d5298a3f73f62 Mon Sep 17 00:00:00 2001 From: Komo Date: Tue, 3 Dec 2024 04:12:01 +0800 Subject: [PATCH] fix(main/zig): fix missing dynamic linker and libc runtime Closes #20294 Zig uses FHS-type path to guess the dynamic linker of `env` binary. That leads to a warning like in #20294 Zig also tries to find the include dir via `clang`, but it failed. I have no idea why. --- packages/zig/build.sh | 1 + ...zig-lib-std-zig-LibCInstallation.zig.patch | 107 ++++++++++++++++++ packages/zig/zig-lib-std-zig-system.zig.patch | 13 +++ 3 files changed, 121 insertions(+) create mode 100644 packages/zig/zig-lib-std-zig-LibCInstallation.zig.patch create mode 100644 packages/zig/zig-lib-std-zig-system.zig.patch diff --git a/packages/zig/build.sh b/packages/zig/build.sh index 488d86ad145310..a922cb1ea060d4 100644 --- a/packages/zig/build.sh +++ b/packages/zig/build.sh @@ -4,6 +4,7 @@ TERMUX_PKG_LICENSE="MIT" TERMUX_PKG_LICENSE_FILE="zig/LICENSE" TERMUX_PKG_MAINTAINER="@termux" TERMUX_PKG_VERSION="0.13.0" +TERMUX_PKG_REVISION=1 TERMUX_PKG_SRCURL=https://github.com/ziglang/zig/releases/download/${TERMUX_PKG_VERSION}/zig-bootstrap-${TERMUX_PKG_VERSION}.tar.xz TERMUX_PKG_SHA256=cd446c084b5da7bc42e8ad9b4e1c910a957f2bf3f82bcc02888102cd0827c139 TERMUX_PKG_BUILD_IN_SRC=true diff --git a/packages/zig/zig-lib-std-zig-LibCInstallation.zig.patch b/packages/zig/zig-lib-std-zig-LibCInstallation.zig.patch new file mode 100644 index 00000000000000..81c70b524a4cfc --- /dev/null +++ b/packages/zig/zig-lib-std-zig-LibCInstallation.zig.patch @@ -0,0 +1,107 @@ +diff --git a/zig/lib/std/zig/LibCInstallation.zig b/zig/lib/std/zig/LibCInstallation.zig +index 686471bd..4142c72d 100644 +--- a/zig/lib/std/zig/LibCInstallation.zig ++++ b/zig/lib/std/zig/LibCInstallation.zig +@@ -167,52 +167,56 @@ pub const FindNativeOptions = struct { + pub fn findNative(args: FindNativeOptions) FindError!LibCInstallation { + var self: LibCInstallation = .{}; + +- if (is_darwin and args.target.isDarwin()) { +- if (!std.zig.system.darwin.isSdkInstalled(args.allocator)) +- return error.DarwinSdkNotFound; +- const sdk = std.zig.system.darwin.getSdk(args.allocator, args.target) orelse +- return error.DarwinSdkNotFound; +- defer args.allocator.free(sdk); +- +- self.include_dir = try fs.path.join(args.allocator, &.{ +- sdk, "usr/include", +- }); +- self.sys_include_dir = try fs.path.join(args.allocator, &.{ +- sdk, "usr/include", +- }); +- return self; +- } else if (is_windows) { +- const sdk = std.zig.WindowsSdk.find(args.allocator) catch |err| switch (err) { +- error.NotFound => return error.WindowsSdkNotFound, +- error.PathTooLong => return error.WindowsSdkNotFound, +- error.OutOfMemory => return error.OutOfMemory, +- }; +- defer sdk.free(args.allocator); +- +- try self.findNativeMsvcIncludeDir(args, sdk); +- try self.findNativeMsvcLibDir(args, sdk); +- try self.findNativeKernel32LibDir(args, sdk); +- try self.findNativeIncludeDirWindows(args, sdk); +- try self.findNativeCrtDirWindows(args, sdk); +- } else if (is_haiku) { +- try self.findNativeIncludeDirPosix(args); +- try self.findNativeGccDirHaiku(args); +- self.crt_dir = try args.allocator.dupeZ(u8, "/system/develop/lib"); +- } else if (builtin.target.os.tag.isSolarish()) { +- // There is only one libc, and its headers/libraries are always in the same spot. +- self.include_dir = try args.allocator.dupeZ(u8, "/usr/include"); +- self.sys_include_dir = try args.allocator.dupeZ(u8, "/usr/include"); +- self.crt_dir = try args.allocator.dupeZ(u8, "/usr/lib/64"); +- } else if (std.process.can_spawn) { +- try self.findNativeIncludeDirPosix(args); +- switch (builtin.target.os.tag) { +- .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try args.allocator.dupeZ(u8, "/usr/lib"), +- .linux => try self.findNativeCrtDirPosix(args), +- else => {}, +- } +- } else { +- return error.LibCRuntimeNotFound; +- } ++ // if (is_darwin and args.target.isDarwin()) { ++ // if (!std.zig.system.darwin.isSdkInstalled(args.allocator)) ++ // return error.DarwinSdkNotFound; ++ // const sdk = std.zig.system.darwin.getSdk(args.allocator, args.target) orelse ++ // return error.DarwinSdkNotFound; ++ // defer args.allocator.free(sdk); ++ ++ // self.include_dir = try fs.path.join(args.allocator, &.{ ++ // sdk, "usr/include", ++ // }); ++ // self.sys_include_dir = try fs.path.join(args.allocator, &.{ ++ // sdk, "usr/include", ++ // }); ++ // return self; ++ // } else if (is_windows) { ++ // const sdk = std.zig.WindowsSdk.find(args.allocator) catch |err| switch (err) { ++ // error.NotFound => return error.WindowsSdkNotFound, ++ // error.PathTooLong => return error.WindowsSdkNotFound, ++ // error.OutOfMemory => return error.OutOfMemory, ++ // }; ++ // defer sdk.free(args.allocator); ++ ++ // try self.findNativeMsvcIncludeDir(args, sdk); ++ // try self.findNativeMsvcLibDir(args, sdk); ++ // try self.findNativeKernel32LibDir(args, sdk); ++ // try self.findNativeIncludeDirWindows(args, sdk); ++ // try self.findNativeCrtDirWindows(args, sdk); ++ // } else if (is_haiku) { ++ // try self.findNativeIncludeDirPosix(args); ++ // try self.findNativeGccDirHaiku(args); ++ // self.crt_dir = try args.allocator.dupeZ(u8, "/system/develop/lib"); ++ // } else if (builtin.target.os.tag.isSolarish()) { ++ // // There is only one libc, and its headers/libraries are always in the same spot. ++ // self.include_dir = try args.allocator.dupeZ(u8, "/usr/include"); ++ // self.sys_include_dir = try args.allocator.dupeZ(u8, "/usr/include"); ++ // self.crt_dir = try args.allocator.dupeZ(u8, "/usr/lib/64"); ++ // } else if (std.process.can_spawn) { ++ // try self.findNativeIncludeDirPosix(args); ++ // switch (builtin.target.os.tag) { ++ // .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try args.allocator.dupeZ(u8, "/usr/lib"), ++ // .linux => try self.findNativeCrtDirPosix(args), ++ // else => {}, ++ // } ++ // } else { ++ // return error.LibCRuntimeNotFound; ++ // } ++ ++ self.include_dir = try args.allocator.dupeZ(u8, "@TERMUX_PREFIX@/include"); ++ self.sys_include_dir = try args.allocator.dupeZ(u8, "@TERMUX_PREFIX@/sys_include"); ++ self.crt_dir = try args.allocator.dupeZ(u8, "@TERMUX_PREFIX@/lib"); + return self; + } + diff --git a/packages/zig/zig-lib-std-zig-system.zig.patch b/packages/zig/zig-lib-std-zig-system.zig.patch new file mode 100644 index 00000000000000..fe7e67cb5cb37b --- /dev/null +++ b/packages/zig/zig-lib-std-zig-system.zig.patch @@ -0,0 +1,13 @@ +diff --git a/zig/lib/std/zig/system.zig b/zig/lib/std/zig/system.zig +index 83c798c3..69aef66e 100644 +--- a/zig/lib/std/zig/system.zig ++++ b/zig/lib/std/zig/system.zig +@@ -996,6 +996,8 @@ fn detectAbiAndDynamicLinker( + .haiku => "/bin/env", + }; + ++ file_name = "@TERMUX_PREFIX@/bin/env"; ++ + // According to `man 2 execve`: + // + // The kernel imposes a maximum length on the text