Consistent import of the std module

Currently the standard library is a bit inconsistent with how it imports std in some places and std.zig in others . Is there a particular reason behind this (e.g avoiding running all tests when using zig test) or is this just a miss?

This was brought up recently in #stdlib-devel on Discord:

hello everyone, is @import("std") approach (Sorry I forgot proper word) should be used instead of @import("../some/dots/std.zig") everywhere in stdlib or is it only for specific usecases? I guess it’s first since we need to specify --zig-lib-dir when testing anyway (since we have both approaches in stdlib)

in general, modules are encouraged to use file-relative imports to import files from the current package, and std is no exception


Hopefully std: use relative imports for stdlib by tauoverpi · Pull Request #16837 · ziglang/zig · GitHub leads to a resolution. Wonder if a check for violations should be included with the changes.

1 Like

One problem I have with the stdlib being able to use @import("std") is the fact that user created modules cannot refer to themselves like that that without breaking tests modules can no longer depend on themself · Issue #14708 · ziglang/zig · GitHub.

It only works for std because it is a “magic” module.

1 Like