Skip to content
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

module paths can resolve incorrectly #15767

Closed
radarroark opened this issue May 19, 2023 · 1 comment · Fixed by #15717
Closed

module paths can resolve incorrectly #15767

radarroark opened this issue May 19, 2023 · 1 comment · Fixed by #15717
Labels
bug Observed behavior contradicts documented or intended behavior zig build system std.Build, the build runner, `zig build` subcommand, package management
Milestone

Comments

@radarroark
Copy link
Contributor

Zig Version

0.11.0-dev.3132+465272921

Steps to Reproduce and Observed Behavior

This bug already has a PR at #15717, just adding an issue for it as well.

To reproduce, create a zig project with another zig project in a subdirectory:

mkdir outer && cd outer
zig init-exe
mkdir inner && cd inner
zig init-exe
mv src/main.zig src/inner.zig

Now the outer project looks like this:

├── build.zig
├── inner
│   ├── build.zig
│   └── src
│       └── inner.zig
└── src
    └── main.zig

Now open inner/build.zig and make these changes so it points to the outer project:

diff --git a/inner/build.zig b/inner/build.zig
index d6b4a01..e3b823a 100644
--- a/inner/build.zig
+++ b/inner/build.zig
@@ -19,10 +19,13 @@ pub fn build(b: *std.Build) void {
         .name = "inner",
         // In this case the main source file is merely a path, however, in more
         // complicated build scripts, this could be a generated file.
-        .root_source_file = .{ .path = "src/main.zig" },
+        .root_source_file = .{ .path = "src/inner.zig" },
         .target = target,
         .optimize = optimize,
     });
+    exe.addAnonymousModule("outer", .{
+        .source_file = .{ .path = "../src/main.zig" },
+    });

Finally, in outer, run this:

zig build --build-file inner/build.zig

You will see:

zig build-exe inner Debug native: error: warning: FileNotFound: inner/src/main.zig
error: FileNotFound

No bueno!

Expected Behavior

It should print wicked cool centaur ANSI art with an inspirational quote. Just kidding. Compilation should succeed because the path in inner/build.zig is ../src/main.zig, so it should resolve to src/main.zig, not to inner/src/main.zig.

@radarroark radarroark added the bug Observed behavior contradicts documented or intended behavior label May 19, 2023
@radarroark
Copy link
Contributor Author

@Vexu may I have a nice and shiny build system tag?

@Vexu Vexu added the zig build system std.Build, the build runner, `zig build` subcommand, package management label May 25, 2023
@Vexu Vexu added this to the 0.12.0 milestone May 25, 2023
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Jun 3, 2023
@andrewrk andrewrk modified the milestones: 0.11.0, 0.11.1 Jul 24, 2023
@andrewrk andrewrk modified the milestones: 0.11.1, 0.12.0 Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior zig build system std.Build, the build runner, `zig build` subcommand, package management
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants