-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve error message when target and optimize is not declared in a dependency #18575
Comments
the dependency doesnt declare target or optimize options ( |
side note, in both of the |
@xdBronch I thought it had to be something missing on my part, thanks. I think we should keep this open and improve the error message. About the clarification about the |
Just to be sure, and for references, this is the proper way to declare modules in a package's pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); // Was missing
const optimize = b.standardOptimizeOption(.{}); // Was missing
const hal = b.addModule("hal", .{
.root_source_file = .{ .path = "src/hal.zig" },
.target = target, // Was missing
.optimize = optimize, // Was missing
});
const devices = b.addModule("devices", .{
.root_source_file = .{ .path = "src/devices.zig" },
.target = target, // Was missing
.optimize = optimize, // Was missing
});
devices.addImport("hal", hal);
}
|
its probably good practice in case a project wants to override the target/optimize mode for a specific dependency but its not strictly required to declare the target and optimize options, modules will inherit them from the parent module e.g. the pub fn build(b: *std.Build) void {
_ = b.addModule("devices", .{
.root_source_file = .{ .path = "src/devices.zig" },
.imports = &.{
.{
.name = "hal",
.module = b.createModule(.{
.root_source_file = .{ .path = "src/hal.zig" },
}),
},
},
});
} but i wouldnt necessarily consider this more correct, just depends on how the package is used |
Is it intentional that the ABI is not inherited? This caught me by surprise and frankly made me spend a lot of time hunting this down. If I build the exe with MSVC ABI I think you would generally want everything to be built with MSVC, right? |
Just as a note, this was further made harder to fix due to the second parameter to b.dependency being anytype, making it pretty hard to know what I could pass in there. Relevant issue: #17198 |
I just ran into this too. I was following this example on how to define What is the guidance on how to correctly define build.zig for a module dependency? Seems like it would be better to allow .target and .optimize to be defined by the parent. I'm new to Zig but don't quite understand why omitting those fields in the call to |
Zig Version
0.12.0-dev.2236+32e88251e
Steps to Reproduce and Observed Behavior
When I import a module in my code like this:
I get this error:
I made a repo to reproduce the issue:
https://github.com/kuon/zig-bug-2024-01-15
Expected Behavior
Code should compile without error or with a clearer error.
The text was updated successfully, but these errors were encountered: