{fmt} C++ library uses build.zig
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2025-06-16 09:56:37 -03:00
.github/workflows ci: update mlugg/setup-zig@v2 2025-06-16 09:56:37 -03:00
.gitignore Initial project 2025-04-24 17:32:03 -03:00
build.zig simplify build library 2025-04-27 11:01:57 -03:00
build.zig.zon Initial project 2025-04-24 17:32:03 -03:00
LICENSE Add LICENSE 2025-04-24 17:38:46 -03:00
README.md Initial project 2025-04-24 17:32:03 -03:00

fmt-zig

Using build.zig integration for the {fmt} library - a modern formatting library providing a fast and safe alternative to C stdio and C++ iostreams.

Key features of {fmt}:

  • Fast and efficient formatting with type-safe format strings
  • Implements C++20 std::format
  • Supports user-defined types
  • Extensive formatting options and positional arguments
  • Modern clean API design
  • Header-only and compiled versions available

Requirements

  • zig v0.14.0 or master

How to build

Make directory and init

$ zig init
## add in 'build.zig.zon' fmt-zig package
$ zig fetch --save=fmt git+https://github.com/allyourcodebase/fmt-zig

Add in build.zig

const std = @import("std");

pub fn build(b: *std.Build) !void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const fmt_dep = b.dependency("fmt", .{
        .target = target,
        .optimize = optimize,
    });
    const fmt_artifact = fmt_dep.artifact("fmt");

    for(fmt_artifact.root_module.include_dirs.items) |include_dir| {
        try exe.root_module.include_dirs.append(b.allocator, include_dir);
    }
    exe.linkLibrary(fmt_artifact);
}