| ... | @@ -119,7 +119,6 @@ fn serveDocsFile( | ... | @@ -119,7 +119,6 @@ fn serveDocsFile( |
| 119 | const file_contents = try context.lib_dir.readFileAlloc(gpa, name, 10 * 1024 * 1024); | 119 | const file_contents = try context.lib_dir.readFileAlloc(gpa, name, 10 * 1024 * 1024); |
| 120 | defer gpa.free(file_contents); | 120 | defer gpa.free(file_contents); |
| 121 | try request.respond(file_contents, .{ | 121 | try request.respond(file_contents, .{ |
| 122 | .status = .ok, | | |
| 123 | .extra_headers = &.{ | 122 | .extra_headers = &.{ |
| 124 | .{ .name = "content-type", .value = content_type }, | 123 | .{ .name = "content-type", .value = content_type }, |
| 125 | cache_control_header, | 124 | cache_control_header, |
| ... | @@ -128,9 +127,46 @@ fn serveDocsFile( | ... | @@ -128,9 +127,46 @@ fn serveDocsFile( |
| 128 | } | 127 | } |
| 129 | | 128 | |
| 130 | fn serveSourcesTar(request: *std.http.Server.Request, context: *Context) !void { | 129 | fn serveSourcesTar(request: *std.http.Server.Request, context: *Context) !void { |
| 131 | _ = request; | 130 | const gpa = context.gpa; |
| 132 | _ = context; | 131 | |
| 133 | @panic("TODO"); | 132 | var send_buffer: [0x4000]u8 = undefined; |
| | 133 | var response = request.respondStreaming(.{ |
| | 134 | .send_buffer = &send_buffer, |
| | 135 | .respond_options = .{ |
| | 136 | .extra_headers = &.{ |
| | 137 | .{ .name = "content-type", .value = "application/x-tar" }, |
| | 138 | cache_control_header, |
| | 139 | }, |
| | 140 | }, |
| | 141 | }); |
| | 142 | const w = response.writer(); |
| | 143 | try w.writeAll("tar header"); |
| | 144 | |
| | 145 | var std_dir = try context.lib_dir.openDir("std", .{ .iterate = true }); |
| | 146 | defer std_dir.close(); |
| | 147 | |
| | 148 | var walker = try std_dir.walk(gpa); |
| | 149 | defer walker.deinit(); |
| | 150 | |
| | 151 | while (try walker.next()) |entry| { |
| | 152 | switch (entry.kind) { |
| | 153 | .file => { |
| | 154 | if (!std.mem.endsWith(u8, entry.basename, ".zig")) |
| | 155 | continue; |
| | 156 | if (std.mem.endsWith(u8, entry.basename, "test.zig")) |
| | 157 | continue; |
| | 158 | }, |
| | 159 | else => continue, |
| | 160 | } |
| | 161 | |
| | 162 | try w.writeAll(entry.path); |
| | 163 | |
| | 164 | var file = try std_dir.openFile(entry.path, .{}); |
| | 165 | defer file.close(); |
| | 166 | |
| | 167 | try w.writeFile(file); |
| | 168 | } |
| | 169 | try response.end(); |
| 134 | } | 170 | } |
| 135 | | 171 | |
| 136 | fn serveWasm( | 172 | fn serveWasm( |
| ... | @@ -151,7 +187,6 @@ fn serveWasm( | ... | @@ -151,7 +187,6 @@ fn serveWasm( |
| 151 | const file_contents = try std.fs.cwd().readFileAlloc(gpa, wasm_binary_path, 10 * 1024 * 1024); | 187 | const file_contents = try std.fs.cwd().readFileAlloc(gpa, wasm_binary_path, 10 * 1024 * 1024); |
| 152 | defer gpa.free(file_contents); | 188 | defer gpa.free(file_contents); |
| 153 | try request.respond(file_contents, .{ | 189 | try request.respond(file_contents, .{ |
| 154 | .status = .ok, | | |
| 155 | .extra_headers = &.{ | 190 | .extra_headers = &.{ |
| 156 | .{ .name = "content-type", .value = "application/wasm" }, | 191 | .{ .name = "content-type", .value = "application/wasm" }, |
| 157 | cache_control_header, | 192 | cache_control_header, |
| ... | @@ -250,7 +285,7 @@ fn buildWasmBinary( | ... | @@ -250,7 +285,7 @@ fn buildWasmBinary( |
| 250 | const EbpHdr = std.zig.Server.Message.EmitBinPath; | 285 | const EbpHdr = std.zig.Server.Message.EmitBinPath; |
| 251 | const ebp_hdr = @as(*align(1) const EbpHdr, @ptrCast(body)); | 286 | const ebp_hdr = @as(*align(1) const EbpHdr, @ptrCast(body)); |
| 252 | if (!ebp_hdr.flags.cache_hit) { | 287 | if (!ebp_hdr.flags.cache_hit) { |
| 253 | std.log.info("source changes detected; rebuilding wasm component", .{}); | 288 | std.log.info("source changes detected; rebuilt wasm component", .{}); |
| 254 | } | 289 | } |
| 255 | result = try arena.dupe(u8, body[@sizeOf(EbpHdr)..]); | 290 | result = try arena.dupe(u8, body[@sizeOf(EbpHdr)..]); |
| 256 | }, | 291 | }, |