You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 PATHmy$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
Toolchain Abstraction Affix::Build resolves lang => 'zig' to the zig build-lib command and forwards any flags you pass via add's flags parameter. Because Zig ships the headers, stdlibs, and linkers for Windows, macOS, and Linux inside a single binary, cross-compiling is just a matter of swapping the -target value.
The .dll result
The -target x86_64-windows-gnu tells Zig to emit a Portable Executable (PE) file. The output is written to Affix::Build's default name, which follows your host platform's shared-library convention (e.g., libcross_lib.so on Linux) — but the contents are a Windows DLL. Copy the file to a Windows machine and load it with Affix::load_library.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Developing on Linux but need to test a Windows
.dll? Zig ships a single toolchain that can cross-compile for any target, andAffix::Buildspeaks Zig natively vialang => 'zig'. By passing a-targetflag, you can produce Windows binaries straight from a Linux box.The Recipe
We will configure
Affix::Buildto target Windowsx86_64from a Linux machine using Zig's built-in cross-compilation.How It Works
Toolchain Abstraction
Affix::Buildresolveslang => 'zig'to thezig build-libcommand and forwards any flags you pass viaadd'sflagsparameter. Because Zig ships the headers, stdlibs, and linkers for Windows, macOS, and Linux inside a single binary, cross-compiling is just a matter of swapping the-targetvalue.The
.dllresultThe
-target x86_64-windows-gnutells Zig to emit a Portable Executable (PE) file. The output is written toAffix::Build's default name, which follows your host platform's shared-library convention (e.g.,libcross_lib.soon Linux) — but the contents are a Windows DLL. Copy the file to a Windows machine and load it withAffix::load_library.All reactions