diff --git a/build.zig b/build.zig index 89a2117..d40d10a 100644 --- a/build.zig +++ b/build.zig @@ -436,6 +436,7 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*RunStep { // C include path for (lib_sokol.root_module.include_dirs.items) |include_dir| { + if (include_dir == .other_step) continue; const path = if (include_dir == .path) include_dir.path.getPath(b) else if (include_dir == .path_system) @@ -513,6 +514,8 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*RunStep { b.fmt("{s}-apple-{s}", .{ if (options.target.result.cpu.arch.isAARCH64()) "arm64" else @tagName(options.target.result.cpu.arch), @tagName(options.target.result.os.tag) }) else if (options.target.result.isWasm()) b.fmt("{s}-unknown-unknown-wasm", .{@tagName(options.target.result.cpu.arch)}) + else if (options.target.result.isWasm() and options.target.result.os.tag == .wasi) + b.fmt("{s}-unknown-{s}", .{ @tagName(options.target.result.cpu.arch), @tagName(options.target.result.os.tag) }) else b.fmt("{s}-{s}-{s}", .{ @tagName(options.target.result.cpu.arch), @tagName(options.target.result.os.tag), @tagName(options.target.result.abi) }); diff --git a/src/examples/mrt.d b/src/examples/mrt.d index 0d74933..a67e389 100644 --- a/src/examples/mrt.d +++ b/src/examples/mrt.d @@ -232,10 +232,11 @@ void frame() sg.beginPass(state.offscreen.pass, state.offscreen.pass_action); sg.applyPipeline(state.offscreen.pip); sg.applyBindings(state.offscreen.bind); + auto offs_rg = sgutil.asRange(offscreen_params); sg.applyUniforms( sg.ShaderStage.Vs, shd.SLOT_OFFSCREEN_PARAMS, - sgutil.asRange(offscreen_params), + offs_rg, ); sg.draw(0, 36, 1); sg.endPass(); @@ -245,7 +246,8 @@ void frame() sg.beginDefaultPass(state.dflt.pass_action, app.width(), app.height()); sg.applyPipeline(state.fsq.pip); sg.applyBindings(state.fsq.bind); - sg.applyUniforms(sg.ShaderStage.Vs, shd.SLOT_FSQ_PARAMS, sgutil.asRange(fsq_params)); + auto fsq_rg = sgutil.asRange(fsq_params); + sg.applyUniforms(sg.ShaderStage.Vs, shd.SLOT_FSQ_PARAMS, fsq_rg); sg.draw(0, 4, 1); sg.applyPipeline(state.dbg.pip); foreach(i;[0,1,2]) { diff --git a/src/handmade/math.d b/src/handmade/math.d index 987ab26..7eedd3d 100644 --- a/src/handmade/math.d +++ b/src/handmade/math.d @@ -10,17 +10,28 @@ module handmade.math; extern(C): -enum real PI = 0x1.921fb54442d18469898cc51701b84p+1L; -double zig_sqrt(double value) @nogc nothrow @trusted; -double zig_sqrtf(double value) @nogc nothrow @trusted; -double zig_cos(double value) @nogc nothrow @trusted; -double zig_sin(double value) @nogc nothrow @trusted; -double zig_tan(double value) @nogc nothrow @trusted; -alias sqrt = zig_sqrt; -alias sqrtf = zig_sqrtf; -alias cos = zig_cos; -alias sin = zig_sin; -alias tan = zig_tan; +version(WebAssembly){ + enum PI = 3.14159265358979323846264338327950288419716939937510; + double zig_sqrt(ulong value) @nogc nothrow @trusted; + double zig_sqrtf(double value) @nogc nothrow @trusted; + double zig_cos(double value) @nogc nothrow @trusted; + double zig_sin(double value) @nogc nothrow @trusted; + double zig_tan(double value) @nogc nothrow @trusted; + alias cos = zig_cos; + alias sin = zig_sin; + alias tan = zig_tan; + + auto sqrt(T)(T value){ + static if(is(T == double) || is(T == float)){ + return zig_sqrtf(value); + } else { + return zig_sqrt(value); + } + } +} else { + public import core.stdc.math: sqrt, cos, sin, tan; + public import std.math: PI; +} @safe: diff --git a/tools/zigcc.zig b/tools/zigcc.zig index 99ddc75..de5ed4c 100644 --- a/tools/zigcc.zig +++ b/tools/zigcc.zig @@ -21,20 +21,23 @@ pub fn main() !void { try cmds.append("zig"); try cmds.append("cc"); - if (builtin.os.tag != .windows) + if (builtin.os.tag != .windows) { // not working on msvc target (nostdlib++) try cmds.append("-lunwind"); + } // LDC2 not setting triple targets on host build to cc/linker, except Apple (why?) var isNative = true; while (args.next()) |arg| { - // MacOS M1/M2 on ldc2 replace aarch64 to arm64 - (TODO: fix?) + // MacOS M1/M2 target, replace aarch64 to arm64 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, std.fmt.comptimePrint("{s}-unknown-{s}", .{ @tagName(builtin.cpu.arch), @tagName(builtin.os.tag) }))) { + try cmds.append(std.fmt.comptimePrint("{s}-{s}", .{ @tagName(builtin.cpu.arch), @tagName(builtin.os.tag) })); } else if (std.mem.eql(u8, arg, "-target")) { isNative = false; try cmds.append(arg); // get "-target" flag