From 80933723efe9bf840fe749b0bfc0d610f1db1669 Mon Sep 17 00:00:00 2001 From: Sage Hane Date: Fri, 12 Dec 2025 17:04:44 +0900 Subject: [PATCH] chore: Update Zig to 0.15.2 --- build.zig.zon | 2 +- example/build.zig | 8 ++- example/build.zig.zon | 2 +- example/src/main.zig | 25 ++++---- flake.lock | 135 +++++++++++++++++++++++++++++++++++++----- flake.nix | 54 +++++++---------- 6 files changed, 163 insertions(+), 63 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index 6fc86a3..ca83b9d 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -2,7 +2,7 @@ .name = .zig_tracy, .fingerprint = 0x1c9150cfb12ae268, .version = "0.0.5", - .minimum_zig_version = "0.14.1", + .minimum_zig_version = "0.15.2", .paths = .{ "build.zig", "build.zig.zon", diff --git a/example/build.zig b/example/build.zig index 06dc682..cb11520 100644 --- a/example/build.zig +++ b/example/build.zig @@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "tracy-example", - .root_source_file = b.path("src/main.zig"), - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }), }); exe.root_module.addImport("tracy", tracy.module("tracy")); exe.linkLibrary(tracy.artifact("tracy")); diff --git a/example/build.zig.zon b/example/build.zig.zon index c5e0c54..dcc7fc9 100644 --- a/example/build.zig.zon +++ b/example/build.zig.zon @@ -2,7 +2,7 @@ .name = .zig_tracy_example, .fingerprint = 0xe9dd79ab1e600c1e, .version = "0.0.2", - .minimum_zig_version = "0.14.1", + .minimum_zig_version = "0.15.2", .paths = .{ "build.zig", "build.zig.zon", diff --git a/example/src/main.zig b/example/src/main.zig index fae5f4a..835fdcf 100644 --- a/example/src/main.zig +++ b/example/src/main.zig @@ -3,7 +3,7 @@ const tracy = @import("tracy"); var finalise_threads: std.Thread.ResetEvent = .{}; -fn handleSigInt(_: c_int) callconv(.C) void { +export fn handleSigInt(_: c_int) void { finalise_threads.set(); } @@ -13,7 +13,7 @@ pub fn main() !void { std.posix.sigaction(std.posix.SIG.INT, &.{ .handler = .{ .handler = handleSigInt }, - .mask = std.posix.empty_sigset, + .mask = std.posix.sigemptyset(), .flags = 0, }, null); @@ -25,7 +25,7 @@ pub fn main() !void { const zone = tracy.initZone(@src(), .{ .name = "Important work" }); defer zone.deinit(); - std.time.sleep(100); + std.Thread.sleep(100); } } @@ -39,26 +39,31 @@ fn otherThread() void { defer arena.deinit(); var tracing_allocator = tracy.TracingAllocator.initNamed("arena", arena.allocator()); + const allocator = tracing_allocator.allocator(); - var stack = std.ArrayList(u8).init(tracing_allocator.allocator()); - defer stack.deinit(); + var stack = std.ArrayList(u8).empty; + defer stack.deinit(allocator); - const stdin = std.io.getStdIn().reader(); - const stdout = std.io.getStdOut().writer(); + const stdin = std.fs.File.stdin().deprecatedReader(); + + var stdout_buffer: [1024]u8 = undefined; + var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); + const stdout = &stdout_writer.interface; while (!finalise_threads.isSet()) { const zone = tracy.initZone(@src(), .{ .name = "IO loop" }); defer zone.deinit(); stdout.print("Enter string: ", .{}) catch break; + stdout.flush() catch break; const stream_zone = tracy.initZone(@src(), .{ .name = "Writer.streamUntilDelimiter" }); - stdin.streamUntilDelimiter(stack.writer(), '\n', null) catch break; + stdin.streamUntilDelimiter(stack.writer(allocator), '\n', null) catch break; stream_zone.deinit(); const toowned_zone = tracy.initZone(@src(), .{ .name = "ArrayList.toOwnedSlice" }); - const str = stack.toOwnedSlice() catch break; - defer tracing_allocator.allocator().free(str); + const str = stack.toOwnedSlice(allocator) catch break; + defer allocator.free(str); toowned_zone.deinit(); const reverse_zone = tracy.initZone(@src(), .{ .name = "std.mem.reverse" }); diff --git a/flake.lock b/flake.lock index 22493f2..e769a3e 100644 --- a/flake.lock +++ b/flake.lock @@ -1,35 +1,142 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1691368598, - "narHash": "sha256-ia7li22keBBbj02tEdqjVeLtc7ZlSBuhUk+7XTUFr14=", - "path": "/nix/store/631cgbs310h1rcix7zs171xzx7p2y97g-source", - "rev": "5a8e9243812ba528000995b294292d3b5e120947", - "type": "path" + "lastModified": 1765425892, + "narHash": "sha256-jlQpSkg2sK6IJVzTQBDyRxQZgKADC2HKMRfGCSgNMHo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5d6bdbddb4695a62f0d00a3620b37a15275a5093", + "type": "github" }, "original": { "id": "nixpkgs", "type": "indirect" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1708161998, + "narHash": "sha256-6KnemmUorCvlcAvGziFosAVkrlWZGIc6UNT9GUYr0jQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "84d981bae8b5e783b3b548de505b22880559515f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { + "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", - "zig-source": "zig-source" + "zig-overlay": "zig-overlay" } }, - "zig-source": { - "flake": false, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "zig-overlay": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, "locked": { - "lastModified": 1712150963, - "narHash": "sha256-dMfSyQckPok5AyNeMWyJzSq6ow+K5GCoKiyt9tM1UdM=", - "type": "tarball", - "url": "https://ziglang.org/builds/zig-linux-x86_64-0.12.0-dev.3522%2Bb88ae8dbd.tar.xz" + "lastModified": 1764203689, + "narHash": "sha256-ivb0SqCptyIxx5g8ryRrUL0xrJhLrJPlvZbZjxVaui0=", + "owner": "mitchellh", + "repo": "zig-overlay", + "rev": "8f7347545dea59b75e40247cc1ed55a42f64dbbf", + "type": "github" }, "original": { - "type": "tarball", - "url": "https://ziglang.org/builds/zig-linux-x86_64-0.12.0-dev.3522%2Bb88ae8dbd.tar.xz" + "owner": "mitchellh", + "repo": "zig-overlay", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 36099fc..9ae94fb 100644 --- a/flake.nix +++ b/flake.nix @@ -2,46 +2,32 @@ description = "zig-tracy development environment"; inputs = { - zig-source = { - url = "https://ziglang.org/builds/zig-linux-x86_64-0.12.0-dev.3522+b88ae8dbd.tar.xz"; - flake = false; - }; + flake-utils.url = "github:numtide/flake-utils"; + zig-overlay.url = "github:mitchellh/zig-overlay"; }; outputs = { self, nixpkgs, - zig-source + flake-utils, + zig-overlay }: let - default_system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${default_system}; - zig_0_12_0_rc = pkgs.stdenv.mkDerivation rec { - pname = "zig"; - version = "0.12.0-dev.3522+b88ae8dbd"; - src = zig-source.outPath; + # https://github.com/mitchellh/zig-overlay/blob/a13f8e3f83ce51411d079579f28acb20472443f8/flake.nix#L21 + systems = builtins.attrNames zig-overlay.packages; + in + flake-utils.lib.eachSystem systems ( + system: let + pkgs = nixpkgs.legacyPackages.${system}; + zigpkgs = zig-overlay.packages.${system}; + in rec { + devShells.default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + zigpkgs."0.15.2" - installPhase = '' - mkdir -p "$out/bin" - cp zig "$out/bin" - cp -r lib "$out" - cp -r doc "$out" - ''; - - meta = with pkgs.lib; { - homepage = "https://ziglang.org/"; - description = "General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software"; - license = licenses.mit; - platforms = platforms.unix; - }; - }; - in { - devShell.${default_system} = pkgs.mkShell { - nativeBuildInputs = [ - zig_0_12_0_rc - pkgs.lldb_16 - ]; - }; - }; + lldb + ]; + }; + } + ); } -