Skip to content

Build and Packaging

buntatoes edited this page Nov 28, 2026 · 1 revision

Build and Packaging

EU5 RPC builds and packages for both Windows and Linux using only Zig 0.17.1+ — no CMake, Make, Python, NSIS, Inno Setup, tar, or gzip required. Cross-compilation and release artifact generation are wired directly into build.zig.


Prerequisites

  • Zig 0.17.1 or newer (minimum_zig_version = "0.17.1" in build.zig.zon).
  • Zero external package dependencies (build.zig.zon has .dependencies = .{}).

Verify your Zig version:

zig version

Build Commands

git clone https://github.com/buntatoes/eu5-rpc.git
cd eu5-rpc

# 1. Run all unit tests
zig build test

# 2. Build an optimized native binary (zig-out/bin/eu5-rpc or eu5-rpc.exe)
zig build -Doptimize=ReleaseSafe

# 3. Cross-compile & package BOTH Windows GUI installer and Linux .tar.gz into dist/
zig build package

Build Options

build.zig exposes Zig's standard target and optimization options:

Option Example Behavior
-Doptimize= Debug, ReleaseSafe, ReleaseFast, ReleaseSmall Non-Debug builds automatically strip symbols (.strip = true) and set .subsystem = .windows on Windows so no console window appears.
-Dtarget= x86_64-windows-gnu, x86_64-linux-gnu.2.31 Cross-compiles the standalone eu5-rpc binary to any supported target.

Unit Test Suite (zig build test)

src/root.zig wires all 13 library modules into a single test entrypoint compiled and executed by zig build test:

Module What Is Tested
toml.zig Sections, inline # comments, single/double quotes, escapes, booleans, integers, and full parse -> dump -> parse roundtrip
config.zig Default DEFAULT_TOML parsing and {country}, {tag}, {year}, {date}, {age} template substitution
logger.zig ISO-8601 UTC epoch timestamp formatting (1970-01-01T00:00:00Z, 2023-11-14T22:13:20Z)
game_state.zig All six EU5 historical Ages (1337 onward), lobby/menu/in-game presence formatting, and live event vs. historical Age precedence
country_lookup.zig Paradox localization parsing (skipping $DYNAMIC$ placeholders), fallback tags, unknown tag uppercasing, and No/None rejection
save_inspector.zig SP_/MP_ save filename parsing, 2 KiB binary header extraction (#hex hash stripping, tag block, version), and end-to-end inspectUserDataDir
eu5_files.zig Steam libraryfolders.vdf & appmanifest_3450310.acf parsing, plus multi-library Proton user data folder prioritization
process.zig Native process checks and Linux /proc/<pid>/cmdline matching across Proton, Wine, reaper, gamescope, gamemoderun, mangohud, env, and false-positive guards
steam_rp.zig Live English Rich Presence + mid-game nation swaps, all 10 non-English official EU5 languages, observer strings, raw #playing_mp fallback tokens, and cleanPdxText
log_watcher.zig debug.log, multiplayer.log, and game.log parsing (Transition, NEW YEAR, SITUATION, WAR, CIVIL WAR, EXPLORATION, DISASTER, New Country, continue_game.json)
discord_ipc.zig Escaped SET_ACTIVITY JSON payload generation, timestamps, assets, and nonce formatting
updater.zig SemVer parsing/comparison (v0.3.3 -> v4.0.0 -> v4.1), GitHub JSON parsing, untrusted host rejection, and pure-Zig gzip + USTAR ELF extraction
tray.zig Thread-safe status buffer updates and atomic action polling

Pure-Zig Release Packaging (zig build package)

Running zig build package from either Linux or Windows produces both release artifacts in dist/:

flowchart LR
    SRC["src/*.zig + assets/ + LICENSE + README.md"] --> WIN["x86_64-windows-gnu ReleaseSafe (eu5-rpc.exe + icon.ico resource)"]
    SRC --> LIN["x86_64-linux-gnu.2.31 ReleaseSafe (eu5-rpc ELF)"]
    WIN --> INST["installer_win.zig (@embedFile payloads + COM IShellLinkW)"]
    INST --> OUTW["dist/EU5-RPC-Setup-v4.1.0-win64.exe"]
    LIN --> PKG["packager.zig (host tool: POSIX USTAR + std.compress.flate gzip)"]
    PKG --> OUTL["dist/eu5-rpc-linux-x86_64.tar.gz"]
Loading

1. Windows GUI Setup Installer (dist/EU5-RPC-Setup-v4.1.0-win64.exe)

  • Cross-compiles eu5-rpc.exe for x86_64-windows-gnu (ReleaseSafe, stripped, .windows subsystem) with assets/icon.ico compiled as Win32 resource 1 ICON "icon.ico" (attachWindowsIcon).
  • Links standard Windows system libraries:
    • Core binary: kernel32, advapi32, shell32, user32, ws2_32, crypt32
    • Setup installer: kernel32, user32, shell32, ole32, advapi32
  • Compiles src/installer_win.zig with five @embedFile anonymous imports: payload_exe, icon_ico, icon_png, license_txt, and readme_md.

2. Linux Native Archive (dist/eu5-rpc-linux-x86_64.tar.gz)

  • Cross-compiles eu5-rpc for x86_64-linux-gnu pinned to glibc 2.31.0 (ReleaseSafe, stripped) so the binary runs on older and newer Linux distributions alike.
  • Compiles and runs the host helper src/packager.zig, which writes a deterministic POSIX USTAR tar stream (fixed mtime, preserved permissions) compressed with Zig's std.compress.flate.Compress (.gzip) containing:
    • eu5-rpc-linux-x86_64/eu5-rpc (0755)
    • eu5-rpc-linux-x86_64/LICENSE (0644)
    • eu5-rpc-linux-x86_64/README.md (0644)
    • eu5-rpc-linux-x86_64/assets/icon.png (0644)
    • eu5-rpc-linux-x86_64/assets/icon.ico (0644)

Continuous Integration

GitHub Actions (.github/workflows/ci.yml) runs on every push and pull request to main across a two-OS matrix (ubuntu-latest and windows-latest) using mlugg/setup-zig@v2 with Zig 0.17.1:

  1. zig build test
  2. zig build -Doptimize=ReleaseSafe
  3. zig build package