Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Snektron committed Aug 17, 2024
1 parent 4ecd243 commit e5b1e69
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 92 deletions.
2 changes: 1 addition & 1 deletion lib/std/Build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2373,7 +2373,7 @@ pub const LazyPath = union(enum) {
// basis for not traversing up too many directories.

var file_path: Cache.Path = .{
// TODO: generated should really get a Path
// TODO(robin): generated should really get a Path
.root_dir = Cache.Directory.cwd(),
.sub_path = gen.file.path orelse {
std.debug.lockStdErr();
Expand Down
2 changes: 1 addition & 1 deletion lib/std/Build/Fuzz/WebServer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ fn buildWasmBinary(
const digest = body[@sizeOf(EbpHdr)..][0..Cache.bin_digest_len];
result = Path{
.root_dir = ws.global_cache_directory,
.sub_path = try std.fmt.allocPrint(arena, "o" ++ std.fs.path.sep_str ++ "{}", .{std.fmt.fmtSliceHexLower(digest)}),
.sub_path = try arena.dupe(u8, "o" ++ std.fs.path.sep_str ++ Cache.binToHex(digest.*)),
};
},
else => {}, // ignore other messages
Expand Down
4 changes: 1 addition & 3 deletions lib/std/Build/Step.zig
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,10 @@ fn zigProcessUpdate(s: *Step, zp: *ZigProcess, watch: bool) !?Path {
const ebp_hdr = @as(*align(1) const EbpHdr, @ptrCast(body));
s.result_cached = ebp_hdr.flags.cache_hit;
const digest = body[@sizeOf(EbpHdr)..][0..Cache.bin_digest_len];
std.debug.print("got digest: {}\n", .{ std.fmt.fmtSliceHexLower(digest) });
result = Path{
.root_dir = b.cache_root,
.sub_path = try std.fmt.allocPrint(arena, "o" ++ std.fs.path.sep_str ++ "{}", .{std.fmt.fmtSliceHexLower(digest)}),
.sub_path = try arena.dupe(u8, "o" ++ std.fs.path.sep_str ++ Cache.binToHex(digest.*)),
};
std.debug.print("path: {}\n", .{ result.? });
},
.file_system_inputs => {
s.clearWatchInputs();
Expand Down
16 changes: 8 additions & 8 deletions lib/std/Build/Step/Compile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1781,30 +1781,30 @@ fn make(step: *Step, options: Step.MakeOptions) !void {

// Update generated files
if (maybe_output_dir) |output_dir| {
// std.debug.print("output dir: {}\n", .{output_dir});
if (compile.emit_directory) |lp| {
lp.path = b.fmt("{}", .{output_dir});
}

// -femit-bin[=path] (default) Output machine code
if (compile.generated_bin) |bin| {
bin.path = output_dir.joinString(b.allocator, compile.out_filename) catch @panic("OOM");
// std.debug.print("bin path: {s}\n", .{bin.path.?});
}

const sep = std.fs.path.sep_str;

// output PDB if someone requested it
if (compile.generated_pdb) |pdb| {
pdb.path = b.fmt("{}" ++ std.fs.path.sep_str ++ "{s}.pdb", .{ output_dir, compile.name });
pdb.path = b.fmt("{}" ++ sep ++ "{s}.pdb", .{ output_dir, compile.name });
}

// -femit-implib[=path] (default) Produce an import .lib when building a Windows DLL
if (compile.generated_implib) |implib| {
implib.path = b.fmt("{}" ++ std.fs.path.sep_str ++ "{s}.lib", .{ output_dir, compile.name });
implib.path = b.fmt("{}" ++ sep ++ "{s}.lib", .{ output_dir, compile.name });
}

// -femit-h[=path] Generate a C header file (.h)
if (compile.generated_h) |lp| {
lp.path = b.fmt("{}" ++ std.fs.path.sep_str ++ "{s}.h", .{ output_dir, compile.name });
lp.path = b.fmt("{}" ++ sep ++ "{s}.h", .{ output_dir, compile.name });
}

// -femit-docs[=path] Create a docs/ dir with html documentation
Expand All @@ -1814,17 +1814,17 @@ fn make(step: *Step, options: Step.MakeOptions) !void {

// -femit-asm[=path] Output .s (assembly code)
if (compile.generated_asm) |lp| {
lp.path = b.fmt("{}" ++ std.fs.path.sep_str ++ "{s}.s", .{ output_dir, compile.name });
lp.path = b.fmt("{}" ++ sep ++ "{s}.s", .{ output_dir, compile.name });
}

// -femit-llvm-ir[=path] Produce a .ll file with optimized LLVM IR (requires LLVM extensions)
if (compile.generated_llvm_ir) |lp| {
lp.path = b.fmt("{}" ++ std.fs.path.sep_str ++ "{s}.ll", .{ output_dir, compile.name });
lp.path = b.fmt("{}" ++ sep ++ "{s}.ll", .{ output_dir, compile.name });
}

// -femit-llvm-bc[=path] Produce an optimized LLVM module as a .bc file (requires LLVM extensions)
if (compile.generated_llvm_bc) |lp| {
lp.path = b.fmt("{}" ++ std.fs.path.sep_str ++ "{s}.bc", .{ output_dir, compile.name });
lp.path = b.fmt("{}" ++ sep ++ "{s}.bc", .{ output_dir, compile.name });
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4570,8 +4570,8 @@ pub fn cImport(comp: *Compilation, c_src: []const u8, owner_mod: *Package.Module
}

const bin_digest = man.finalBin();
const hex_digest = Cache.binToHex(digest);
const o_sub_path = try std.fs.path.join(arena, &[_][]const u8{ "o", &hex_digest });
const hex_digest = Cache.binToHex(bin_digest);
const o_sub_path = "o" ++ std.fs.path.sep_str ++ hex_digest;
var o_dir = try comp.local_cache_directory.handle.makeOpenPath(o_sub_path, .{});
defer o_dir.close();

Expand Down
5 changes: 2 additions & 3 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6004,9 +6004,8 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
return sema.failWithOwnedErrorMsg(&child_block, msg);
}
const parent_mod = parent_block.ownerModule();
const c_import_zig_path = try std.fmt.allocPrint(comp.arena, "o" ++ std.fs.path.sep_str ++ "{}", .{
std.fmt.fmtSliceHexLower(&c_import_res.digest),
});
const digest = Cache.binToHex(c_import_res.digest);
const c_import_zig_path = try comp.arena.dupe(u8, "o" ++ std.fs.path.sep_str ++ digest);
const c_import_mod = Package.Module.create(comp.arena, .{
.global_cache_directory = comp.global_cache_directory,
.paths = .{
Expand Down
74 changes: 0 additions & 74 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4229,85 +4229,11 @@ fn serveUpdateResults(s: *Server, comp: *Compilation) !void {
}

if (comp.digest) |digest| {
// var digest: [Cache.bin_digest_len]u8 = undefined;
// _ = std.fmt.hexToBytes(&digest, &hex_digest) catch unreachable;
// std.debug.print("sending digest: {*} {s} {}\n", .{ comp, &hex_digest, std.fmt.fmtSliceHexLower(&digest) });
try s.serveEmitDigest(&digest, .{
.flags = .{ .cache_hit = comp.last_update_was_cache_hit },
});
}

// This logic is counter-intuitive because the protocol accounts for each
// emitted artifact possibly being in a different location, which correctly
// matches the behavior of the compiler, however, the build system
// currently always passes flags that makes all build artifacts output to
// the same local cache directory, and relies on them all being in the same
// directory.
//
// So, until the build system and protocol are changed to reflect this,
// this logic must ensure that emit_bin_path is emitted for at least one
// thing, if there are any artifacts.

// std.debug.print("aaaaaaaaaaaaaaaaaa: {}\n", .{comp.cache_use});
// std.debug.print("aaaaaaaaaaaaaaaaaa comp.bin_file={s}\n", .{if (comp.bin_file) |bf| bf.emit.sub_path else "(null)"});
// std.debug.print("aaaaaaaaaaaaaaaaaa comp.emit_asm={s}\n", .{if (comp.emit_asm) |bf| bf.basename else "(null)"});

// switch (comp.cache_use) {
// .incremental => if (comp.bin_file) |lf| {
// const full_path = try lf.emit.directory.join(gpa, &.{lf.emit.sub_path});
// std.debug.print("aaaaaaaaaaaaaaaaax: full_path={s}\n", .{full_path});
// defer gpa.free(full_path);
// try s.serveEmitBinPath(full_path, .{
// .flags = .{ .cache_hit = comp.last_update_was_cache_hit },
// });
// return;
// },
// .whole => |whole| if (whole.bin_sub_path) |sub_path| {
// const full_path = try comp.local_cache_directory.join(gpa, &.{sub_path});
// std.debug.print("aaaaaaaaaaaaaaaaay: full_path={s}\n", .{full_path});
// defer gpa.free(full_path);
// try s.serveEmitBinPath(full_path, .{
// .flags = .{ .cache_hit = comp.last_update_was_cache_hit },
// });
// return;
// } else {
// std.debug.print("aaaaaaaaaaaaaaaaaz: ue {*}\n", .{whole});
// },
// }

// for ([_]?Compilation.Emit{
// comp.docs_emit,
// comp.implib_emit,
// }) |opt_emit| {
// const emit = opt_emit orelse continue;
// const full_path = try emit.directory.join(gpa, &.{emit.sub_path});
// std.debug.print("aaaaaaaaaaaaaaaaaz: full_path={s}\n", .{full_path});
// defer gpa.free(full_path);
// try s.serveEmitBinPath(full_path, .{
// .flags = .{ .cache_hit = comp.last_update_was_cache_hit },
// });
// return;
// }

// for ([_]?Compilation.EmitLoc{
// comp.emit_asm,
// comp.emit_llvm_ir,
// comp.emit_llvm_bc,
// }) |opt_emit_loc| {
// std.debug.print("aaaaa\n", .{});
// const emit_loc = opt_emit_loc orelse continue;
// std.debug.print("aaaaa emit_loc={}\n", .{emit_loc});
// const directory = emit_loc.directory orelse continue;
// std.debug.print("aaaaa directory={s}\n", .{directory.path.?});
// const full_path = try directory.join(gpa, &.{emit_loc.basename});
// std.debug.print("aaaaaaaaaaaaaaaaaw: full_path={s}\n", .{full_path});
// defer gpa.free(full_path);
// try s.serveEmitBinPath(full_path, .{
// .flags = .{ .cache_hit = comp.last_update_was_cache_hit },
// });
// return;
// }

// Serve empty error bundle to indicate the update is done.
try s.serveErrorBundle(std.zig.ErrorBundle.empty);
}
Expand Down

0 comments on commit e5b1e69

Please sign in to comment.