Developing on Linux but need to test a Windows .dll? Zig ships a single toolchain that can cross-compile for any target, and Affix::Build speaks Zig natively via lang => 'zig'. By passing a -target flag, you can produce Windows binaries straight from a Linux box.

The Recipe

We will configure Affix::Build to target Windows x86_64 from a Linux machine using Zig's built-in cross-compilation.

use v5.40;
use Affix::Build;

# 1. Define the cross-compilation target
# This requires the 'zig' binary to be in your PATH
my $target = "x86_64-windows-gnu";

my $c = Affix::Build->new( name => 'cross_lib' );

# Zig source is C-ABI compatible: use the 'export' keyword.
# The '-target' flag is forwarded to 'zig build-lib'.
$c->add( \<<~'ZIG', lang => 'zig', flags => [ '-target', $target ] );
    export fn add(a: i32, b: i32) i32 {
        return a + b;
    }
ZIG

# 2. Link produces a Windows DLL even on Linux!
my $dll_path = $c->link;

say "Windows library created at: $dll_path";

How It Works