Skip to content

Commit

Permalink
some fixes:
Browse files Browse the repository at this point in the history
* target: macOS arm64 support
* target: wasm32/64 support
* disable mcpu command (zig build is native by default)
  • Loading branch information
kassane committed Jan 6, 2024
1 parent c8f1053 commit 1b0c50b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 6 additions & 4 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -479,16 +479,18 @@ fn buildLDC(b: *Builder, lib: *CompileStep, config: ldcConfig) !*RunStep {

// link-time optimization
if (lib.want_lto) |enabled|
if (enabled) try cmds.append("--flto=thin");
if (enabled) try cmds.append("--flto=full");

// ldc2 doesn't support zig native (a.k.a: native-native or native)
if (lib.rootModuleTarget().isDarwin())
try cmds.append(b.fmt("--mtriple={s}-apple-{s}", .{ @tagName(lib.rootModuleTarget().cpu.arch), @tagName(lib.rootModuleTarget().os.tag) }))
try cmds.append(b.fmt("--mtriple={s}-apple-{s}", .{ if (lib.rootModuleTarget().cpu.arch.isAARCH64()) "arm64" else @tagName(lib.rootModuleTarget().cpu.arch), @tagName(lib.rootModuleTarget().os.tag) }))
else if (lib.rootModuleTarget().isWasm())
try cmds.append(b.fmt("--mtriple={s}-unknown-unknown-{s}", .{ @tagName(lib.rootModuleTarget().cpu.arch), @tagName(lib.rootModuleTarget().os.tag) }))
else
try cmds.append(b.fmt("--mtriple={s}-{s}-{s}", .{ @tagName(lib.rootModuleTarget().cpu.arch), @tagName(lib.rootModuleTarget().os.tag), @tagName(lib.rootModuleTarget().abi) }));

// cpu model (e.g. "generic")
try cmds.append(b.fmt("--mcpu={s}", .{lib.rootModuleTarget().cpu.model.name}));
// cpu model (e.g. "baseline")
// try cmds.append(b.fmt("--mcpu={s}", .{lib.rootModuleTarget().cpu.model.name}));
// output file
try cmds.append(b.fmt("--of={s}", .{b.pathJoin(&.{ b.install_prefix, "bin", config.name orelse "d_binary" })}));

Expand Down
7 changes: 6 additions & 1 deletion tools/zigcc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@ pub fn main() !void {
// LDC2 not setting triple targets on host build to cc/linker, except Apple (why?)
var isNative = true;
while (args.next()) |arg| {
if (std.mem.eql(u8, arg, std.fmt.comptimePrint("{s}-apple-{s}", .{ @tagName(builtin.cpu.arch), @tagName(builtin.os.tag) }))) {
// MacOS M1/M2 on ldc2 replace aarch64 to arm64 - (TODO: fix?)
if (std.mem.eql(u8, arg, std.fmt.comptimePrint("{s}-apple-{s}", .{ if (builtin.cpu.arch.isAARCH64()) "arm64" else @tagName(builtin.cpu.arch), @tagName(builtin.os.tag) }))) {
try cmds.append("native-native");
try cmds.append("-fapple-link-rtlib");
} else if (std.mem.eql(u8, arg, std.fmt.comptimePrint("{s}-unknown-unknown-{s}", .{ @tagName(builtin.cpu.arch), @tagName(builtin.os.tag) }))) {
// wasm32 or wasm64
try cmds.append(std.fmt.comptimePrint("{s}-emscripten", .{@tagName(builtin.cpu.arch)}));
} else if (std.mem.eql(u8, arg, "-target")) {
isNative = false;
try cmds.append(arg); // get "-target" flag
} else {
try cmds.append(arg);
}
}
// Why native? See: https://github.com/kassane/sokol-d/issues/1
if (isNative) {
try cmds.append("-target");
if (builtin.os.tag == .windows)
Expand Down

0 comments on commit 1b0c50b

Please sign in to comment.