Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0

- name: Build project
run: zig build
Expand All @@ -66,7 +66,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0

- name: Run tests
run: zig build test
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0

- name: Setup Bun
uses: oven-sh/setup-bun@v1
Expand Down Expand Up @@ -160,7 +160,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0

- name: Setup Bun
uses: oven-sh/setup-bun@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
if: ${{ !inputs.base_url }}
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0

- name: Setup Node
uses: actions/setup-node@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0

- name: Cache Zig build artifacts
uses: actions/cache@v4
Expand Down Expand Up @@ -316,7 +316,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0

- name: Setup Git
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0

- name: Update ziex dependency to current commit
run: |
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0

- name: Update ziex dependency to current commit
run: |
Expand Down
17 changes: 11 additions & 6 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ pub fn build(b: *std.Build) !void {
zx_runtime_options.addOption([]const u8, "staticdir", "zig-out/static");
zx_runtime_options.addOption([]const u8, "datadir", "zig-out/data");
zx_runtime_options.addOption(?[]const u8, "app_base_path", null);
zx_runtime_options.addOption(?u16, "server_port", null);
zx_runtime_options.addOption(?[]const u8, "server_address", null);
zx_runtime_options.addOption(?[]const u8, "server_rootdir", null);
zx_runtime_options.addOption(?[]const u8, "cli_command", null);
zx_runtime_options.addOption(bool, "introspect", false);

const cli_options_dev = b.addOptions();
cli_options_dev.addOption([]const u8, "zig_exe", b.graph.zig_exe);
Expand Down Expand Up @@ -93,7 +98,6 @@ pub fn build(b: *std.Build) !void {

// --- ZX CLI (Transpiler, Exporter, Dev Server) --- //
const zli_dep = b.dependency("zli", .{ .target = target, .optimize = optimize });
const zls_dep = b.dependency("zls", .{ .target = target, .optimize = optimize });
const exe_rootmod_opts: std.Build.Module.CreateOptions = .{
.root_source_file = b.path("src/main.zig"),
.target = target,
Expand All @@ -112,7 +116,10 @@ pub fn build(b: *std.Build) !void {

const exe = b.addExecutable(.{ .name = "zx", .root_module = b.createModule(exe_rootmod_opts) });
exe.root_module.addOptions("build_options", exe_build_options);
if (!exclude_lsp) exe.root_module.addImport("zls", zls_dep.module("zls"));
if (!exclude_lsp) {
const zls_dep = b.dependency("zls", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("zls", zls_dep.module("zls"));
}
b.installArtifact(exe);

// --- Steps: Run --- //
Expand Down Expand Up @@ -210,7 +217,7 @@ pub fn build(b: *std.Build) !void {
});
const css_gen_run = b.addRunArtifact(css_gen_exe);

if (std.fs.cwd().access("vendor/webref", .{})) |_| {} else |_| {
if (b.build_root.handle.access(b.graph.io, "vendor/webref", .{})) |_| {} else |_| {
const sync_cmd = b.addSystemCommand(&.{ "./tools/syncvendor", "webref" });
css_gen_run.step.dependOn(&sync_cmd.step);
}
Expand All @@ -232,7 +239,7 @@ pub fn build(b: *std.Build) !void {
});
const events_gen_run = b.addRunArtifact(events_gen_exe);

if (std.fs.cwd().access("vendor/webref", .{})) |_| {} else |_| {
if (b.build_root.handle.access(b.graph.io, "vendor/webref", .{})) |_| {} else |_| {
const sync_cmd = b.addSystemCommand(&.{ "./tools/syncvendor", "webref" });
events_gen_run.step.dependOn(&sync_cmd.step);
}
Expand Down Expand Up @@ -266,7 +273,6 @@ pub fn build(b: *std.Build) !void {
const release_tree_sitter_dep = b.dependency("tree_sitter", .{ .target = resolved_target, .optimize = .ReleaseSafe });
const release_tree_sitter_zx_dep = b.dependency("tree_sitter_zx", .{ .target = resolved_target, .optimize = .ReleaseSafe, .@"build-shared" = false });
const release_tree_sitter_mdzx_dep = b.dependency("tree_sitter_mdzx", .{ .target = resolved_target, .optimize = .ReleaseSafe, .@"build-shared" = false });
const release_zls_dep = b.dependency("zls", .{ .target = resolved_target, .optimize = .ReleaseSafe });

// Sub-modules for release
const release_style_mod = b.createModule(.{ .root_source_file = b.path("src/style/root.zig"), .target = resolved_target, .optimize = .ReleaseSafe });
Expand Down Expand Up @@ -299,7 +305,6 @@ pub fn build(b: *std.Build) !void {
.{ .name = "cli_options", .module = cli_options_rel.createModule() },
.{ .name = "zx", .module = release_mod },
.{ .name = "zli", .module = zli_dep.module("zli") },
.{ .name = "zls", .module = release_zls_dep.module("zls") },
.{ .name = "tree_sitter", .module = release_tree_sitter_dep.module("tree_sitter") },
.{ .name = "tree_sitter_zx", .module = release_tree_sitter_zx_dep.module("tree_sitter_zx") },
},
Expand Down
8 changes: 4 additions & 4 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
},
// httpz - HTTP server for Ziex
.httpz = .{
.url = "git+https://github.com/nurulhudaapon/httpz.git#7268154f43f5827bf78668e8e79a00f2ebe4db13",
.hash = "httpz-0.0.0-PNVzrBgtBwCVkSJyophIX6WHwDR0r8XhBGQr96Kk-1El",
.url = "git+https://github.com/karlseguin/http.zig.git#569bba10f22afd4ea1815416b546a8065905f820",
.hash = "httpz-0.0.0-PNVzrJUWCADf96eygXxMPMSWJ-SMNkGDB1B6BUEP7dZZ",
},
.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
Expand All @@ -26,8 +26,8 @@
.cachez = .{ .path = "vendor/cachez" },
// Ziex Language Server utilities
.zls = .{
.url = "git+https://github.com/ziex-dev/zls.git?ref=zx-0.15.1#6afd4d52580899022d24f41689781ec4a9350602",
.hash = "zls-0.15.1-rmm5fgg2JABtvFCDJk6Up7CuP4Khm62Li4NkCfwniFnU",
.url = "git+https://github.com/ziex-dev/zls.git?ref=zx-0.16.0#9dc776aae7db3d522be18a8d20f77f2caa085554",
.hash = "zls-0.16.0-rmm5ftHOJgC9W6p-o3hJMFIbjWE4hKV1CIU_tOSjNiSj",
},
},
.paths = .{
Expand Down
83 changes: 83 additions & 0 deletions patchs/zls.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
zx: make ZLS resolve build-graph modules in .zx files

zxls forwards .zx files to ZLS under their real .zx URI (the *content* is
transpiled to Zig, but the URI keeps the .zx extension). This patches enables .zx files in ZLS

Apply from the ZLS package root: git apply patchs/zls.patch
(or) patch -p1 < patchs/zls.patch

Generated against ZLS 0.16.0 @ 494486203c3a48927f2383aa3d5ce5fca112186d

--- a/src/DocumentStore.zig
+++ b/src/DocumentStore.zig
@@ -51,6 +51,16 @@
},
};

+// zx: zxls forwards `.zx` files to ZLS under their real `.zx` URI (zxls
+// transpiles the *content* to Zig but keeps the URI). For cross-file imports to
+// resolve, ZLS must treat `.zx` as a Zig file import just like `.zig`.
+
+/// Whether `import_string` refers to a Zig source file (`.zig` or `.zx`).
+fn isZigFileImport(import_string: []const u8) bool {
+ return std.mem.endsWith(u8, import_string, ".zig") or
+ std.mem.endsWith(u8, import_string, ".zx");
+}
+
/// Represents a `build.zig`
pub const BuildFile = struct {
uri: Uri,
@@ -115,6 +125,12 @@

var module_root_source_file_paths: std.ArrayList([]const u8) = .empty;

+ // zx: `.zx` page files are routed by the zx framework rather than reached
+ // via `@import`, so they never appear in the import graph below. As a
+ // fallback, associate any `.zx` file located under the build file's
+ // directory with the first compilation's root module.
+ var zx_fallback_root: ?[]const u8 = null;
+
{
const build_config = build_file.tryLockConfig(io) orelse return .unknown;
defer build_file.unlockConfig(io);
@@ -124,6 +140,13 @@
try module_root_source_file_paths.ensureUnusedCapacity(arena, module_paths.len);
for (module_paths) |module_path| {
module_root_source_file_paths.appendAssumeCapacity(try arena.dupe(u8, module_path));
+ }
+
+ if (std.mem.endsWith(u8, uri.raw, ".zx") and build_config.compilations.len != 0) {
+ const build_dir = std.Io.Dir.path.dirname(build_file.uri.raw) orelse build_file.uri.raw;
+ if (std.mem.startsWith(u8, uri.raw, build_dir)) {
+ zx_fallback_root = try arena.dupe(u8, build_config.compilations[0].root_module);
+ }
}
}

@@ -148,6 +171,8 @@
}
}

+ if (zx_fallback_root) |root| return .{ .yes = try allocator.dupe(u8, root) };
+
return .no;
}

@@ -516,7 +541,7 @@
var import_string = offsets.tokenToSlice(tree, tree.nodeMainToken(params[0]));
import_string = import_string[1 .. import_string.len - 1];

- if (!std.mem.endsWith(u8, import_string, ".zig")) continue;
+ if (!isZigFileImport(import_string)) continue;

const import_uri = try Uri.resolveImport(allocator, uri, parsed_uri, import_string);
file_imports.appendAssumeCapacity(import_uri);
@@ -1984,7 +2009,7 @@
const tracy_zone = tracy.trace(@src());
defer tracy_zone.end();

- if (std.mem.endsWith(u8, import_str, ".zig") or std.mem.endsWith(u8, import_str, ".zon")) {
+ if (isZigFileImport(import_str) or std.mem.endsWith(u8, import_str, ".zon")) {
const parsed_uri = handle.uri.toStdUri();
return .{ .one = try Uri.resolveImport(allocator, handle.uri, parsed_uri, import_str) };
}
14 changes: 5 additions & 9 deletions pkg/adapters/src/db.zig
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var _ctx: *anyopaque = @ptrCast(&_stateless);
var _vtable: *const DriverVTable = &noop.vtable;
var _default_config: DefaultConfig = .{};
var _default_connection: ?Connection = null;
var _default_connection_mutex: std.Thread.Mutex = .{};
var _default_connection_mutex: std.atomic.Mutex = .unlocked;

pub fn adapter(ctx: *anyopaque, vtable: *const DriverVTable) void {
_ctx = ctx;
Expand Down Expand Up @@ -158,7 +158,7 @@ pub fn deserialize(bytes: []const u8, options: OpenOptions) !Connection {
}

pub fn connection() !*Connection {
_default_connection_mutex.lock();
while (!_default_connection_mutex.tryLock()) std.Thread.yield() catch {};
defer _default_connection_mutex.unlock();

if (_default_connection == null) {
Expand All @@ -169,7 +169,7 @@ pub fn connection() !*Connection {
}

pub fn closeDefault() void {
_default_connection_mutex.lock();
while (!_default_connection_mutex.tryLock()) std.Thread.yield() catch {};
defer _default_connection_mutex.unlock();

if (_default_connection) |*conn| {
Expand Down Expand Up @@ -538,12 +538,8 @@ fn resolveDatabaseLocation(filename: ?[]const u8) !?[]const u8 {
fn configuredUrl() ?[]const u8 {
if (_default_config.url) |url| return url;
if (builtin.os.tag == .wasi or builtin.os.tag == .freestanding) return null;
if (std.process.getEnvVarOwned(std.heap.page_allocator, "ZX_DB_URL")) |value| {
return value;
} else |_| {}
if (std.process.getEnvVarOwned(std.heap.page_allocator, "DATABASE_URL")) |value| {
return value;
} else |_| {}
if (std.c.getenv("ZX_DB_URL")) |value| return std.mem.span(value);
if (std.c.getenv("DATABASE_URL")) |value| return std.mem.span(value);
return null;
}

Expand Down
14 changes: 11 additions & 3 deletions pkg/adapters/src/db/sqlite.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ const DatabaseCtx = struct {
}

fn acquire(self: *DatabaseCtx) !BorrowedConn {
const io = std.Options.debug_io;
return switch (self.mode) {
.single => .{ .conn = self.conn orelse return db.DbError.InvalidState },
.pooled => .{ .conn = (self.pool orelse return db.DbError.InvalidState).acquire(), .pool = self.pool },
.pooled => .{ .conn = try (self.pool orelse return db.DbError.InvalidState).acquire(io), .pool = self.pool },
};
}
};
Expand All @@ -53,7 +54,7 @@ const BorrowedConn = struct {
pool: ?*zqlite.Pool = null,

fn deinit(self: *BorrowedConn) void {
if (self.pool != null) self.conn.release();
if (self.pool != null) self.conn.release(std.Options.debug_io);
}
};

Expand Down Expand Up @@ -695,7 +696,14 @@ fn ensureParentDir(path: []const u8) !void {
if (isMemoryPath(path) or isUriPath(path)) return;
const parent = std.fs.path.dirname(path) orelse return;
if (parent.len == 0) return;
try std.fs.cwd().makePath(parent);
const io = std.Options.debug_io;
if (std.Io.Dir.cwd().statFile(io, parent, .{ .follow_symlinks = true })) |st| {
if (st.kind == .directory) return;
} else |_| {}
std.Io.Dir.cwd().createDirPath(io, parent) catch |err| switch (err) {
error.PathAlreadyExists => {},
else => return err,
};
}

fn isUriPath(path: []const u8) bool {
Expand Down
1 change: 1 addition & 0 deletions pkg/adapters/vendor/zqlite/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
},
.version = "0.0.1",
.fingerprint = 0x9fb4d74a63da6245,
.minimum_zig_version = "0.16.0",
.dependencies = .{},
}
5 changes: 3 additions & 2 deletions pkg/adapters/vendor/zqlite/src/conn.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const std = @import("std");
const Io = std.Io;
const c = @cImport(@cInclude("sqlite3.h"));

const zqlite = @import("zqlite.zig");
Expand All @@ -24,8 +25,8 @@ pub const Conn = struct {
return .{ .conn = conn.? };
}

pub fn release(self: Conn) void {
self._pool.?.release(self);
pub fn release(self: Conn, io: Io) void {
self._pool.?.release(io, self);
}

pub fn close(self: Conn) void {
Expand Down
Loading
Loading