Skip to content

b.anonymousDependency: no dependency named X in build.zig.zon #17185

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

Closed
jmrico01 opened this issue Sep 17, 2023 · 4 comments
Closed

b.anonymousDependency: no dependency named X in build.zig.zon #17185

jmrico01 opened this issue Sep 17, 2023 · 4 comments
Labels
bug Observed behavior contradicts documented or intended behavior zig build system std.Build, the build runner, `zig build` subcommand, package management

Comments

@jmrico01
Copy link
Contributor

jmrico01 commented Sep 17, 2023

Zig Version

0.12.0-dev.396+55f0d8b41

Steps to Reproduce and Observed Behavior

(Running on Windows 10)

Originally described the issue in #16354 (comment), but I'm opening a new issue since it seems to be a bit different and not addressed by those fixes.

To reproduce:

I get the following error, even though deps/common/build.zig.zon does declare a zigimg dependency:
no dependency named 'zigimg' in 'C:\Users\<user>\Documents\Development\zig-bugreport\deps\common\build.zig.zon'. All packages used in build.zig must be declared in this file.

Expected Behavior

zig-bugreport executable should compile successfully and be able to import the common module.

@mlugg for awareness, as they addressed the original issue

@jmrico01 jmrico01 added the bug Observed behavior contradicts documented or intended behavior label Sep 17, 2023
@mlugg
Copy link
Member

mlugg commented Sep 17, 2023

This is a fundamental problem with anonymousDependency as a concept: since actual package management (in particular, reading and parsing build.zig.zon) is handled by the compiler rather than the build system in the standard library, dependencies added through anonymousDependency cannot themselves have dependencies, as they are unknown to the zig build command itself.

I think this is a strong argument of supporting something like #14603 for file-based dependencies, and maybe even removing anonymousDependency in favour of it. Another argument in favour of that PR is that it would allow us to easily set up automated testing for the full package manager (everything other than the actual dependency fetching logic), which is effectively impossible right now since all packages must be hosted online somewhere. @andrewrk, do you have any thoughts or an alternate solution to these issues?

@jmrico01
Copy link
Contributor Author

jmrico01 commented Sep 17, 2023

Thanks, that's some great context. Commented with my thoughts on the PR, hopefully it's useful and not adding too much noise.

In the meantime, are there any workarounds for this? I'd like to leverage the package manager dependency import with a local Zig project that has its own set of dependencies. I tired declaring those downstream dependencies in a root-level build.zig.zon, but that doesn't work 😢

EDIT: Found 2 workarounds for now. The first is to change downstream .dependencys inside deps/common/build.zig to also use .anonymousDependency, so that no nested dependencies have to be fetched through the build.zig.zon. This is actually pretty doable with my setup. The second is to find the temporary dirs where dependencies are fetched and edit the code there to rebuild & test library changes. In Windows, the temp dir is C:\Users\<user>\AppData\Local\zig\p.

@Vexu Vexu added the zig build system std.Build, the build runner, `zig build` subcommand, package management label Nov 29, 2023
@Vexu Vexu added this to the 0.13.0 milestone Nov 29, 2023
@andrewrk andrewrk modified the milestones: 0.14.0, 0.15.0 Feb 10, 2025
@castholm
Copy link
Contributor

b.anonymousDependency was removed and support for relative paths in build.zig.zon added in 0.12 so this can probably be closed.

@jmrico01
Copy link
Contributor Author

b.anonymousDependency was removed and support for relative paths in build.zig.zon added in 0.12 so this can probably be closed.

Yes, thanks! Forgot about this issue. I've been using relative paths in build.zig.zon without any problems. Closing...

@jacobly0 jacobly0 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 12, 2025
@jacobly0 jacobly0 removed this from the 0.15.0 milestone Feb 12, 2025
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

No branches or pull requests

6 participants