explain the error

This commit is contained in:
dave caruso
2024-12-17 22:31:07 -08:00
parent 4f81d0e643
commit b321908b2b
3 changed files with 31 additions and 7 deletions

View File

@@ -295,9 +295,9 @@ pub fn build(b: *Build) !void {
}
// zig build check
var bun_check_obj = addBunObject(b, &build_options);
{
var step = b.step("check", "Check for semantic analysis errors");
var bun_check_obj = addBunObject(b, &build_options);
bun_check_obj.generated_bin = null;
step.dependOn(&bun_check_obj.step);
@@ -349,10 +349,23 @@ pub fn build(b: *Build) !void {
.target = b.graph.host,
.optimize = .Debug,
});
// This executable intentionally does not add all of Bun's includes, as they
// are never needed, and any compile error referencing an external module is
// something that should be gated behind `bun.Environment.export_cpp_apis`
// This executable intentionally does not add all of Bun's proper
// modules, as they are theoretically not needed, and any compile error
// referencing an external module is something that should be gated
// behind `bun.Environment.export_cpp_apis`. If these modules were
// required, then that indicates that random code is being analyzed
// when it should not be, and is a mistake.
exe.root_module.addImport("build_options", build_options.buildOptionsModule(b));
const noop = b.createModule(.{
.root_source_file = b.path("src/noop.zig"),
.target = b.graph.host,
.optimize = .Debug,
});
var it = bun_check_obj.root_module.import_table.iterator();
while (it.next()) |entry| {
if(!std.mem.eql(u8, entry.key_ptr.*, "build_options"))
exe.root_module.addImport(entry.key_ptr.*, noop);
}
const run = b.addRunArtifact(exe);
step.dependOn(&run.step);

View File

@@ -1536,9 +1536,13 @@ pub fn main() !void {
});
if (!result.success) {
console.error("Failed to extract enums, see above for the error.");
console.error("If you just added a new t.zigEnum, check the file for top-level comptime blocks, they may");
console.error("need to add new checks for `if (bun.Environment.export_cpp_apis)` to not export code");
console.error("when being compiled from the code generator.");
console.error("");
console.error("If you just added a new t.zigEnum, check the file for top-level comptime blocks,");
console.error("they may need to add new checks for `if (bun.Environment.export_cpp_apis)` to");
console.error("avoid exporting and referencing code when being compiled from the code generator.");
console.error("");
console.error("If that does not work, then move the desired Zig enum to a new file, or consider");
console.error("cutting down on namespace indirection.");
process.exit(1);
}
const out = JSON.parse(result.stdout.toString("utf-8"));

7
src/noop.zig Normal file
View File

@@ -0,0 +1,7 @@
// This file is used as a module entry point for modules that do not exist,
// while the `bindgen.ts` code generator is in use. *Some* module has to be
// defined because Zig will eagerly resolve all source files and their Zir.
//
// If this source file appears in an error message, walk up its reference trace
// and see what is referencing it. It is highly likely that reference can be
// removed by gating it behind `Environment.export_cpp_apis`.