-
-
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
expose the root source file with @import("root") #2189
Comments
Do i understand this correctly: a file that was specified when invoking the zig compiler is the root source file (for example |
that is correct. |
There is a problem. If you Anyways, this muddles with the very clean namespace semantics zig has. |
#1778 does not need this. You just use a comptime global in a package's namespace (does that exist?), set from the root source file. |
@shawnl how would this introduce infinite recursion? due to zig's lazy nature that would be perfectly fine and is no different than: pub const foo = @This(); for the root file. the following: use @import("@root"); // or use @This(); would be an infinite loop but that is another issue (#2580) altogether. |
We already rely on this behavior in bootstrap.zig but it is special magic:
zig/std/special/bootstrap.zig
Line 4 in 6cc2d39
This proposal would make it always available and so the above code would not be special magic anymore.
It's reasonable for userland libraries to have global configuration and use the root source file for that. For example this would be a necessary component of #1778.
This, along with #1439 would allow us to move some of the global panic function magic to userland, and potentially even the startup code.
build-exe
would unconditionally include the startup code, which would have acomptime
block which examines the root source file formain
,_start
, etc, and determines what it should export.The text was updated successfully, but these errors were encountered: