Search code examples
versionzig

How can I programmatically retrieve the version of Zig?


How do I programmatically retrieve the version of ?. In I could do it by using sys module.

>>> import sys
>>> sys.version

How can I achieve the same thing in ?


Solution

  • Use builtin.zig_version. That returns SemanticVersion.

    const std = @import("std");
    const builtin = @import("builtin");
    
    pub fn main() !void {
        std.log.info("Zig version: {}", .{ builtin.zig_version });
    }
    

    Prints:

    $ zig build run
    info: Zig version: 0.12.0-dev.587+eb072fa52