ios: framework embedding in .app + -F search paths
- `-F <dir>` CLI flag adds Apple framework search paths (parallel to `-L`). - `TargetConfig.framework_paths` flows into the iOS link line (`-F<dir>`). - iOS link adds `-Wl,-rpath,@executable_path/Frameworks` so embedded frameworks resolve at runtime. - `createBundle` now takes the framework list; for each one it locates `<name>.framework` in the `-F` paths and `cp -R`s it into `<bundle>.app/Frameworks/`. - `c_import.compileCToObjects` forwards `-target`/`-isysroot` to clang so `#c_import` works under cross-compile (was using host clang implicitly). - iOS SDK is auto-discovered once at startup and shared by both the C compile and the link paths. - `SX_DEBUG_LINK=1` prints the resolved link argv. - `library/modules/sdl3.sx`: drop `#library "SDL3"` — linking is now per-target (build.sx handles `-lSDL3` on macOS, `-framework SDL3` on iOS).
This commit is contained in:
23
src/main.zig
23
src/main.zig
@@ -27,6 +27,7 @@ pub fn main(init: std.process.Init) !void {
|
||||
var input_path: ?[]const u8 = null;
|
||||
var target_config = sx.target.TargetConfig{};
|
||||
var lib_paths = std.ArrayList([]const u8).empty;
|
||||
var framework_paths = std.ArrayList([]const u8).empty;
|
||||
var link_flags = std.ArrayList([]const u8).empty;
|
||||
var show_timing: bool = false;
|
||||
var explicit_opt: bool = false;
|
||||
@@ -119,6 +120,14 @@ pub fn main(init: std.process.Init) !void {
|
||||
if (i >= args.len) { std.debug.print("error: -L requires a value\n", .{}); return; }
|
||||
try lib_paths.append(allocator, args[i]);
|
||||
}
|
||||
} else if (std.mem.startsWith(u8, arg, "-F")) {
|
||||
if (arg.len > 2) {
|
||||
try framework_paths.append(allocator, arg[2..]);
|
||||
} else {
|
||||
i += 1;
|
||||
if (i >= args.len) { std.debug.print("error: -F requires a value\n", .{}); return; }
|
||||
try framework_paths.append(allocator, args[i]);
|
||||
}
|
||||
} else if (std.mem.eql(u8, arg, "--lflags")) {
|
||||
i += 1;
|
||||
if (i >= args.len) { std.debug.print("error: --lflags requires a value\n", .{}); return; }
|
||||
@@ -132,8 +141,16 @@ pub fn main(init: std.process.Init) !void {
|
||||
}
|
||||
|
||||
target_config.lib_paths = try lib_paths.toOwnedSlice(allocator);
|
||||
target_config.framework_paths = try framework_paths.toOwnedSlice(allocator);
|
||||
target_config.extra_link_flags = try link_flags.toOwnedSlice(allocator);
|
||||
|
||||
// Auto-discover iOS SDK once so both the C compile path and the link
|
||||
// path see the same sysroot. Honors any explicit --sysroot.
|
||||
if (target_config.isIOS() and target_config.sysroot == null) {
|
||||
const sdk_name: []const u8 = if (target_config.isIOSSimulator()) "iphonesimulator" else "iphoneos";
|
||||
target_config.sysroot = sx.target.discoverAppleSdk(allocator, io, sdk_name) catch null;
|
||||
}
|
||||
|
||||
const path = input_path orelse {
|
||||
printUsage();
|
||||
return;
|
||||
@@ -261,7 +278,7 @@ fn compileCForJIT(allocator: std.mem.Allocator, io: std.Io, comp: *sx.core.Compi
|
||||
const c_infos = try comp.collectCImportSources();
|
||||
if (c_infos.len == 0) return .{ .allocator = allocator };
|
||||
|
||||
const obj_bufs = try sx.c_import.compileCToObjects(allocator, c_infos);
|
||||
const obj_bufs = try sx.c_import.compileCToObjects(allocator, c_infos, comp.target_config);
|
||||
return try sx.c_import.loadCObjectsForJIT(allocator, io, obj_bufs);
|
||||
}
|
||||
|
||||
@@ -275,7 +292,7 @@ fn compileCForBuild(allocator: std.mem.Allocator, io: std.Io, comp: *sx.core.Com
|
||||
return try sx.c_import.compileCWithEmcc(allocator, io, c_infos, comp.target_config, tmp_dir);
|
||||
}
|
||||
|
||||
const obj_bufs = try sx.c_import.compileCToObjects(allocator, c_infos);
|
||||
const obj_bufs = try sx.c_import.compileCToObjects(allocator, c_infos, comp.target_config);
|
||||
return try sx.c_import.writeCObjectFiles(allocator, io, obj_bufs, tmp_dir);
|
||||
}
|
||||
|
||||
@@ -561,7 +578,7 @@ fn compileWithTimer(allocator: std.mem.Allocator, io: std.Io, input_path: []cons
|
||||
// Wrap into a .app bundle if requested (iOS/macOS).
|
||||
if (merged_config.bundle_path) |bp| {
|
||||
timer.mark();
|
||||
sx.target.createBundle(allocator, io, final_output, merged_config) catch std.process.exit(1);
|
||||
sx.target.createBundle(allocator, io, final_output, merged_config, fws) catch std.process.exit(1);
|
||||
timer.record("bundle");
|
||||
std.debug.print("bundled: {s}\n", .{bp});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user