@@ -4,12 +4,7 @@ pub fn build(b: *std.Build) !void {
44 const target = b .standardTargetOptions (.{});
55 const optimize = b .standardOptimizeOption (.{});
66
7- const version : Version = if (b .option (
8- []const u8 ,
9- "force-version" ,
10- "When building the SuperHTML CLI tool force a specific version, bypassing 'git describe'" ,
11- )) | v | .{ .commit = v } else getVersion (b );
12-
7+ const version = getVersion (b );
138 const enable_tracy = b .option (bool , "tracy" , "Enable Tracy profiling" ) orelse false ;
149
1510 const tracy = b .dependency ("tracy" , .{ .enable = enable_tracy });
@@ -75,8 +70,29 @@ pub fn build(b: *std.Build) !void {
7570 setupCliTool (b , target , optimize , options , superhtml , folders , lsp );
7671 setupWasmStep (b , optimize , options , superhtml , lsp );
7772 setupFetchLanguageSubtagRegistryStep (b , target );
73+
74+ const release = b .step ("release" , "Create release builds of Zine" );
7875 if (version == .tag ) {
79- setupReleaseStep (b , options , superhtml , folders , lsp );
76+ const zon = @import ("build.zig.zon" );
77+ if (std .mem .eql (u8 , zon .version , version .tag [1.. ])) {
78+ setupReleaseStep (
79+ b ,
80+ options ,
81+ superhtml ,
82+ folders ,
83+ lsp ,
84+ release ,
85+ );
86+ } else {
87+ release .dependOn (& b .addFail (b .fmt (
88+ "error: git tag does not match zon package version (zon: '{s}', git: '{s}')" ,
89+ .{ zon .version , version .tag [1.. ] },
90+ )).step );
91+ }
92+ } else {
93+ release .dependOn (& b .addFail (
94+ "error: git tag missing, cannot make release builds" ,
95+ ).step );
8096 }
8197
8298 setupGeneratorStep (b , target );
@@ -237,11 +253,8 @@ fn setupReleaseStep(
237253 superhtml : * std.Build.Module ,
238254 folders : * std.Build.Dependency ,
239255 lsp : * std.Build.Dependency ,
256+ release_step : * std.Build.Step ,
240257) void {
241- const release_step = b .step (
242- "release" ,
243- "Create releases for the SuperHTML CLI" ,
244- );
245258 const targets : []const std.Target.Query = &.{
246259 .{ .cpu_arch = .aarch64 , .os_tag = .macos },
247260 .{ .cpu_arch = .aarch64 , .os_tag = .linux },
@@ -271,15 +284,53 @@ fn setupReleaseStep(
271284 super_exe_release .root_module .addImport ("lsp" , lsp .module ("lsp" ));
272285 super_exe_release .root_module .addOptions ("build_options" , options );
273286
274- const target_output = b .addInstallArtifact (super_exe_release , .{
275- .dest_dir = .{
276- .override = .{
277- .custom = t .zigTriple (b .allocator ) catch unreachable ,
278- },
287+ switch (t .os_tag .? ) {
288+ .macos , .windows = > {
289+ const archive_name = b .fmt ("{s}.zip" , .{
290+ t .zigTriple (b .allocator ) catch unreachable ,
291+ });
292+
293+ const zip = b .addSystemCommand (&.{
294+ "zip" ,
295+ "-9" ,
296+ // "-dd",
297+ "-q" ,
298+ "-j" ,
299+ });
300+ const archive = zip .addOutputFileArg (archive_name );
301+ zip .addDirectoryArg (super_exe_release .getEmittedBin ());
302+ _ = zip .captureStdOut ();
303+
304+ release_step .dependOn (& b .addInstallFileWithDir (
305+ archive ,
306+ .{ .custom = "releases" },
307+ archive_name ,
308+ ).step );
279309 },
280- });
281-
282- release_step .dependOn (& target_output .step );
310+ else = > {
311+ const archive_name = b .fmt ("{s}.tar.xz" , .{
312+ t .zigTriple (b .allocator ) catch unreachable ,
313+ });
314+
315+ const tar = b .addSystemCommand (&.{
316+ "gtar" ,
317+ "-cJf" ,
318+ });
319+
320+ const archive = tar .addOutputFileArg (archive_name );
321+ tar .addArg ("-C" );
322+
323+ tar .addDirectoryArg (super_exe_release .getEmittedBinDirectory ());
324+ tar .addArg ("superhtml" );
325+ _ = tar .captureStdOut ();
326+
327+ release_step .dependOn (& b .addInstallFileWithDir (
328+ archive ,
329+ .{ .custom = "releases" },
330+ archive_name ,
331+ ).step );
332+ },
333+ }
283334 }
284335
285336 // wasm
@@ -302,15 +353,21 @@ fn setupReleaseStep(
302353 super_wasm_lsp .root_module .addImport ("lsp" , lsp .module ("lsp" ));
303354 super_wasm_lsp .root_module .addOptions ("build_options" , options );
304355
305- const target_output = b .addInstallArtifact (super_wasm_lsp , .{
306- .dest_dir = .{
307- .override = .{
308- .custom = "wasm-wasi-lsponly" ,
309- },
310- },
356+ const archive_name = "wasm-wasi-lsponly.tar.xz" ;
357+ const tar = b .addSystemCommand (&.{
358+ "gtar" ,
359+ "-cJf" ,
311360 });
312-
313- release_step .dependOn (& target_output .step );
361+ const archive = tar .addOutputFileArg (archive_name );
362+ tar .addArg ("-C" );
363+ tar .addDirectoryArg (super_wasm_lsp .getEmittedBinDirectory ());
364+ tar .addArg ("superhtml.wasm" );
365+ _ = tar .captureStdOut ();
366+ release_step .dependOn (& b .addInstallFileWithDir (
367+ archive ,
368+ .{ .custom = "releases" },
369+ archive_name ,
370+ ).step );
314371 }
315372}
316373
0 commit comments