-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Directly from the docs:
Because the root module's root source file is always accessible using
@import("root")
, is is sometimes used by libraries — including the Zig Standard Library — as a place for the program to expose some "global" information to that library.
Problem is, that is the ONLY way to configure the standard library, and also it is wrong. It says that the "root source" of the "root module" is "always accessible" and to build a test we explicitly pass the values with those exact names:
const test_exe = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
}),
});
That root source of the root module IS NOT available on @import("root")
. I'm not even sure they are available anywhere at all.
After a few hours trying to figure out how to do this thing that should be super simple, it seems the only way to configure the std options is to implement your own test runner, which means copy-pasting an entire piece of the compiler source code and manually keeping it in sync with upstream. But the important point is that currently the docs make a guarantee that is objectively false and that nothing mentions that special declarations will not work for tests and require implementing your own test runner to set any of them.
Should the docs be updated to say that you have to copy code from the compiler into your project if your app has to configure something, was that actually supposed to work or is there some other way to configure the options?
In the process of figuring this out I found #12201, which was closed as "not planned". But what is "not planned"? Are options not planned to be configured from tests? Are the docs not planned to include how tests are different? Should any library that exposes global options for applications document that there is no planned support from the language to set any such options on tests unless they want to fork and maintain a piece of the test tooling?