Open kcbanner opened 9 months ago
Two possible resolutions:
--- a/lib/std/Build/Module.zig
+++ b/lib/std/Build/Module.zig
@@ -244,6 +244,7 @@ pub fn create(owner: *std.Build, options: CreateOptions) *Module {
/// Adds an existing module to be used with `@import`.
pub fn addImport(m: *Module, name: []const u8, module: *Module) void {
+ assert(m.root_source_file != null);
const b = m.owner;
m.import_table.put(b.allocator, b.dupe(name), module) catch @panic("OOM");
--- a/src/main.zig
+++ b/src/main.zig
@@ -7950,7 +7950,9 @@ fn handleModArg(
gop.value_ptr.* = .{
.paths = p: {
if (opt_root_src_orig) |root_src_orig| {
- create_module.opts.have_zcu = true;
+ if (std.mem.eql(u8, mod_name, "root")) {
+ create_module.opts.have_zcu = true;
+ }
const root_src = try introspect.resolvePath(arena, root_src_orig);
break :p .{
.root = .{
Zig Version
0.12.0-dev.2701+d18f52197
Steps to Reproduce and Observed Behavior
This is a reduction of an issue I ran into in a project of mine:
foo.zig
is an empty file.The result when building is:
This reduction is contrived, but I bumped into this in a real project. I build a shared library containing the C/C++ deps, and as part of this I call
Package.link
fromzgui
(one of the zig-gamedev libs), it does this:I'm calling this to link the
zgui_c_cpp
shared library into my shared library, but it also adds imports. This is the part that causes the above issue, without adding zig imports, you don't hit the issue.The issue can also be resolved by adding a blank
.root_source_file
to the shared library.Expected Behavior
Either the zig imports are dropped (since there is no zig root source file), or a more helpful error message indicating the issue (no root source file exists, but there are zig imports).