Skip to content

Commit

Permalink
fix(main/zig): fix missing dynamic linker and libc runtime
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mbekkomo committed Dec 17, 2024
1 parent aa8e0e8 commit e35c1ea
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/zig/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
107 changes: 107 additions & 0 deletions packages/zig/zig-lib-std-zig-LibCInstallation.zig.patch
Original file line number Diff line number Diff line change
@@ -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;
}

13 changes: 13 additions & 0 deletions packages/zig/zig-lib-std-zig-system.zig.patch
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e35c1ea

Please sign in to comment.