diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2021-08-05 10:33:42 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2021-08-10 13:40:39 +0200 |
| commit | 049ff45430f7d556d1c6947c0bc44f3df67a8b00 (patch) | |
| tree | 751aa2f9481ac12b00e3c5b0ab21591db92719d9 /src/link | |
| parent | f2bf1390a29a9decaa5ca49d3ae720b360583b35 (diff) | |
| download | zig-049ff45430f7d556d1c6947c0bc44f3df67a8b00.tar.gz zig-049ff45430f7d556d1c6947c0bc44f3df67a8b00.zip | |
macho: add basic support for building iOS binaries
* ensure we correctly transfer `-iwithsysroot` and
`-iframeworkwithsysroot` flags with values from `build.zig` and that
they are correctly transferred forward to `zig cc`
* try to look for `libSystem.tbd` in the provided syslibroot - one
caveat that the user will have to specify library search paths too
Diffstat (limited to 'src/link')
| -rw-r--r-- | src/link/MachO.zig | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 5d9b0e6fe1..6b0710129f 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -794,15 +794,14 @@ fn linkWithZld(self: *MachO, comp: *Compilation) !void { } } - // If we're compiling native and we can find libSystem.B.{dylib, tbd}, - // we link against that instead of embedded libSystem.B.tbd file. - var native_libsystem_available = false; - if (self.base.options.is_native_os) blk: { + // If we were given the sysroot, try to look there first for libSystem.B.{dylib, tbd}. + var libsystem_available = false; + if (self.base.options.sysroot != null) blk: { // Try stub file first. If we hit it, then we're done as the stub file // re-exports every single symbol definition. if (try resolveLib(arena, lib_dirs.items, "System", ".tbd")) |full_path| { try libs.append(full_path); - native_libsystem_available = true; + libsystem_available = true; break :blk; } // If we didn't hit the stub file, try .dylib next. However, libSystem.dylib @@ -811,12 +810,12 @@ fn linkWithZld(self: *MachO, comp: *Compilation) !void { if (try resolveLib(arena, lib_dirs.items, "c", ".dylib")) |libc_path| { try libs.append(libsystem_path); try libs.append(libc_path); - native_libsystem_available = true; + libsystem_available = true; break :blk; } } } - if (!native_libsystem_available) { + if (!libsystem_available) { const full_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "darwin", "libSystem.B.tbd", }); @@ -841,7 +840,7 @@ fn linkWithZld(self: *MachO, comp: *Compilation) !void { break; } } else { - log.warn("framework not found for '-f{s}'", .{framework}); + log.warn("framework not found for '-framework {s}'", .{framework}); framework_not_found = true; } } @@ -901,10 +900,8 @@ fn linkWithZld(self: *MachO, comp: *Compilation) !void { try argv.append("-o"); try argv.append(full_out_path); - if (native_libsystem_available) { - try argv.append("-lSystem"); - try argv.append("-lc"); - } + try argv.append("-lSystem"); + try argv.append("-lc"); for (search_lib_names.items) |l_name| { try argv.append(try std.fmt.allocPrint(arena, "-l{s}", .{l_name})); @@ -914,6 +911,14 @@ fn linkWithZld(self: *MachO, comp: *Compilation) !void { try argv.append(try std.fmt.allocPrint(arena, "-L{s}", .{lib_dir})); } + for (self.base.options.frameworks) |framework| { + try argv.append(try std.fmt.allocPrint(arena, "-framework {s}", .{framework})); + } + + for (self.base.options.framework_dirs) |framework_dir| { + try argv.append(try std.fmt.allocPrint(arena, "-F{s}", .{framework_dir})); + } + Compilation.dump_argv(argv.items); } |
