mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
explain the error
This commit is contained in:
21
build.zig
21
build.zig
@@ -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);
|
||||
|
||||
@@ -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
7
src/noop.zig
Normal 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`.
|
||||
Reference in New Issue
Block a user