From 31f68321acbe89aa8da36ceea02f004f9637d61d Mon Sep 17 00:00:00 2001 From: "Nurul Huda (Apon)" Date: Fri, 28 Nov 2025 12:30:04 +0600 Subject: [PATCH] chore: only add zx-doc steps when args are passed --- build.zig | 45 ++++++++++----------------------------------- build.zig.zon | 2 +- site/Dockerfile | 2 +- tools/run | 2 +- 4 files changed, 13 insertions(+), 38 deletions(-) diff --git a/build.zig b/build.zig index 0fb85b30..0c965b67 100644 --- a/build.zig +++ b/build.zig @@ -5,9 +5,6 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - // --- TransformJS Rust Library --- - // const transformjs_build_step = buildTransformJs(b, target, optimize); - // --- ZX Core --- const mod = b.addModule("zx", .{ .root_source_file = b.path("src/root.zig"), @@ -23,6 +20,7 @@ pub fn build(b: *std.Build) void { mod.addOptions("zx_info", options); // --- ZX CLI (Transpiler, Exporter, Dev Server) --- + // const transformjs_build_step = buildRustLibs(b, target, optimize); const zli_dep = b.dependency("zli", .{ .target = target, .optimize = optimize }); const exe = b.addExecutable(.{ .name = "zx", @@ -38,27 +36,9 @@ pub fn build(b: *std.Build) void { }), }); - // Link TransformJS Rust library - // linkTransformJs(b, exe, transformjs_build_step, optimize); - + // linkRustLibs(b, exe, transformjs_build_step, optimize); b.installArtifact(exe); - // --- ZX LSP --- - // const zls_dep = b.dependency("zls", .{ .target = target, .optimize = optimize }); - // const zxls_exe = b.addExecutable(.{ - // .name = "zxls", - // .root_module = b.createModule(.{ - // .root_source_file = b.path("src/lsp/main.zig"), - // .target = target, - // .optimize = optimize, - // .imports = &.{ - // .{ .name = "zls", .module = zls_dep.module("zls") }, - // }, - // }), - // }); - // _ = zxls_exe; - // b.installArtifact(zxls_exe); - // --- Steps: Run --- const run_step = b.step("run", "Run the app"); const run_cmd = b.addRunArtifact(exe); @@ -67,7 +47,8 @@ pub fn build(b: *std.Build) void { if (b.args) |args| run_cmd.addArgs(args); // --- ZX Site (Docs, Example, sample) --- - setupZxDocSite(b, exe, mod, .{ + const is_zx_docsite = b.option(bool, "zx-docsite", "Build the ZX docsite") orelse false; + if (is_zx_docsite) setupZxDocSite(b, exe, mod, .{ .name = "zx_site", .root_module = b.createModule(.{ .root_source_file = b.path("site/main.zig"), @@ -86,7 +67,6 @@ pub fn build(b: *std.Build) void { const exe_tests = b.addTest(.{ .root_module = exe.root_module }); const run_exe_tests = b.addRunArtifact(exe_tests); - // Create transpiler test module and test executable const testing_mod = b.createModule(.{ .root_source_file = b.path("test/main.zig"), .target = target, @@ -137,9 +117,8 @@ pub fn build(b: *std.Build) void { }), }); - // Link TransformJS Rust library for release builds - // const release_transformjs_build_step = buildTransformJs(b, resolved_target, .ReleaseFast); - // linkTransformJs(b, release_exe, release_transformjs_build_step, .ReleaseFast); + // const release_transformjs_build_step = buildRustLibs(b, resolved_target, .ReleaseFast); + // linkRustLibs(b, release_exe, release_transformjs_build_step, .ReleaseFast); const exe_ext = if (resolved_target.result.os.tag == .windows) ".exe" else ""; const install_release = b.addInstallArtifact(release_exe, .{ @@ -159,7 +138,7 @@ pub fn setup(b: *std.Build, options: std.Build.ExecutableOptions) void { const zx_dep = b.dependency("zx", .{ .target = target, .optimize = optimize }); // --- ZX Transpilation --- - const transpile_cmd = b.addRunArtifact(zx_dep.artifact("zx")); // ZX CLI must installed and in the PATH + const transpile_cmd = b.addRunArtifact(zx_dep.artifact("zx")); // const transpile_cmd = b.addSystemCommand(&.{"zx"}); // ZX CLI must installed and in the PATH transpile_cmd.addArg("transpile"); transpile_cmd.addArg(b.pathJoin(&.{"site"})); @@ -254,11 +233,7 @@ fn setupZxDocSite(b: *std.Build, zx_exe: *std.Build.Step.Compile, zx_mod: *std.B }); exe.step.dependOn(&transpile_cmd.step); - - // --- Steps: Site Build --- - const site_step = b.step("site", "Build the site (docs, example, sample)"); - site_step.dependOn(&transpile_cmd.step); - site_step.dependOn(&b.addInstallArtifact(exe, .{}).step); + b.installArtifact(exe); // --- Steps: Run Docs --- const run_docs_step = b.step("serve", "Run the site (docs, example, sample)"); @@ -270,7 +245,7 @@ fn setupZxDocSite(b: *std.Build, zx_exe: *std.Build.Step.Compile, zx_mod: *std.B /// Build the TransformJS Rust library as a C dynamic library /// Returns a build step that must be completed before linking -fn buildTransformJs( +fn buildRustLibs( b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, @@ -328,7 +303,7 @@ fn zigTargetToRustTarget(target: std.Target) ?[]const u8 { } /// Link TransformJS Rust library to an executable -fn linkTransformJs( +fn linkRustLibs( b: *std.Build, exe: *std.Build.Step.Compile, build_step: *std.Build.Step, diff --git a/build.zig.zon b/build.zig.zon index 5424a6ed..3bc005c0 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = .zx, - .version = "0.0.1-dev.222", + .version = "0.0.1-dev.223", .description = "ZX is a framework for building web applications with Zig.", .repository = "https://github.com/nurulhudaapon/zx", .fingerprint = 0xcad77a8d2a3389f2, diff --git a/site/Dockerfile b/site/Dockerfile index 0b6e499d..c36383eb 100644 --- a/site/Dockerfile +++ b/site/Dockerfile @@ -11,7 +11,7 @@ mv zig-$(uname -m)-linux-${ZIG_VER}/ /opt/zig WORKDIR /build COPY . . -RUN /opt/zig/zig build site -Doptimize=ReleaseFast -Dcpu=baseline +RUN /opt/zig/zig build -Dzx-docsite -Doptimize=ReleaseFast -Dcpu=baseline # Run the app FROM alpine:3.22.2 diff --git a/tools/run b/tools/run index 195a66cc..55b4b2b4 100644 --- a/tools/run +++ b/tools/run @@ -1,4 +1,4 @@ #!/bin/bash zig build run -- transpile site --outdir site/.zx -zig build serve \ No newline at end of file +zig build serve -Dzx-docsite \ No newline at end of file