Skip to content

Setup

  1. Create a new Zig project called getty-learn:

    Shell session
    mkdir getty-learn
    cd getty-learn
    zig init
    
     

  2. Declare Getty as a dependency with zig fetch:

    Shell session
    zig fetch --save git+https://github.com/getty-zig/getty.git#<COMMIT>
    
     

  3. Expose Getty as a module in build.zig:

    build.zig
    pub fn build(b: *std.Build) void {
        const target = b.standardTargetOptions(.{});
        const optimize = b.standardOptimizeOption(.{});
    
        const opts = .{ .target = target, .optimize = optimize };
        const getty_mod = b.dependency("getty", opts).module("getty");
    
        const exe = b.addExecutable(.{
            .name = "my-project",
            .root_source_file = .{ .path = "src/main.zig" },
            .target = target,
            .optimize = optimize,
        });
        exe.root_module.addImport("getty", getty_mod);
    
        // ...
    }
    
     

  4. Replace src/main.zig's content with the following code to ensure everything is correct:

    src/main.zig
    const std = @import("std");
    const getty = @import("getty");
    
    pub fn main() !void {
        std.debug.print("Hello, {}!\n", .{getty});
    }
    
    Shell session
    $ zig build run
    Hello, getty!