Build version information

Is it possible to access zig compiler version inside zig code?
I want something like “0.11.0-dev.980+601ab9a25” to be included inside my code.
I don’t see anything related in builtin.zig and grep didn’t find anything with ‘0.11.0’ string inside installed files.

Workaround would be to have build.zig to generate that information inside file which could be included later.


Sorry this isn’t more helpful, but I know that zls does this somehow!

const builtin = @import("builtin");

in there you will find zig_version_string and zig_version.

See the language reference for more info:


I wonder - there’s lib/std/builtin.zig, but it looks like it’s not the same as what we get with @import("builtin");, as there are no traces of zig_version or zig_version_string there.

Also there’s neither builtin folder in lib/std nor builtin / builtin.zig in lib.

What does @import("builtin"); import then?

“builtin” is a module generated by the compiler that contains information about the current build (target, optimization mode, etc). if you do “goto definition” in ZLS you will see that it points to a file somewhere in zig-cache.

The builtin namespace in the stdlib contains the type definitions of the structs, enums, etc, that the compiler puts in the builtin module.

1 Like

Thank you. I was suspecting that “builtin” is actually a built-in module, not a part of stdlib.

My ZLS can’t find builtin or anything within it, which is why I started looking in stdlib myself in the first place. Maybe it’s because I use the latest nightly build of Zig with ZLS 0.11.0, or maybe because I my ZLS config isn’t good enough, who knows.

Yep, ZLS needs to understand your build script in order to provide information about modules, and if you have a big mismatch between ZLS and Zig this process will fail.