diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-08-23 12:57:55 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-08-23 19:23:38 -0700 |
| commit | 9848318725345e4516d68e4f4537f602078d59ad (patch) | |
| tree | 0f1746127373a75442bce8fdab7f916c333bfbe4 /lib/compiler/std-docs.zig | |
| parent | 5dd2bb525d1f19969c450c2b99a71f866a4f01ff (diff) | |
| download | zig-9848318725345e4516d68e4f4537f602078d59ad.tar.gz zig-9848318725345e4516d68e4f4537f602078d59ad.zip | |
fix autodocs regression FTBFS
regressed in dffc8c44f9a01aa05ea364ffdc71509d15bc2601 since there is no
test coverage for the `zig std` command yet.
closes #21180
Diffstat (limited to 'lib/compiler/std-docs.zig')
| -rw-r--r-- | lib/compiler/std-docs.zig | 81 |
1 files changed, 51 insertions, 30 deletions
diff --git a/lib/compiler/std-docs.zig b/lib/compiler/std-docs.zig index 4cfdf9b1e3..0382bbf971 100644 --- a/lib/compiler/std-docs.zig +++ b/lib/compiler/std-docs.zig @@ -4,6 +4,7 @@ const mem = std.mem; const io = std.io; const Allocator = std.mem.Allocator; const assert = std.debug.assert; +const Cache = std.Build.Cache; fn usage() noreturn { io.getStdOut().writeAll( @@ -232,9 +233,18 @@ fn serveWasm( // Do the compilation every request, so that the user can edit the files // and see the changes without restarting the server. - const wasm_binary_path = try buildWasmBinary(arena, context, optimize_mode); + const wasm_base_path = try buildWasmBinary(arena, context, optimize_mode); + const bin_name = try std.zig.binNameAlloc(arena, .{ + .root_name = autodoc_root_name, + .target = std.zig.system.resolveTargetQuery(std.Build.parseTargetQuery(.{ + .arch_os_abi = autodoc_arch_os_abi, + .cpu_features = autodoc_cpu_features, + }) catch unreachable) catch unreachable, + .output_mode = .Exe, + }); // std.http.Server does not have a sendfile API yet. - const file_contents = try std.fs.cwd().readFileAlloc(gpa, wasm_binary_path, 10 * 1024 * 1024); + const bin_path = try wasm_base_path.join(arena, bin_name); + const file_contents = try bin_path.root_dir.handle.readFileAlloc(gpa, bin_path.sub_path, 10 * 1024 * 1024); defer gpa.free(file_contents); try request.respond(file_contents, .{ .extra_headers = &.{ @@ -244,37 +254,42 @@ fn serveWasm( }); } +const autodoc_root_name = "autodoc"; +const autodoc_arch_os_abi = "wasm32-freestanding"; +const autodoc_cpu_features = "baseline+atomics+bulk_memory+multivalue+mutable_globals+nontrapping_fptoint+reference_types+sign_ext"; + fn buildWasmBinary( arena: Allocator, context: *Context, optimize_mode: std.builtin.OptimizeMode, -) ![]const u8 { +) !Cache.Path { const gpa = context.gpa; var argv: std.ArrayListUnmanaged([]const u8) = .{}; try argv.appendSlice(arena, &.{ - context.zig_exe_path, - "build-exe", - "-fno-entry", - "-O", - @tagName(optimize_mode), - "-target", - "wasm32-freestanding", - "-mcpu", - "baseline+atomics+bulk_memory+multivalue+mutable_globals+nontrapping_fptoint+reference_types+sign_ext", - "--cache-dir", - context.global_cache_path, - "--global-cache-dir", - context.global_cache_path, - "--name", - "autodoc", - "-rdynamic", - "--dep", - "Walk", - try std.fmt.allocPrint(arena, "-Mroot={s}/docs/wasm/main.zig", .{context.zig_lib_directory}), - try std.fmt.allocPrint(arena, "-MWalk={s}/docs/wasm/Walk.zig", .{context.zig_lib_directory}), - "--listen=-", + context.zig_exe_path, // + "build-exe", // + "-fno-entry", // + "-O", @tagName(optimize_mode), // + "-target", autodoc_arch_os_abi, // + "-mcpu", autodoc_cpu_features, // + "--cache-dir", context.global_cache_path, // + "--global-cache-dir", context.global_cache_path, // + "--name", autodoc_root_name, // + "-rdynamic", // + "--dep", "Walk", // + try std.fmt.allocPrint( + arena, + "-Mroot={s}/docs/wasm/main.zig", + .{context.zig_lib_directory}, + ), + try std.fmt.allocPrint( + arena, + "-MWalk={s}/docs/wasm/Walk.zig", + .{context.zig_lib_directory}, + ), + "--listen=-", // }); var child = std.process.Child.init(argv.items, gpa); @@ -293,7 +308,7 @@ fn buildWasmBinary( try sendMessage(child.stdin.?, .exit); const Header = std.zig.Server.Message.Header; - var result: ?[]const u8 = null; + var result: ?Cache.Path = null; var result_error_bundle = std.zig.ErrorBundle.empty; const stdout = poller.fifo(.stdout); @@ -330,13 +345,19 @@ fn buildWasmBinary( .extra = extra_array, }; }, - .emit_bin_path => { - const EbpHdr = std.zig.Server.Message.EmitBinPath; - const ebp_hdr = @as(*align(1) const EbpHdr, @ptrCast(body)); - if (!ebp_hdr.flags.cache_hit) { + .emit_digest => { + const EmitDigest = std.zig.Server.Message.EmitDigest; + const emit_digest = @as(*align(1) const EmitDigest, @ptrCast(body)); + if (!emit_digest.flags.cache_hit) { std.log.info("source changes detected; rebuilt wasm component", .{}); } - result = try arena.dupe(u8, body[@sizeOf(EbpHdr)..]); + const digest = body[@sizeOf(EmitDigest)..][0..Cache.bin_digest_len]; + result = .{ + .root_dir = Cache.Directory.cwd(), + .sub_path = try std.fs.path.join(arena, &.{ + context.global_cache_path, "o" ++ std.fs.path.sep_str ++ Cache.binToHex(digest.*), + }), + }; }, else => {}, // ignore other messages } |
