...
This commit is contained in:
23
src/main.zig
23
src/main.zig
@@ -46,9 +46,9 @@ pub fn main(init: std.process.Init) !void {
|
||||
else if (std.mem.eql(u8, raw, "wasm64"))
|
||||
"wasm64-unknown-emscripten"
|
||||
else if (std.mem.eql(u8, raw, "macos") or std.mem.eql(u8, raw, "macos-arm"))
|
||||
"aarch64-apple-macos"
|
||||
try macosTripleForArch(allocator, "aarch64")
|
||||
else if (std.mem.eql(u8, raw, "macos-x86"))
|
||||
"x86_64-apple-macos"
|
||||
try macosTripleForArch(allocator, "x86_64")
|
||||
else if (std.mem.eql(u8, raw, "linux") or std.mem.eql(u8, raw, "linux-x86"))
|
||||
"x86_64-unknown-linux-gnu"
|
||||
else if (std.mem.eql(u8, raw, "linux-arm"))
|
||||
@@ -182,6 +182,7 @@ pub fn main(init: std.process.Init) !void {
|
||||
};
|
||||
|
||||
if (std.mem.eql(u8, command, "build")) {
|
||||
target_config.is_aot = true;
|
||||
const output_name = target_config.output_path orelse blk: {
|
||||
const base = deriveOutputName(path);
|
||||
if (target_config.isEmscripten()) {
|
||||
@@ -321,6 +322,24 @@ fn compileCForBuild(allocator: std.mem.Allocator, io: std.Io, comp: *sx.core.Com
|
||||
return try sx.c_import.writeCObjectFiles(allocator, io, obj_bufs, tmp_dir);
|
||||
}
|
||||
|
||||
/// Build an Apple Darwin triple for `arch` (e.g. "aarch64" / "x86_64") using
|
||||
/// the host's OS version suffix from `LLVMGetDefaultTargetTriple()`. Without
|
||||
/// the version suffix, the emitted object file carries no platform load
|
||||
/// command and `ld` warns "no platform load command found ... assuming: macOS".
|
||||
/// Falls back to "darwin" if the host triple doesn't start with darwin (e.g.
|
||||
/// when sx is cross-built on Linux for macOS).
|
||||
fn macosTripleForArch(allocator: std.mem.Allocator, arch: []const u8) ![]const u8 {
|
||||
const host = sx.llvm_api.c.LLVMGetDefaultTargetTriple();
|
||||
defer sx.llvm_api.c.LLVMDisposeMessage(host);
|
||||
const span = std.mem.span(host);
|
||||
var it = std.mem.splitScalar(u8, span, '-');
|
||||
_ = it.next();
|
||||
_ = it.next();
|
||||
const os_part = it.next() orelse "darwin";
|
||||
const os_suffix = if (std.mem.startsWith(u8, os_part, "darwin")) os_part else "darwin";
|
||||
return std.fmt.allocPrint(allocator, "{s}-apple-{s}", .{ arch, os_suffix });
|
||||
}
|
||||
|
||||
fn parseOptLevel(s: []const u8) ?sx.target.TargetConfig.OptLevel {
|
||||
if (std.mem.eql(u8, s, "none") or std.mem.eql(u8, s, "0")) return .none;
|
||||
if (std.mem.eql(u8, s, "less") or std.mem.eql(u8, s, "1")) return .less;
|
||||
|
||||
Reference in New Issue
Block a user