diff --git a/.github/workflows/launcher.yml b/.github/workflows/launcher.yml index 608d26914..18c9a2296 100644 --- a/.github/workflows/launcher.yml +++ b/.github/workflows/launcher.yml @@ -27,7 +27,12 @@ jobs: - os: windows-latest asset: horizon-launcher-windows-x64.zip binary: horizon-launcher.exe + # The C runtime linked in: without it the launcher asks for VCRUNTIME140.dll, + # which only the Visual C++ redistributable installs. + rustflags: -C target-feature=+crt-static runs-on: ${{ matrix.os }} + env: + RUSTFLAGS: ${{ matrix.rustflags }} defaults: run: working-directory: launcher @@ -48,6 +53,9 @@ jobs: run: grep -qx "version = \"${GITHUB_REF_NAME#launcher-v}\"" Cargo.toml - run: cargo test --release --locked --lib - run: cargo build --release --locked + - name: Only system libraries + if: runner.os == 'Windows' + run: python ../tools/check_imports.py target/release/${{ matrix.binary }} - name: Package run: | mkdir -p dist diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ed094cdef..b6e36a6e3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,9 @@ name: release builds # Started by hand: gh workflow run release.yml --ref -# Builds the Windows x64 client and uploads the playable folder as an artifact. -# Linux and macOS builds are made on the development machines. +# Builds the Windows x64 and Linux x86_64 clients and uploads the playable folders as artifacts. +# macOS builds are made on the development machines. Linux is built here, on an older Ubuntu, +# so the binary uses the standard loader and runs on any recent distribution (and on NixOS +# through nix-ld): a build made on NixOS asks for a /nix/store loader no other system has. on: workflow_dispatch: permissions: @@ -18,6 +20,10 @@ jobs: env: RUSTFLAGS: -C target-feature=+crt-static run: cargo +stable build --release --locked -p horizon-client --bin horizon-client + - name: Only system DLLs + # Vulkan and the rest are loaded at run time; a linked non-system DLL is a + # "DLL not found" dialog on some players' machines. + run: python tools/check_imports.py target/release/horizon-client.exe - name: Package shell: bash run: packaging/package.sh target/release/horizon-client.exe dist/horizon-windows-x64 @@ -25,3 +31,21 @@ jobs: with: name: horizon-windows-x64 path: dist/horizon-windows-x64 + linux: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: Install Rust toolchain + run: rustup toolchain install stable --profile minimal + - name: ALSA headers + run: sudo apt-get update && sudo apt-get install -y --no-install-recommends libasound2-dev + - name: Build the client + run: cargo +stable build --release --locked -p horizon-client --bin horizon-client + - name: Standard loader and libraries only + run: python3 tools/check_imports.py target/release/horizon-client + - name: Package + run: packaging/package.sh target/release/horizon-client dist/horizon-linux-x86_64 + - uses: actions/upload-artifact@v4 + with: + name: horizon-linux-x86_64 + path: dist/horizon-linux-x86_64 diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index 0a8896b6f..3d45098b0 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -214,6 +214,18 @@ fn mip_chain(pixels: &[u8], size: u32, layers: u32) -> (Vec, u32) { } (out, levels) } +/// What to tell a player whose system offers no usable graphics adapter. +/// Vulkan is loaded at run time (the game links no graphics library), so a +/// missing driver shows here rather than as a missing-DLL dialog. +#[cfg(target_os = "windows")] +const NO_GPU_DRIVER: &str = "No Vulkan graphics driver found: Horizon needs a GPU driver with Vulkan \ + (vulkan-1.dll comes with it). Install the latest driver for your NVIDIA, AMD or Intel GPU \ + and start the game again"; +#[cfg(target_os = "macos")] +const NO_GPU_DRIVER: &str = "No Metal graphics device found"; +#[cfg(not(any(target_os = "windows", target_os = "macos")))] +const NO_GPU_DRIVER: &str = "No Vulkan graphics driver found: Horizon needs the Vulkan loader \ + (libvulkan.so.1) and a Vulkan driver for your GPU (Mesa's, or NVIDIA's)"; impl Renderer { pub async fn new( window: Arc, @@ -234,7 +246,8 @@ impl Renderer { force_fallback_adapter: false, ..Default::default() }) - .await?; + .await + .map_err(|e| format!("{NO_GPU_DRIVER} ({e})"))?; let info = adapter.get_info(); eprintln!( "Horizon renderer: {} ({:?}, {:?})", diff --git a/crates/horizon-client/src/main.rs b/crates/horizon-client/src/main.rs index a9fb16aa8..febc160c3 100644 --- a/crates/horizon-client/src/main.rs +++ b/crates/horizon-client/src/main.rs @@ -5,6 +5,13 @@ mod game; fn main() { if let Err(error) = game::run() { eprintln!("Horizon: {error}"); + // Started from Explorer, the console window closes with the game: + // keep the message on screen until it is read. + #[cfg(windows)] + if std::io::IsTerminal::is_terminal(&std::io::stdin()) { + eprintln!("Press Enter to close."); + let _ = std::io::stdin().read_line(&mut String::new()); + } std::process::exit(1); } } diff --git a/tools/check_imports.py b/tools/check_imports.py new file mode 100644 index 000000000..74a53ec67 --- /dev/null +++ b/tools/check_imports.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python3 +"""Fail when a release binary needs a library its players may not have. + +Windows .exe: every DLL in the import and delay-import tables must ship with +Windows (no VCRUNTIME140.dll, vulkan-1.dll, ...): Vulkan and the like are +loaded at run time, so a missing driver is an error message, not a dialog. +Linux ELF: the loader must be the standard one (not a /nix/store path) and the +needed libraries the ones every desktop distribution has. +""" + +import argparse +import struct +import sys +from pathlib import Path + +# DLLs that are part of Windows 10 and 11. api-ms-win-* and ext-ms-win-* API +# sets resolve inside Windows too. +WINDOWS_SYSTEM = { + "advapi32.dll", "bcrypt.dll", "bcryptprimitives.dll", "cfgmgr32.dll", "combase.dll", + "comctl32.dll", "comdlg32.dll", "crypt32.dll", "d2d1.dll", "d3d11.dll", "d3d12.dll", + "d3dcompiler_47.dll", "dbghelp.dll", "dcomp.dll", "dwmapi.dll", "dwrite.dll", "dxgi.dll", + "gdi32.dll", "hid.dll", "icuuc.dll", "imm32.dll", "iphlpapi.dll", "kernel32.dll", + "kernelbase.dll", "mfplat.dll", "mmdevapi.dll", "msvcrt.dll", "ncrypt.dll", "ntdll.dll", + "ole32.dll", "oleaut32.dll", "opengl32.dll", "propsys.dll", "secur32.dll", "setupapi.dll", + "shcore.dll", "shell32.dll", "shlwapi.dll", "ucrtbase.dll", "user32.dll", "userenv.dll", + "uxtheme.dll", "version.dll", "winmm.dll", "ws2_32.dll", "xinput1_4.dll", +} +LINUX_LOADER = "/lib64/ld-linux-x86-64.so.2" +LINUX_SYSTEM = { + "libc.so.6", "libm.so.6", "libgcc_s.so.1", "libdl.so.2", "libpthread.so.0", "librt.so.1", + "ld-linux-x86-64.so.2", "libasound.so.2", +} + + +def windows_allowed(name): + name = name.lower() + return name in WINDOWS_SYSTEM or name.startswith(("api-ms-win-", "ext-ms-win-")) + + +def pe_imports(data): + """DLL names in a PE32+ file's import and delay-import tables.""" + pe = struct.unpack_from("