refactor: remove depcreated zig feature

This commit is contained in:
Nurul Huda (Apon) 2026-05-31 13:40:16 +06:00
parent c10b97bb32
commit 50b1f197f3
No known key found for this signature in database
GPG Key ID: 5D3F1DE2855A2F79
23 changed files with 69 additions and 49 deletions

View File

@ -14,8 +14,8 @@
},
// httpz - HTTP server for Ziex
.httpz = .{
.url = "git+https://github.com/karlseguin/http.zig.git#744c588608d2b13e6dba2013577b2e0928877f19",
.hash = "httpz-0.0.0-PNVzrCzKCAAKOXAKsuPzDZYzstlou0FLBp3HlDoRgmUa",
.url = "git+https://github.com/karlseguin/http.zig.git?ref=dev#affbcc1bdedb03fc90a985c2f5c5dc65f7b42f5b",
.hash = "httpz-0.0.0-PNVzrILKCADcKBmMLyKYRo0XAUPVMeUvkOLpsdiSkH-I",
},
.adapters = .{ .path = "pkg/adapters" },
.zli = .{ .path = "vendor/cliz" }, // Get rid of this in favor of copying from Zig's new builtin args parser once 0.16.0 is released

View File

@ -12,12 +12,19 @@ pub fn build(b: *std.Build) void {
// Database - SQLite
{
const translate_c = b.addTranslateC(.{
.root_source_file = b.path("vendor/sqlite/sqlite3.h"),
.target = target,
.optimize = optimize,
});
const zqlite = b.createModule(.{
.root_source_file = b.path("vendor/zqlite/src/zqlite.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
zqlite.addImport("c", translate_c.createModule());
zqlite.addIncludePath(b.path("vendor/sqlite"));
const sqlite = b.addModule("db_sqlite", .{

View File

@ -124,7 +124,7 @@ fn open(_: *anyopaque, filename: ?[]const u8, options: db.OpenOptions) !db.Conne
errdefer ctx.deinit();
if (ctx.mode == .pooled) {
const path_z = try allocator.dupeZ(u8, path);
const path_z = try allocator.dupeSentinel(u8, path, 0);
defer allocator.free(path_z);
const pool_config = try allocator.create(PoolConnectionConfig);
@ -142,7 +142,7 @@ fn open(_: *anyopaque, filename: ?[]const u8, options: db.OpenOptions) !db.Conne
});
allocator.destroy(pool_config);
} else {
const path_z = try allocator.dupeZ(u8, path);
const path_z = try allocator.dupeSentinel(u8, path, 0);
defer allocator.free(path_z);
ctx.conn = try zqlite.open(path_z, flags);
@ -163,7 +163,7 @@ fn deserialize(_: *anyopaque, bytes: []const u8, options: db.OpenOptions) !db.Co
const path_copy = try allocator.dupe(u8, ":memory:");
errdefer allocator.free(path_copy);
const path_z = try allocator.dupeZ(u8, ":memory:");
const path_z = try allocator.dupeSentinel(u8, ":memory:", 0);
defer allocator.free(path_z);
ctx.* = .{

View File

@ -9,16 +9,29 @@ pub fn build(b: *std.Build) !void {
const lib_path = b.path("lib");
const translate_c = b.addTranslateC(.{
.root_source_file = b.path("lib/sqlite3.h"),
.target = target,
.optimize = optimize,
});
const mod_zqlite = b.addModule("zqlite", .{
.root_source_file = b.path("src/zqlite.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{
.name = "c",
.module = translate_c.createModule(),
}
},
});
const mod_sqlite = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
});
mod_sqlite.addIncludePath(lib_path);
mod_sqlite.addCSourceFile(.{

View File

@ -1,6 +1,6 @@
const std = @import("std");
const Io = std.Io;
const c = @cImport(@cInclude("sqlite3.h"));
pub const c = @import("c");
const zqlite = @import("zqlite.zig");
const Blob = zqlite.Blob;

View File

@ -1,5 +1,5 @@
const std = @import("std");
pub const c = @cImport(@cInclude("sqlite3.h"));
pub const c = @import("c");
pub const Pool = @import("pool.zig").Pool;

View File

@ -175,7 +175,7 @@ fn handleRunClick(ctx: zx.client.Event) void {
const inner_text: []const u8 = editor_container.ref.getAlloc(zx.Client.js.String, zx.allocator, "innerText") catch "NA";
std.log.info("Run clicked {s}", .{inner_text});
// const zx_sourcez = zx.allocator.dupeZ(u8, inner_text) catch return;
// const zx_sourcez = zx.allocator.dupeSentinel(u8, inner_text, 0) catch return;
// const ast = zx.Ast.parse(zx.allocator, zx_sourcez, .{}) catch return;
// c.log(.{zx.client.js.String(ast.zig_source)});
}

View File

@ -322,7 +322,7 @@ fn fetchStaticParams(io: std.Io, allocator: std.mem.Allocator, host: []const u8,
const response = aw.written();
if (response.len == 0 or std.mem.eql(u8, response, ".{}")) return .{ .items = &.{}, .allocator = null };
const response_z = try allocator.dupeZ(u8, response);
const response_z = try allocator.dupeSentinel(u8, response, 0);
defer allocator.free(response_z);
const parsed = std.zon.parse.fromSliceAlloc([]const []const zx.PageOptions.StaticParam, allocator, response_z, null, .{}) catch |err| {

View File

@ -203,7 +203,7 @@ fn formatFile(
);
defer allocator.free(source);
const source_z = try allocator.dupeZ(u8, source);
const source_z = try allocator.dupeSentinel(u8, source, 0);
defer allocator.free(source_z);
var format_result = try zx.Ast.fmt(allocator, source_z);
@ -271,7 +271,7 @@ fn formatDir(
);
defer allocator.free(source);
const source_z = try allocator.dupeZ(u8, source);
const source_z = try allocator.dupeSentinel(u8, source, 0);
defer allocator.free(source_z);
var format_result = try zx.Ast.fmt(allocator, source_z);

View File

@ -150,7 +150,7 @@ pub fn buildjs(ctx: zli.CommandContext, binpath: []const u8, is_dev: bool, verbo
const main_tsx_arg = package_json.main orelse "site/main.tsx";
defer ctx.allocator.free(outfile_arg);
const main_tsx_argz = try ctx.allocator.dupeZ(u8, main_tsx_arg);
const main_tsx_argz = try ctx.allocator.dupeSentinel(u8, main_tsx_arg, 0);
defer ctx.allocator.free(main_tsx_argz);
log.debug("Building main.tsx: in package.json: {s}", .{package_json.main orelse "na"});
@ -341,13 +341,13 @@ pub fn transform(
options: ?TransformOptions,
) !TransformResult {
// Ensure source is null-terminated
const source_z = try allocator.dupeZ(u8, source);
const source_z = try allocator.dupeSentinel(u8, source, 0);
defer allocator.free(source_z);
// Allocate file_path if provided, keep it alive during C call
var file_path_z: ?[:0]u8 = null;
if (file_path) |path| {
file_path_z = try allocator.dupeZ(u8, path);
file_path_z = try allocator.dupeSentinel(u8, path, 0);
}
defer if (file_path_z) |path_z| allocator.free(path_z);
@ -358,7 +358,7 @@ pub fn transform(
var target_z: ?[:0]u8 = null;
if (options) |opts| {
if (opts.target) |target| {
target_z = try allocator.dupeZ(u8, target);
target_z = try allocator.dupeSentinel(u8, target, 0);
}
c_options = transformjs_c.CTransformOptions{
.jsx_enabled = if (opts.jsx_enabled) 1 else 0,
@ -416,13 +416,13 @@ pub fn transformWithError(
options: ?TransformOptions,
) !struct { result: TransformResult, error_message: ?[]const u8 } {
// Ensure source is null-terminated
const source_z = try allocator.dupeZ(u8, source);
const source_z = try allocator.dupeSentinel(u8, source, 0);
defer allocator.free(source_z);
// Allocate file_path if provided, keep it alive during C call
var file_path_z: ?[:0]u8 = null;
if (file_path) |path| {
file_path_z = try allocator.dupeZ(u8, path);
file_path_z = try allocator.dupeSentinel(u8, path, 0);
}
defer if (file_path_z) |path_z| allocator.free(path_z);
@ -433,7 +433,7 @@ pub fn transformWithError(
var target_z: ?[:0]u8 = null;
if (options) |opts| {
if (opts.target) |target| {
target_z = try allocator.dupeZ(u8, target);
target_z = try allocator.dupeSentinel(u8, target, 0);
}
c_options = transformjs_c.CTransformOptions{
.jsx_enabled = if (opts.jsx_enabled) 1 else 0,

View File

@ -109,7 +109,7 @@ fn fileExists(io: std.Io, path: []const u8) bool {
fn readBuildMeta(io: std.Io, allocator: std.mem.Allocator, path: []const u8) !BuildMeta {
const source = try std.Io.Dir.cwd().readFileAlloc(io, path, allocator, .unlimited);
defer allocator.free(source);
const source_z = try allocator.dupeZ(u8, source);
const source_z = try allocator.dupeSentinel(u8, source, 0);
defer allocator.free(source_z);
return try std.zon.parse.fromSliceAlloc(BuildMeta, allocator, source_z, null, .{ .ignore_unknown_fields = true });
}

View File

@ -171,7 +171,7 @@ fn transpile(ctx: zli.CommandContext) !void {
const source = try std.Io.Dir.cwd().readFileAlloc(io, path, ctx.allocator, std.Io.Limit.limited(std.math.maxInt(usize)));
defer ctx.allocator.free(source);
const source_z = try ctx.allocator.dupeZ(u8, source);
const source_z = try ctx.allocator.dupeSentinel(u8, source, 0);
defer ctx.allocator.free(source_z);
// Parse and transpile
@ -928,7 +928,7 @@ fn genRoutes(allocator: std.mem.Allocator, output_dir: []const u8, rootdir: ?[]c
const meta_path = try std.fs.path.join(allocator, &.{ output_dir, "meta.zig" });
defer allocator.free(meta_path);
const content_z = try allocator.dupeZ(u8, content.written());
const content_z = try allocator.dupeSentinel(u8, content.written(), 0);
defer allocator.free(content_z);
var ast = try std.zig.Ast.parse(allocator, content_z, .zig);
defer ast.deinit(allocator);
@ -1289,7 +1289,7 @@ fn transpileFile(
);
defer allocator.free(source);
const source_z = try allocator.dupeZ(u8, source);
const source_z = try allocator.dupeSentinel(u8, source, 0);
defer allocator.free(source_z);
// Convert to relative path for deterministic component IDs and sourcemaps

View File

@ -14,7 +14,7 @@ pub fn fmt(allocator: std.mem.Allocator, source: [:0]const u8) !FmtResult {
}
const render_result = try parser_result.renderAlloc(arena, .{ .mode = .zx, .sourcemap = false, .path = null });
const formatted_sourcez = try allocator.dupeZ(u8, render_result.source);
const formatted_sourcez = try allocator.dupeSentinel(u8, render_result.source, 0);
return FmtResult{ .source = formatted_sourcez, .diagnostics = diagnostics };
}
@ -63,8 +63,8 @@ pub fn parse(gpa: std.mem.Allocator, zx_source: [:0]const u8, options: ParseOpti
errdefer diagnostics.deinit();
const render_result = try parse_result.renderAlloc(arena, .{ .mode = .zig, .sourcemap = options.map.enabled(), .path = options.path });
var zig_ast = try std.zig.Ast.parse(gpa, try arena.dupeZ(u8, render_result.source), .zig);
const zig_sourcez = try arena.dupeZ(u8, if (zig_ast.errors.len == 0) try zig_ast.renderAlloc(arena) else render_result.source);
var zig_ast = try std.zig.Ast.parse(gpa, try arena.dupeSentinel(u8, render_result.source, 0), .zig);
const zig_sourcez = try arena.dupeSentinel(u8, if (zig_ast.errors.len == 0) try zig_ast.renderAlloc(arena) else render_result.source, 0);
var components = std.ArrayList(ClientComponentMetadata).empty;
try components.ensureTotalCapacity(gpa, render_result.client_components.len);
@ -86,8 +86,8 @@ pub fn parse(gpa: std.mem.Allocator, zx_source: [:0]const u8, options: ParseOpti
return ParseResult{
.zig_ast = zig_ast,
.zx_source = try gpa.dupeZ(u8, render_result.source),
.zig_source = try gpa.dupeZ(u8, zig_sourcez),
.zx_source = try gpa.dupeSentinel(u8, render_result.source, 0),
.zig_source = try gpa.dupeSentinel(u8, zig_sourcez, 0),
.client_components = components,
.sourcemap = result_sourcemap,
.diagnostics = diagnostics,

View File

@ -40,7 +40,7 @@ pub fn extractBlocks(allocator: std.mem.Allocator, ast: *Ast) !ExtractBlockResul
try extractBlocksInner(ast, root, &blocks, &cleaned_source, allocator);
try cleaned_source.append(allocator, 0);
const cleaned = try allocator.dupeZ(u8, cleaned_source.items[0 .. cleaned_source.items.len - 1]);
const cleaned = try allocator.dupeSentinel(u8, cleaned_source.items[0 .. cleaned_source.items.len - 1], 0);
return ExtractBlockResult{
.zx_blocks = try blocks.toOwnedSlice(allocator),
@ -180,7 +180,7 @@ pub fn patchInBlocks(allocator: std.mem.Allocator, extract_result: ExtractBlockR
try result.append(allocator, 0);
const result_slice = result.items[0 .. result.items.len - 1 :0];
return try allocator.dupeZ(u8, result_slice);
return try allocator.dupeSentinel(u8, result_slice, 0);
}
fn getIndentationLevel(source: []const u8, pos: usize) u32 {
@ -236,7 +236,7 @@ pub fn renderNode(self: *Ast, node: ts.Node, w: *std.Io.Writer) !void {
// Free old zig_source and replace with formatted
allocator.free(extract_result.zig_source);
extract_result.zig_source = try allocator.dupeZ(u8, formatted_zig);
extract_result.zig_source = try allocator.dupeSentinel(u8, formatted_zig, 0);
// Patch in formatted zx_blocks
const final_result = try patchInBlocks(allocator, extract_result);

View File

@ -232,7 +232,7 @@ pub const Handler = struct {
const zig_uri = handler.getZlsUri(zx_uri);
const source_z = handler.allocator.dupeZ(u8, content) catch return;
const source_z = handler.allocator.dupeSentinel(u8, content, 0) catch return;
defer handler.allocator.free(source_z);
var parse_result = zx.Ast.parse(handler.allocator, source_z, .{}) catch null;
@ -254,7 +254,7 @@ pub const Handler = struct {
/// Store .zx file state and publish zx-specific diagnostics.
fn storeAndDiagnose(handler: *Handler, uri: []const u8, source: []const u8) void {
const source_z = handler.allocator.dupeZ(u8, source) catch return;
const source_z = handler.allocator.dupeSentinel(u8, source, 0) catch return;
defer handler.allocator.free(source_z);
var result = zx.Ast.parse(handler.allocator, source_z, .{}) catch return;
@ -836,7 +836,7 @@ pub const Handler = struct {
) error{OutOfMemory}!?[]const lsp.types.flat.TextEdit {
if (isZxUri(params.textDocument.uri)) {
if (handler.zx_files.get(params.textDocument.uri)) |state| {
const source_z = try handler.allocator.dupeZ(u8, state.source);
const source_z = try handler.allocator.dupeSentinel(u8, state.source, 0);
defer handler.allocator.free(source_z);
var format_result = zx.Ast.fmt(handler.allocator, source_z) catch |err| {

View File

@ -76,7 +76,7 @@ fn main_wasm(init: std.process.Init) !void {
// Transpile/Fmt file_path.zx and write with file_path.zig
for (files.items) |file_path| {
const zx_source = try cwd.readFileAlloc(init.io, file_path, allocator, .unlimited);
const zx_sourcez = try allocator.dupeZ(u8, zx_source);
const zx_sourcez = try allocator.dupeSentinel(u8, zx_source, 0);
const ast = try zx.Ast.parse(allocator, zx_sourcez, .{});
const output = if (is_transpile) ast.zig_source else ast.zx_source;

View File

@ -125,7 +125,7 @@ const PendingFetch = struct {
allocator: std.mem.Allocator = undefined,
};
var pending_slots: [MAX_PENDING]PendingFetch = [_]PendingFetch{.{}} ** MAX_PENDING;
var pending_slots: [MAX_PENDING]PendingFetch = @splat(PendingFetch{});
fn findOrAllocSlot(fetch_id: u64) ?usize {
const preferred: usize = @intCast(fetch_id % MAX_PENDING);

View File

@ -28,7 +28,7 @@ const WebSocketSlot = struct {
ws: ?*WebSocket = null,
};
var ws_slots: [MAX_WEBSOCKETS]WebSocketSlot = [_]WebSocketSlot{.{}} ** MAX_WEBSOCKETS;
var ws_slots: [MAX_WEBSOCKETS]WebSocketSlot = @splat(WebSocketSlot{});
fn findOrAllocSlot(ws_id: u64) ?usize {
const preferred: usize = @intCast(ws_id % MAX_WEBSOCKETS);

View File

@ -180,10 +180,10 @@ const CallbackEntry = struct {
};
/// Global callback registry
var callbacks: [MAX_CALLBACKS]CallbackEntry = [_]CallbackEntry{.{
var callbacks: [MAX_CALLBACKS]CallbackEntry = @splat(CallbackEntry{
.callback_type = .event,
.active = false,
}} ** MAX_CALLBACKS;
});
var next_callback_id: u64 = 1;
/// Register a callback and get its ID

View File

@ -374,7 +374,7 @@ fn test_fmt_inner(comptime file_path: []const u8, comptime has_diff_expected: bo
const source = try cache.get(source_path) orelse return error.FileNotFound;
const source_altered = try std.fmt.allocPrint(allocator, "\n\n {s} \n\n", .{source});
defer allocator.free(source_altered);
const source_z = try allocator.dupeZ(u8, source_altered);
const source_z = try allocator.dupeSentinel(u8, source_altered, 0);
defer allocator.free(source_z);
// Parse and transpile
@ -386,7 +386,7 @@ fn test_fmt_inner(comptime file_path: []const u8, comptime has_diff_expected: bo
std.log.err("Expected file not found: {s}\n", .{expected_source_path});
return error.FileNotFound;
};
const expected_source_z = try allocator.dupeZ(u8, expected_source);
const expected_source_z = try allocator.dupeSentinel(u8, expected_source, 0);
defer allocator.free(expected_source_z);
try testing.expectEqualStrings(expected_source_z, result.source orelse return error.FmtHadErrors);
}

View File

@ -446,7 +446,7 @@ fn test_transpile_inner(comptime file_path: []const u8, comptime no_expect: bool
// Get pre-loaded source file
const source = try cache.get(source_path) orelse return error.FileNotFound;
const source_z = try allocator.dupeZ(u8, source);
const source_z = try allocator.dupeSentinel(u8, source, 0);
defer allocator.free(source_z);
// Parse and transpile with file path for Client support
@ -469,7 +469,7 @@ fn test_transpile_inner(comptime file_path: []const u8, comptime no_expect: bool
std.log.err("Expected file not found: {s}\n", .{expected_source_path});
return error.FileNotFound;
};
const expected_source_z = try allocator.dupeZ(u8, expected_source);
const expected_source_z = try allocator.dupeSentinel(u8, expected_source, 0);
defer allocator.free(expected_source_z);
if (!no_expect) {

View File

@ -125,7 +125,7 @@ test "sm > e2e simple element transpilation" {
\\
\\const zx = @import("zx");
;
const source_z = try allocator.dupeZ(u8, source);
const source_z = try allocator.dupeSentinel(u8, source, 0);
defer allocator.free(source_z);
var result = try zx.Ast.parse(allocator, source_z, .{ .map = .inlined });
@ -173,7 +173,7 @@ test "sm > e2e generatedToSource roundtrip for zig code" {
\\ std.debug.print("hello\n", .{});
\\}
;
const source_z = try allocator.dupeZ(u8, source);
const source_z = try allocator.dupeSentinel(u8, source, 0);
defer allocator.free(source_z);
var result = try zx.Ast.parse(allocator, source_z, .{ .map = .inlined });
@ -210,7 +210,7 @@ test "sm > e2e expression in element" {
\\
\\const zx = @import("zx");
;
const source_z = try allocator.dupeZ(u8, source);
const source_z = try allocator.dupeSentinel(u8, source, 0);
defer allocator.free(source_z);
var result = try zx.Ast.parse(allocator, source_z, .{ .map = .inlined });
@ -248,7 +248,7 @@ test "sm > all test files produce valid sourcemaps" {
const source = std.Io.Dir.cwd().readFileAlloc(std.testing.io, tf.zx_path, allocator, .limited(std.math.maxInt(usize))) catch continue;
defer allocator.free(source);
const source_z = try allocator.dupeZ(u8, source);
const source_z = try allocator.dupeSentinel(u8, source, 0);
defer allocator.free(source_z);
var result = zx.Ast.parse(allocator, source_z, .{ .map = .inlined, .path = tf.zx_path }) catch continue;
@ -294,7 +294,7 @@ test "sm > golden file mappings" {
};
defer allocator.free(source);
const source_z = try allocator.dupeZ(u8, source);
const source_z = try allocator.dupeSentinel(u8, source, 0);
defer allocator.free(source_z);
var result = zx.Ast.parse(allocator, source_z, .{ .map = .inlined, .path = tf.zx_path }) catch |err| {
@ -361,7 +361,7 @@ test "sm > generate sourcemap debug files" {
const source = std.Io.Dir.cwd().readFileAlloc(std.testing.io, tf.zx_path, allocator, .limited(std.math.maxInt(usize))) catch continue;
defer allocator.free(source);
const source_z = try allocator.dupeZ(u8, source);
const source_z = try allocator.dupeSentinel(u8, source, 0);
defer allocator.free(source_z);
var result = zx.Ast.parse(allocator, source_z, .{ .map = .inlined, .path = tf.zx_path }) catch continue;

View File

@ -20,7 +20,7 @@ pub const std_options = std.Options{
const Allocator = std.mem.Allocator;
const BORDER = "=" ** 80;
const BORDER: [80]u8 = @splat('=');
// use in custom panic handler
var current_test: ?[]const u8 = null;