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

Samples build.zig cannot be directly used #597

Open
Pyrolistical opened this issue May 15, 2024 · 6 comments
Open

Samples build.zig cannot be directly used #597

Pyrolistical opened this issue May 15, 2024 · 6 comments

Comments

@Pyrolistical
Copy link
Contributor

Pyrolistical commented May 15, 2024

If you try to build a sample directly, it errors:

$ cd samples\minimal_d3d12
$ zig build
...\samples\minimal_d3d12\build.zig:4:25: error: import of file outside module path: '../../build.zig'
const Options = @import("../../build.zig").Options;
                        ^~~~~~~~~~~~~~~~~

I think we can refactor to directly pass in target and optimize but duplicate all other options as b.option.

@Pyrolistical

This comment was marked as off-topic.

@hazeycode
Copy link
Member

Yes the build.zigs for samples were not intended to be run using zig build.

Is there any benefit to doing this over just running a particular sample build command from the top level?

@Pyrolistical

This comment was marked as outdated.

@Pyrolistical
Copy link
Contributor Author

Oh I found another way to break the Options dep with an anytype:
https://github.com/Pyrolistical/zig-gamedev/pull/2/files

@hazeycode
Copy link
Member

hazeycode commented May 22, 2024

Oh I found another way to break the Options dep with an anytype: https://github.com/Pyrolistical/zig-gamedev/pull/2/files

I think we should make this change. Sample apps only consume a self-defined subset of options; and anytype is great for implicit interfaces.

@Pyrolistical
Copy link
Contributor Author

Pyrolistical commented May 22, 2024

I think this is blocked by samples/common.

For example samples/audio_experiments:

  1. Top-level build: sample uses @import("../common/build.zig"). This is allowed since both samples/audio_experiments and samples/common are children of cwd
  2. Direct sample build: Can't use @import("../common/build.zig") since cwd is samples/audio_experiments and ../common is not a child of cwd. This could be solved by adding common to build.zig.zon and @import("common"), but then we have @import("common") and @import("../common/build.zig") in the same file and zig doesn't like that. It sees it as a double import. Note that each @import would be inside fns, but zig still processes it even if the fn is unused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants