From 900fa1dcbcdfe789222a9cb0cd7f3f9c1b33380d Mon Sep 17 00:00:00 2001 From: Techatrix Date: Mon, 26 Oct 2026 01:31:15 +0100 Subject: [PATCH] update to Zig 0.17.0 --- README.md | 2 +- build.zig | 11 +++++------ build.zig.zon | 10 +++++----- src/workers/zig.ts | 8 ++++---- zig.patch | 21 --------------------- 5 files changed, 15 insertions(+), 37 deletions(-) delete mode 100644 zig.patch diff --git a/README.md b/README.md index a5779c5..120bc1d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ You can either: - Use it online: https://playground.zigtools.org/ - Run it locally: -Requires Zig `0.16.0`. Will automatically fetch Zig along with ZLS, compiling both for webassembly. +Requires Zig `0.17.0`. Will automatically fetch Zig along with ZLS, compiling both for webassembly. ```bash zig build -Drelease diff --git a/build.zig b/build.zig index 0905b96..b71e615 100644 --- a/build.zig +++ b/build.zig @@ -2,7 +2,7 @@ const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }); - const optimize: std.builtin.OptimizeMode = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseSmall }); + const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .small }); const enable_wasm_opt = b.option(bool, "wasm-opt", "Run wasm-opt") orelse false; @@ -40,14 +40,13 @@ pub fn build(b: *std.Build) void { const zig_dependency = b.dependency("zig", .{ .target = target, .optimize = optimize, - .@"version-string" = @as([]const u8, "0.16.0"), + .@"version-string" = @as([]const u8, "0.17.0"), .@"no-lib" = true, .dev = "wasm", }); zig_step.dependOn(installArtifact(b, zig_dependency.artifact("zig"), enable_wasm_opt)); - const lib_compiler_rt = b.addLibrary(.{ - .linkage = .static, + const lib_compiler_rt = b.addObject(.{ .name = "compiler_rt", .root_module = b.createModule(.{ .root_source_file = zig_dependency.path("lib/compiler_rt.zig"), @@ -58,7 +57,7 @@ pub fn build(b: *std.Build) void { compiler_rt_step.dependOn(&b.addInstallArtifact(lib_compiler_rt, .{ .dest_dir = .{ .override = .prefix } }).step); const run_tar = b.addSystemCommand(&.{ "tar", "-czf" }); - const zig_tar_gz = run_tar.addOutputFileArg("zig.tar.gz"); + const zig_tar_gz = run_tar.addOutputFileArg2("zig.tar.gz", .{}); tarball_step.dependOn(&b.addInstallFile(zig_tar_gz, "zig.tar.gz").step); run_tar.addArg("-C"); run_tar.addDirectoryArg(zig_dependency.path(".")); @@ -78,7 +77,7 @@ fn installArtifact(b: *std.Build, artifact: *std.Build.Step.Compile, enable_wasm wasm_opt.addArtifactArg(artifact); wasm_opt.addArg("-o"); const file_name = b.fmt("{s}.wasm", .{artifact.name}); - const exe = wasm_opt.addOutputFileArg(file_name); + const exe = wasm_opt.addOutputFileArg2(file_name, .{}); return &b.addInstallBinFile(exe, file_name).step; } else { return &b.addInstallArtifact(artifact, .{}).step; diff --git a/build.zig.zon b/build.zig.zon index 1d611db..207d69f 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -2,15 +2,15 @@ .name = .playground, .version = "0.0.0", .fingerprint = 0xdc188848360fd988, // Changing this has security and trust implications. - .minimum_zig_version = "0.16.0", + .minimum_zig_version = "0.17.0", .dependencies = .{ .zls = .{ - .url = "git+https://github.com/zigtools/zls?ref=0.16.0#494486203c3a48927f2383aa3d5ce5fca112186d", - .hash = "zls-0.16.0-rmm5fs_JJgBG3dk5HwYK1FylE2_LMN0BYpX57tPzT-Xc", + .url = "git+https://github.com/zigtools/zls?ref=0.17.0#542462c4ddf045493fa9ca028ee6bc3f38b2754a", + .hash = "zls-0.17.0-rmm5fjYwHAAfoBoodSZ8k3NYPa8ZZG60JPlOTGFrAhTw", }, .zig = .{ - .url = "git+https://github.com/zigtools/zig?ref=wasm32-wasi#1c430bc130989d285723de8b7aa8e3c77297a266", - .hash = "zig-0.0.0-Fp4XJHzK5Q2xL7r676PlbSvBhz_af_mGXkGPVaXvf_Kx", + .url = "git+https://codeberg.org/ziglang/zig?ref=0.17.0#7647adab80dd088f4de3610fd245915a912eb6ad", + .hash = "zig-0.0.0-Fp4XJNPbSg7JHi19U9bkBViqpw1CEGENf1JhYBLHWjMq", }, }, .paths = .{""}, diff --git a/src/workers/zig.ts b/src/workers/zig.ts index 58327bf..ba3ce1b 100644 --- a/src/workers/zig.ts +++ b/src/workers/zig.ts @@ -8,15 +8,15 @@ async function run(source: string) { currentlyRunning = true; const libDirectory = await getLatestZigArchive(); - const libCompilerRt = await fetch(new URL("../../zig-out/libcompiler_rt.a", import.meta.url)); + const compilerRtObject = await fetch(new URL("../../zig-out/compiler_rt.o", import.meta.url)); const args = [ "zig.wasm", "build-exe", "main.zig", - "libcompiler_rt.a", + "compiler_rt.o", "-fno-compiler-rt", // manually linked because the self hosted webassembly backend cannot compile it by itself - "-fno-entry", // prevent the native webassembly backend from adding a start function to the module + "-fno-ubsan-rt", ]; const env: string[] = []; const fds = [ @@ -25,7 +25,7 @@ async function run(source: string) { stderrOutput(), // stderr new PreopenDirectory(".", new Map([ ["main.zig", new File(new TextEncoder().encode(source))], - ["libcompiler_rt.a", new File(await libCompilerRt.arrayBuffer())] + ["compiler_rt.o", new File(await compilerRtObject.arrayBuffer())] ])), new PreopenDirectory("/lib", libDirectory.contents), new PreopenDirectory("/cache", new Map()), diff --git a/zig.patch b/zig.patch deleted file mode 100644 index 10cbb64..0000000 --- a/zig.patch +++ /dev/null @@ -1,21 +0,0 @@ -diff --git a/src/dev.zig b/src/dev.zig -index f4be5a36..ae4e914b 100644 ---- a/src/dev.zig -+++ b/src/dev.zig -@@ -150,12 +150,13 @@ pub const Env = enum { - else => Env.sema.supports(feature), - }, - .wasm => switch (feature) { -- .stdio_listen, -- .incremental, - .wasm_backend, - .wasm_linker, -+ .build_exe_command, -+ .sema, -+ .ast_gen, - => true, -- else => Env.sema.supports(feature), -+ else => false, - }, - }; - }