Skip to content

Build the NIF on Windows with Zig - #27

Open
misterjohannesson wants to merge 4 commits into
silviucpp:masterfrom
it-minds:win32-zig
Open

misterjohannesson wants to merge 4 commits into
silviucpp:masterfrom
it-minds:win32-zig

Conversation

@misterjohannesson

Copy link
Copy Markdown

The compile hook ran only on linux and darwin, so on Windows rebar3 built nothing and then failed on the missing priv/ezstd_nif.so artifact. A Windows hook — matched as "(win32|windows)", since OTP 25+ reports the arch as x86_64-pc-windows — now runs build_win32.ps1, which fetches zstd at the commit build_deps.sh pins, compiles it and the NIF with zig cc/c++ for x86_64-windows-gnu and links priv/ezstd_nif.dll. Zig carries its own compiler and Windows headers, so it is the only tool the build needs; the NIF API is reached through the callback table erl_nif.h uses on Windows, so no import library is involved. rebar.config.script renames the artifact to .dll there.

A CI workflow runs the suite on Linux, macOS and Windows.

The compile hook ran only on linux and darwin, so on Windows rebar3 built nothing and
then failed on the missing priv/ezstd_nif.so artifact. A Windows hook — matched as
"(win32|windows)", since OTP 25+ reports the arch as x86_64-pc-windows — now runs
build_win32.ps1, which fetches zstd at the commit build_deps.sh pins, compiles it and the
NIF with zig cc/c++ for x86_64-windows-gnu and links priv/ezstd_nif.dll. Zig carries its
own compiler and Windows headers, so it is the only tool the build needs; the NIF API is
reached through the callback table erl_nif.h uses on Windows, so no import library is
involved. rebar.config.script renames the artifact to .dll there. A CI workflow runs the
suite on Linux, macOS and Windows.
The GitHub Actions workflow was the wrong place for it: this repository builds on
Travis. Travis has no Erlang language support on Windows, so the job is a shell job
that installs Erlang and Zig from Chocolatey and runs rebar3 compile and ct through the
escript. The Linux jobs are unchanged.
… limit

The link needs libc++, which Zig compiles from its bundled sources the first time it
links it for a target, echoing some forty thousand warning lines from those sources
while it does; Travis kills a job whose log passes 4 MB. The script now builds it once
on a two-line file with the same flags, output kept unless it fails, and the real link
then finds it in the cache and prints only its own diagnostics.
Travis stops a job that has printed nothing for ten minutes, and on its Windows VM the
quiet libc++ build takes longer than that. The quiet runner now reports every thirty
seconds that it is still going, and the zstd object compiles announce each directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant