Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(native): the desktop host has a Linux half, judged by pixels in CI

esenginee173d4fbc765
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index e2d9c201c..dab99a624 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -608,3 +608,60 @@ jobs:
ESTELLA_VERIFY_MANIFEST=/scenes/hdr-bloom.textures.json \
ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=10 \
'ESTELLA_VERIFY_EXPECT=[{"x":0.5,"y":0.5,"rgb":[0,255,0],"tol":25},{"x":0.64,"y":0.5,"rgb":[0,255,0],"tol":35},{"x":0.85,"y":0.5,"rgb":[0,0,0],"tol":12}]'
+
+ # The native runtime, judged by pixels on a machine with no GPU.
+ #
+ # Until the desktop host existed the native runtime could only be checked on a
+ # simulator or a phone — where an OS dialog over the frame once made a dead app
+ # look healthy. A Linux runner IS one of the platforms it ships to, so it
+ # packages a real project the way the Package dialog does, runs the assembled
+ # app under a virtual display on a software Vulkan driver, and reads the frame.
+ desktop-linux:
+ name: Desktop host (Linux) + pixels
+ runs-on: ubuntu-latest
+ # The first run on a new dependency pin builds Dawn, which is tens of minutes;
+ # after that the cache makes it a compile of the host alone.
+ timeout-minutes: 90
+
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ submodules: recursive
+
+ - uses: ./.github/actions/setup
+
+ # The SDK bundle is compiled into the host binary.
+ - name: Build SDK
+ run: pnpm --filter ./sdk build
+
+ - name: Read the native dependency pins
+ id: pins
+ run: node build-tools/cli.js native --deps-cache-key linux >> "$GITHUB_OUTPUT"
+
+ - name: Cache the pinned checkouts + Dawn build
+ uses: actions/cache@v4
+ with:
+ path: build/native-deps
+ key: ${{ steps.pins.outputs.key }}
+
+ # Vulkan for Dawn, X11/Wayland for the window, fontconfig and libcurl for the
+ # per-OS seam, and the software driver + virtual display that let a runner
+ # with neither a GPU nor a screen answer a question about pixels.
+ - name: Set up the Linux desktop dependencies
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y ninja-build libvulkan-dev mesa-vulkan-drivers xvfb \
+ libx11-dev libxrandr-dev libxi-dev libxcursor-dev libxinerama-dev \
+ libxkbcommon-dev libwayland-dev wayland-protocols libfontconfig1-dev \
+ libcurl4-openssl-dev libasound2-dev libpulse-dev libudev-dev libdrm-dev libgbm-dev
+
+ - name: Fetch Dawn + QuickJS + SDL at their pinned commits
+ run: node build-tools/cli.js native --fetch-deps
+
+ - name: Build the Linux host and its runtime template
+ run: node build-tools/cli.js native --target linux
+
+ - name: A game packaged from it renders
+ env:
+ VK_ICD_FILENAMES: /usr/share/vulkan/icd.d/lvp_icd.x86_64.json
+ run: xvfb-run -a --server-args="-screen 0 1280x720x24" node tools/verify-desktop-render.mjs --examples hello-world
diff --git a/.github/workflows/native-deps-cache.yml b/.github/workflows/native-deps-cache.yml
index 6427d6083..c80b6fd05 100644
--- a/.github/workflows/native-deps-cache.yml
+++ b/.github/workflows/native-deps-cache.yml
@@ -63,6 +63,8 @@ jobs:
os: macos-latest
- target: windows
os: windows-latest
+ - target: linux
+ os: ubuntu-latest
steps:
# No submodules: Dawn and QuickJS are fetched into build/native-deps by
# --fetch-deps, and third_party is the HOST's dependency, which this never
@@ -109,6 +111,18 @@ jobs:
if: startsWith(matrix.os, 'macos') && steps.restore.outputs.cache-hit != 'true'
run: brew install cmake ninja
+ # Vulkan headers for Dawn, and the display-server + font + HTTP libraries the
+ # host links. Named here rather than assumed: an ubuntu runner carries none
+ # of them, and the failure is a configure that cannot find a package.
+ - name: Set up the Linux desktop dependencies
+ if: matrix.target == 'linux' && steps.restore.outputs.cache-hit != 'true'
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y ninja-build libvulkan-dev libx11-dev libxrandr-dev \
+ libxi-dev libxcursor-dev libxinerama-dev libxkbcommon-dev libwayland-dev \
+ wayland-protocols libfontconfig1-dev libcurl4-openssl-dev libasound2-dev \
+ libpulse-dev libudev-dev libdrm-dev libgbm-dev
+
- name: Set up Ninja (Windows)
if: matrix.target == 'windows' && steps.restore.outputs.cache-hit != 'true'
uses: seanmiddleditch/gha-setup-ninja@v6
diff --git a/.github/workflows/release-desktop.yml b/.github/workflows/release-desktop.yml
index f4f7f5e30..043a193d3 100644
--- a/.github/workflows/release-desktop.yml
+++ b/.github/workflows/release-desktop.yml
@@ -123,6 +123,8 @@ jobs:
os: macos-latest
- name: windows
os: windows-latest
+ - name: linux
+ os: ubuntu-latest
runs-on: ${{ matrix.os }}
timeout-minutes: 120
steps:
@@ -160,6 +162,18 @@ jobs:
if: startsWith(matrix.os, 'macos')
run: brew install cmake ninja
+ # Vulkan for Dawn, X11/Wayland for the window, fontconfig and libcurl for the
+ # per-OS seam — plus the software Vulkan driver, which is what makes a
+ # runner with no GPU able to answer the pixel question below.
+ - name: Set up the Linux desktop dependencies
+ if: matrix.name == 'linux'
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y ninja-build libvulkan-dev mesa-vulkan-drivers xvfb \
+ libx11-dev libxrandr-dev libxi-dev libxcursor-dev libxinerama-dev \
+ libxkbcommon-dev libwayland-dev wayland-protocols libfontconfig1-dev \
+ libcurl4-openssl-dev libasound2-dev libpulse-dev libudev-dev libdrm-dev libgbm-dev
+
- name: Set up Ninja (Windows)
if: matrix.name == 'windows'
uses: seanmiddleditch/gha-setup-ninja@v6
@@ -203,7 +217,7 @@ jobs:
# licensed to partners, so it reaches a package from the developer's own SDK
# (Project Settings -> Packaging -> Steamworks SDK), never from here.
- name: Build the desktop template
- if: matrix.name == 'macos' || matrix.name == 'windows'
+ if: matrix.name == 'macos' || matrix.name == 'windows' || matrix.name == 'linux'
run: node build-tools/cli.js native --target ${{ matrix.name }} --template-out artifacts
# The claim a template archive cannot make: that a game packaged from it
@@ -214,6 +228,17 @@ jobs:
if: matrix.name == 'macos' || matrix.name == 'windows'
run: node tools/verify-desktop-render.mjs --examples hello-world,particle-demo
+ # Under a virtual display, on a software Vulkan driver: an ubuntu runner has
+ # neither a screen nor a GPU, and the judge reads PIXELS — so give it the two
+ # things it needs rather than weakening what it asks.
+ - name: A game packaged from it renders (Linux)
+ if: matrix.name == 'linux'
+ env:
+ # lavapipe. Without it Dawn picks nothing and the host reports a lost
+ # device, which is a true answer to a question about the runner.
+ VK_ICD_FILENAMES: /usr/share/vulkan/icd.d/lvp_icd.x86_64.json
+ run: xvfb-run -a --server-args="-screen 0 1280x720x24" node tools/verify-desktop-render.mjs --examples hello-world
+
- name: Upload template artifact
uses: actions/upload-artifact@v7
with:
diff --git a/build-tools/tasks/native.js b/build-tools/tasks/native.js
index 446dc9f5a..0e87776f7 100644
--- a/build-tools/tasks/native.js
+++ b/build-tools/tasks/native.js
@@ -342,8 +342,9 @@ async function sdlPrefix(options, target) {
function hostDesktopTarget() {
if (process.platform === 'darwin') return 'macos';
if (process.platform === 'win32') return 'windows';
- throw new Error(`The desktop host has no ${process.platform} support yet `
- + '(its surface kind and font seam are not written) — see docs/REARCH_STEAM.md S3c.');
+ if (process.platform === 'linux') return 'linux';
+ throw new Error(`The desktop host has no ${process.platform} support: its surface kind and `
+ + 'font seam are not written — see docs/REARCH_STEAM.md.');
}
async function buildDesktopHost(options) {
@@ -505,6 +506,7 @@ const XCFRAMEWORK = path.join('build/cmake/native-ios', 'Estella.xcframework');
const DESKTOP_BUILD_DIR = {
macos: 'build/cmake/native-macos',
windows: 'build/cmake/native-windows',
+ linux: 'build/cmake/native-linux',
};
// Rebuild the xcframework from whichever slices exist. A device-only framework is
diff --git a/build-tools/tasks/nativeDeps.js b/build-tools/tasks/nativeDeps.js
index 687569edc..c9fd5b9af 100644
--- a/build-tools/tasks/nativeDeps.js
+++ b/build-tools/tasks/nativeDeps.js
@@ -33,7 +33,7 @@ export function nativePins(rootDir = config.paths.root) {
/** Whether a target is one of the desktop OSes — the ones whose window, event loop
* and gamepads come from SDL rather than from the OS's own app framework. */
export function isDesktopTarget(target) {
- return target === 'macos' || target === 'windows';
+ return target === 'macos' || target === 'windows' || target === 'linux';
}
/**
@@ -171,6 +171,8 @@ export const DAWN_TARGETS = {
// executable has no rpath to get wrong (docs/REARCH_STEAM.md §3).
macos: { out: 'out-macos', backend: 'metal' },
windows: { out: 'out-windows', backend: 'd3d12' },
+ // Vulkan, as Android is — and static, as the other two desktops are.
+ linux: { out: 'out-linux', backend: 'vulkan' },
};
/**
diff --git a/build-tools/utils/desktopApp.d.ts b/build-tools/utils/desktopApp.d.ts
index 9b3565dfd..73ad27c04 100644
--- a/build-tools/utils/desktopApp.d.ts
+++ b/build-tools/utils/desktopApp.d.ts
@@ -12,7 +12,7 @@ export interface DesktopAppIdentity {
export function assembleDesktopApp(options: {
/** Which desktop OS the app is for; also which template layout is read. */
- platform: 'macos' | 'windows';
+ platform: 'macos' | 'windows' | 'linux';
/** An installed runtime template for that OS. */
templateDir: string;
/** The export: cooked content plus the two configs. */
diff --git a/build-tools/utils/desktopApp.js b/build-tools/utils/desktopApp.js
index 122358c0a..b8678321a 100644
--- a/build-tools/utils/desktopApp.js
+++ b/build-tools/utils/desktopApp.js
@@ -44,6 +44,14 @@ const LAYOUT = {
content: 'Content',
beside: '.',
},
+ // The same shape as Windows, without the extension: a directory a depot maps
+ // whole, with the runtime at its root.
+ linux: {
+ root: (name) => name,
+ executable: (name) => name,
+ content: 'Content',
+ beside: '.',
+ },
};
/**
@@ -54,7 +62,7 @@ const LAYOUT = {
* through Platform::readAsset, exactly as the APK's assets/ is one namespace.
*
* @param {object} options
- * @param {'macos'|'windows'} options.platform
+ * @param {'macos'|'windows'|'linux'} options.platform
* @param {string} options.templateDir Installed runtime template.
* @param {string} options.contentDir The editor export to ship.
* @param {string} options.outDir Where the app directory is written.
@@ -70,7 +78,7 @@ const LAYOUT = {
export async function assembleDesktopApp(options) {
const { platform, templateDir, contentDir, outDir, app } = options;
const layout = LAYOUT[platform];
- if (!layout) throw new Error(`no desktop layout for "${platform}" (macos, windows)`);
+ if (!layout) throw new Error(`no desktop layout for "${platform}" (macos, windows, linux)`);
const sources = desktopTemplateSources(templateDir, platform);
if (!existsSync(sources.executable)) {
diff --git a/build-tools/utils/nativeTemplate.js b/build-tools/utils/nativeTemplate.js
index 18e7844c6..eb94a401a 100644
--- a/build-tools/utils/nativeTemplate.js
+++ b/build-tools/utils/nativeTemplate.js
@@ -130,7 +130,7 @@ export function templateLayout(platform, options = {}) {
},
];
}
- if (platform === 'macos' || platform === 'windows') {
+ if (platform === 'macos' || platform === 'windows' || platform === 'linux') {
const exe = platform === 'windows' ? 'estella_desktop.exe' : 'estella_desktop';
const buildDir = `build/cmake/native-${platform}`;
// The shortest layout of the three, because a desktop build embeds
diff --git a/desktop/electron/exportGame.ts b/desktop/electron/exportGame.ts
index 67ba086b4..34452b275 100644
--- a/desktop/electron/exportGame.ts
+++ b/desktop/electron/exportGame.ts
@@ -741,11 +741,6 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>
+ 'Project, then export again.');
}
for (const { os, dir } of templates) {
- if (os === 'linux') {
- warnings.push('The Linux desktop host is not written yet, so its template was skipped '
- + '(docs/REARCH_STEAM.md §0g).');
- continue;
- }
progress({ phase: `Assembling the ${os} app` });
const built = await assembleDesktopApp({
platform: os, templateDir: dir, contentDir: absOut, outDir: absOut, app: appConfig,
diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt
index 6fa30fb5f..5d0a8925f 100644
--- a/native/CMakeLists.txt
+++ b/native/CMakeLists.txt
@@ -31,9 +31,12 @@ elseif(APPLE)
elseif(WIN32)
set(ESTELLA_DESKTOP ON)
set(ESTELLA_WINDOWS ON)
+elseif(UNIX)
+ set(ESTELLA_DESKTOP ON)
+ set(ESTELLA_LINUX ON)
else()
message(FATAL_ERROR "Unsupported platform: configure with the NDK toolchain (Android), "
- "-DCMAKE_SYSTEM_NAME=iOS, or run on macOS/Windows for the desktop host.")
+ "-DCMAKE_SYSTEM_NAME=iOS, or run on macOS/Windows/Linux for the desktop host.")
endif()
# The desktop host is an EXECUTABLE that embeds everything (see docs/REARCH_STEAM.md
@@ -348,6 +351,8 @@ if(ESTELLA_QUICKJS_DIR)
# font match and the HTTP request.
if(ESTELLA_WINDOWS)
set(DESKTOP_OS_SOURCES host/platform/windows_common.cpp)
+ elseif(ESTELLA_LINUX)
+ set(DESKTOP_OS_SOURCES host/platform/linux_common.cpp)
else()
set(DESKTOP_OS_SOURCES host/platform/apple_common.mm)
endif()
@@ -364,6 +369,17 @@ if(ESTELLA_QUICKJS_DIR)
# it lives in kernelbase, kernel32 does not re-export it, and the SDK
# ships no kernelbase.lib — onecore is the umbrella that has it.
target_link_libraries(estella_js_host d3d12 dxgi dxguid dwrite winhttp onecore)
+ elseif(ESTELLA_LINUX)
+ # fontconfig for the font match; libcurl for the fetch, because Linux
+ # is the one desktop with no OS-provided HTTP stack and no trust store
+ # of its own to reach (see host/platform/linux_common.hpp). Both are
+ # found through pkg-config, which is how every distribution describes
+ # where it put them.
+ find_package(PkgConfig REQUIRED)
+ pkg_check_modules(FONTCONFIG REQUIRED IMPORTED_TARGET fontconfig)
+ pkg_check_modules(LIBCURL REQUIRED IMPORTED_TARGET libcurl)
+ target_link_libraries(estella_js_host PkgConfig::FONTCONFIG PkgConfig::LIBCURL
+ ${CMAKE_DL_LIBS} pthread)
else()
# As on iOS: miniaudio's CoreAudio backend reaches for the Obj-C runtime,
# so its TU is Objective-C++ on every Apple platform.
diff --git a/native/host/platform/desktop.cpp b/native/host/platform/desktop.cpp
index c8ab90973..8c589f4b3 100644
--- a/native/host/platform/desktop.cpp
+++ b/native/host/platform/desktop.cpp
@@ -39,6 +39,8 @@
#include "platform/apple_common.hpp"
#elif defined(_WIN32)
#include "platform/windows_common.hpp"
+#else
+#include "platform/linux_common.hpp"
#endif
using esengine::u32;
@@ -100,8 +102,12 @@ struct DesktopPlatform final : eshost::Platform {
SDL_Window* window = nullptr;
/** The CAMetalLayer / HWND / Wayland surface Dawn draws into, from SDL. */
void* nativeWindow = nullptr;
- /** Win32 only: the HWND's HINSTANCE, which the surface descriptor also wants. */
+ /** What the window belongs to, which the surface descriptor wants beside it:
+ * the HINSTANCE on Win32, the wl_display / Display on Linux. */
void* windowInstance = nullptr;
+ /** Linux only: which display server this session actually is. Not a build-time
+ * fact — one binary runs on both, and SDL is what knows. */
+ bool wayland = false;
/** Where the packaged game's files are — see resolveContentRoot. */
std::string contentRoot;
/** SDL_GetPrefPath's directory, kept because every call allocates. */
@@ -232,7 +238,9 @@ struct DesktopPlatform final : eshost::Platform {
#elif defined(_WIN32)
return {WebGPUDevice::NativeWindowKind::Win32Hwnd, nativeWindow, windowInstance};
#else
-#error "The desktop host has no Linux surface yet — see docs/REARCH_STEAM.md S3c."
+ return {wayland ? WebGPUDevice::NativeWindowKind::WaylandSurface
+ : WebGPUDevice::NativeWindowKind::XlibWindow,
+ nativeWindow, windowInstance};
#endif
}
@@ -296,6 +304,12 @@ struct DesktopPlatform final : eshost::Platform {
}
void startFetch(const eshost::FetchRequest& req) override { eshost::windowsStartFetch(req); }
+#else
+ eshost::FontFile loadFont(const std::string& family, u32 codepoint, int style) override {
+ return eshost::linuxLoadFont(family, codepoint, style);
+ }
+
+ void startFetch(const eshost::FetchRequest& req) override { eshost::linuxStartFetch(req); }
#endif
};
@@ -465,6 +479,10 @@ int main(int argc, char** argv) {
SDL_WindowFlags flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_HIDDEN;
#if defined(__APPLE__)
flags |= SDL_WINDOW_METAL;
+#elif defined(__linux__)
+ // Dawn draws through Vulkan here, and a window created without this flag has
+ // no surface Vulkan can be handed.
+ flags |= SDL_WINDOW_VULKAN;
#endif
SDL_Window* window = SDL_CreateWindow(name.c_str(), kDefaultWidth, kDefaultHeight, flags);
if (!window) {
@@ -495,6 +513,28 @@ int main(int argc, char** argv) {
SDL_Quit();
return 1;
}
+#elif defined(__linux__)
+ // Which display server, asked of the SESSION rather than of the build: one
+ // binary runs on both, and a Wayland desktop and an X11 one hand Vulkan
+ // entirely different handles.
+ SDL_PropertiesID props = SDL_GetWindowProperties(window);
+ g_platform.wayland = SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0;
+ if (g_platform.wayland) {
+ g_platform.windowInstance = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, nullptr);
+ g_platform.nativeWindow = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, nullptr);
+ } else {
+ g_platform.windowInstance = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_X11_DISPLAY_POINTER, nullptr);
+ // An XID, not a pointer: it crosses the seam in the window field as the
+ // integer it is (see NativeSurface).
+ const Sint64 xid = SDL_GetNumberProperty(props, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
+ g_platform.nativeWindow = reinterpret_cast<void*>(static_cast<uintptr_t>(xid));
+ }
+ if (!g_platform.nativeWindow || !g_platform.windowInstance) {
+ SDL_Log("SDL gave no %s handles for the window — cannot create a Vulkan surface.",
+ g_platform.wayland ? "Wayland" : "X11");
+ SDL_Quit();
+ return 1;
+ }
#endif
if (!eshost::boot(g_platform)) {
diff --git a/native/host/platform/linux_common.cpp b/native/host/platform/linux_common.cpp
new file mode 100644
index 000000000..6c56c2050
--- /dev/null
+++ b/native/host/platform/linux_common.cpp
@@ -0,0 +1,203 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file linux_common.cpp
+ * @brief fontconfig font matching and libcurl fetching. See the header.
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the Apache License, Version 2.0.
+ */
+#include "platform/linux_common.hpp"
+
+#include <fontconfig/fontconfig.h>
+#include <curl/curl.h>
+
+#include <cstdio>
+#include <mutex>
+#include <thread>
+#include <vector>
+
+#include "media/glyph_raster.hpp" // GLYPH_BOLD / GLYPH_ITALIC
+
+namespace eshost {
+namespace {
+
+using esengine::u8;
+using esengine::u32;
+
+/** fontconfig's config, initialised once. Its first call reads every font on the
+ * machine, which is tens of milliseconds nobody should pay twice. */
+FcConfig* fonts() {
+ static FcConfig* config = [] {
+ return FcInitLoadConfigAndFonts();
+ }();
+ return config;
+}
+
+std::vector<u8> readWholeFile(const char* path) {
+ std::vector<u8> out;
+ std::FILE* file = std::fopen(path, "rb");
+ if (!file) return out;
+ std::fseek(file, 0, SEEK_END);
+ const long size = std::ftell(file);
+ std::fseek(file, 0, SEEK_SET);
+ if (size > 0) {
+ out.resize(static_cast<size_t>(size));
+ if (std::fread(out.data(), 1, out.size(), file) != out.size()) out.clear();
+ }
+ std::fclose(file);
+ return out;
+}
+
+/** The default family, matching the role Segoe UI plays on Windows and Helvetica
+ * on Apple: whatever this machine calls its sans-serif, which fontconfig knows
+ * and no distribution spells the same way. */
+constexpr const char* kDefaultFamily = "sans-serif";
+
+} // namespace
+
+FontFile linuxLoadFont(const std::string& family, u32 codepoint, int style) {
+ FontFile out;
+ FcConfig* config = fonts();
+ if (!config) return out;
+
+ FcPattern* pattern = FcPatternCreate();
+ if (!pattern) return out;
+ const std::string wanted = family.empty() ? kDefaultFamily : family;
+ FcPatternAddString(pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(wanted.c_str()));
+ if (style & GLYPH_BOLD) FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
+ if (style & GLYPH_ITALIC) FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
+ // The codepoint as a REQUIRED charset: this is what turns "find me this
+ // family" into "find me something that can draw this character", which is the
+ // CJK fallback and the whole reason font matching is platform code.
+ FcCharSet* charset = nullptr;
+ if (codepoint) {
+ charset = FcCharSetCreate();
+ FcCharSetAddChar(charset, codepoint);
+ FcPatternAddCharSet(pattern, FC_CHARSET, charset);
+ }
+
+ FcConfigSubstitute(config, pattern, FcMatchPattern);
+ FcDefaultSubstitute(pattern);
+
+ FcResult result = FcResultNoMatch;
+ FcPattern* matched = FcFontMatch(config, pattern, &result);
+ if (matched && result == FcResultMatch) {
+ FcChar8* file = nullptr;
+ int index = 0;
+ if (FcPatternGetString(matched, FC_FILE, 0, &file) == FcResultMatch && file) {
+ out.path = reinterpret_cast<const char*>(file);
+ out.bytes = readWholeFile(out.path.c_str());
+ if (out.bytes.empty()) out.path.clear();
+ }
+ // A collection (.ttc) holds several faces, so the index travels with the
+ // bytes or the rasterizer reads the wrong one.
+ if (FcPatternGetInteger(matched, FC_INDEX, 0, &index) == FcResultMatch) out.faceIndex = index;
+
+ // What the matched file does NOT provide of what was asked for. fontconfig
+ // answers the closest face it has, so a family with no bold comes back
+ // regular — and the rasterizer synthesizes the rest, as a browser does.
+ int weight = FC_WEIGHT_REGULAR;
+ int slant = FC_SLANT_ROMAN;
+ FcPatternGetInteger(matched, FC_WEIGHT, 0, &weight);
+ FcPatternGetInteger(matched, FC_SLANT, 0, &slant);
+ out.syntheticBold = (style & GLYPH_BOLD) && weight < FC_WEIGHT_DEMIBOLD;
+ out.syntheticItalic = (style & GLYPH_ITALIC) && slant == FC_SLANT_ROMAN;
+ }
+
+ if (matched) FcPatternDestroy(matched);
+ if (charset) FcCharSetDestroy(charset);
+ FcPatternDestroy(pattern);
+ return out;
+}
+
+namespace {
+
+size_t appendBody(char* data, size_t size, size_t count, void* user) {
+ auto* out = static_cast<std::vector<u8>*>(user);
+ out->insert(out->end(), data, data + size * count);
+ return size * count;
+}
+
+size_t appendHeader(char* data, size_t size, size_t count, void* user) {
+ auto* out = static_cast<std::vector<std::pair<std::string, std::string>>*>(user);
+ const std::string line(data, size * count);
+ const size_t colon = line.find(':');
+ if (colon != std::string::npos) {
+ auto trim = [](std::string s) {
+ while (!s.empty() && (s.back() == '\r' || s.back() == '\n' || s.back() == ' ')) s.pop_back();
+ size_t at = 0;
+ while (at < s.size() && s[at] == ' ') ++at;
+ return s.substr(at);
+ };
+ out->emplace_back(trim(line.substr(0, colon)), trim(line.substr(colon + 1)));
+ }
+ return size * count;
+}
+
+} // namespace
+
+void linuxStartFetch(const FetchRequest& req) {
+ // curl_global_init is not thread-safe and must run before the first easy
+ // handle; doing it here, once, keeps every caller from having to know that.
+ static std::once_flag once;
+ std::call_once(once, [] { curl_global_init(CURL_GLOBAL_DEFAULT); });
+
+ // A detached thread per request, as the other two platforms do: libcurl's
+ // easy API is synchronous, and deliverFetch is thread-safe by contract.
+ std::thread([req]() {
+ FetchResult result;
+ result.id = req.id;
+ result.isText = req.wantText;
+
+ CURL* curl = curl_easy_init();
+ if (!curl) {
+ result.error = "curl_easy_init failed";
+ deliverFetch(std::move(result));
+ return;
+ }
+
+ curl_slist* headers = nullptr;
+ for (const auto& [name, value] : req.headers) {
+ headers = curl_slist_append(headers, (name + ": " + value).c_str());
+ }
+
+ curl_easy_setopt(curl, CURLOPT_URL, req.url.c_str());
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+ curl_easy_setopt(curl, CURLOPT_USERAGENT, "Estella");
+ if (headers) curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
+ if (!req.method.empty() && req.method != "GET") {
+ curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, req.method.c_str());
+ }
+ if (!req.body.empty()) {
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, reinterpret_cast<const char*>(req.body.data()));
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, static_cast<long>(req.body.size()));
+ }
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, appendBody);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result.body);
+ curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, appendHeader);
+ curl_easy_setopt(curl, CURLOPT_HEADERDATA, &result.headers);
+
+ const CURLcode code = curl_easy_perform(curl);
+ if (code == CURLE_OK) {
+ long status = 0;
+ curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);
+ result.status = static_cast<int>(status);
+ result.ok = status >= 200 && status < 300;
+ result.statusText = result.ok ? "OK" : "";
+ } else {
+ // curl's own words: "it failed" without a reason is not something a
+ // game can act on, and this is a network round trip.
+ result.error = curl_easy_strerror(code);
+ }
+
+ if (headers) curl_slist_free_all(headers);
+ curl_easy_cleanup(curl);
+ deliverFetch(std::move(result));
+ }).detach();
+}
+
+} // namespace eshost
diff --git a/native/host/platform/linux_common.hpp b/native/host/platform/linux_common.hpp
new file mode 100644
index 000000000..804b82d61
--- /dev/null
+++ b/native/host/platform/linux_common.hpp
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file linux_common.hpp
+ * @brief The two halves of the platform seam SDL does not cover on Linux:
+ * matching a font file (fontconfig) and performing an HTTP request
+ * (libcurl). The siblings are apple_common.hpp and windows_common.hpp.
+ *
+ * @details Linux differs from the other two in one way worth writing down: it
+ * has no OS-provided HTTP stack. macOS has NSURLSession and Windows has
+ * WinHTTP, both of which own the TLS trust store; on Linux that job
+ * belongs to a library, and libcurl is the one every distribution ships
+ * and the Steam Runtime carries. So it is a link-time dependency of the
+ * Linux host, and the only one this seam adds beyond fontconfig.
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the Apache License, Version 2.0.
+ */
+#pragma once
+
+#include <string>
+
+#include "Host.hpp"
+
+namespace eshost {
+
+/** A font file for @p family covering @p codepoint, with @p style's bold/italic
+ * bits applied — implements Platform::loadFont.
+ *
+ * fontconfig falls back across the installed fonts when given the codepoint as a
+ * required charset: the CJK path, with no per-distribution path hard-coded. */
+FontFile linuxLoadFont(const std::string& family, esengine::u32 codepoint, int style);
+
+/** Run @p req on a libcurl worker thread and hand the reply to deliverFetch —
+ * see Platform::startFetch. */
+void linuxStartFetch(const FetchRequest& req);
+
+} // namespace eshost
diff --git a/src/esengine/renderer/webgpu/WebGPUDevice.cpp b/src/esengine/renderer/webgpu/WebGPUDevice.cpp
index b6b589d72..aad5adfb4 100644
--- a/src/esengine/renderer/webgpu/WebGPUDevice.cpp
+++ b/src/esengine/renderer/webgpu/WebGPUDevice.cpp
@@ -291,6 +291,31 @@ bool WebGPUDevice::configureSurface(const NativeSurface& window, u32 width, u32
win32.hwnd = window.handle;
sd.nextInChain = &win32.chain;
surface_ = wgpuInstanceCreateSurface(instance_, &sd);
+#endif
+ break;
+ }
+ case NativeWindowKind::WaylandSurface: {
+#if defined(__linux__)
+ WGPUSurfaceSourceWaylandSurface wayland{};
+ wayland.chain.sType = WGPUSType_SurfaceSourceWaylandSurface;
+ wayland.display = window.instance; // wl_display*
+ wayland.surface = window.handle; // wl_surface*
+ sd.nextInChain = &wayland.chain;
+ surface_ = wgpuInstanceCreateSurface(instance_, &sd);
+#endif
+ break;
+ }
+ case NativeWindowKind::XlibWindow: {
+#if defined(__linux__)
+ WGPUSurfaceSourceXlibWindow xlib{};
+ xlib.chain.sType = WGPUSType_SurfaceSourceXlibWindow;
+ xlib.display = window.instance; // Display*
+ // The XID is an integer, not a pointer — it travels in `handle`
+ // because the seam carries one window field, and is read back as the
+ // integer it is rather than dereferenced.
+ xlib.window = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(window.handle));
+ sd.nextInChain = &xlib.chain;
+ surface_ = wgpuInstanceCreateSurface(instance_, &sd);
#endif
break;
}
diff --git a/src/esengine/renderer/webgpu/WebGPUDevice.hpp b/src/esengine/renderer/webgpu/WebGPUDevice.hpp
index 3f9a064a7..9b1a22d72 100644
--- a/src/esengine/renderer/webgpu/WebGPUDevice.hpp
+++ b/src/esengine/renderer/webgpu/WebGPUDevice.hpp
@@ -191,16 +191,21 @@ public:
#endif
/** The kind of native window a non-emscripten host draws into. */
- enum class NativeWindowKind { MetalLayer, AndroidWindow, Win32Hwnd };
+ /** Linux is TWO kinds because a Linux desktop is two display servers, and
+ * which one a machine is running is not a build-time fact. */
+ enum class NativeWindowKind { MetalLayer, AndroidWindow, Win32Hwnd, WaylandSurface, XlibWindow };
- /** A `CAMetalLayer*` / `ANativeWindow*` / `HWND` for a native-C++ build;
- * compiled out of the wasm build, where the host injects an already-built
- * surface instead. */
+ /** A `CAMetalLayer*` / `ANativeWindow*` / `HWND` / `wl_surface*` for a
+ * native-C++ build; compiled out of the wasm build, where the host injects an
+ * already-built surface instead. */
struct NativeSurface {
NativeWindowKind kind;
+ /** The window: an `HWND`, a `wl_surface*` — or, for Xlib, the `Window`
+ * XID, which is an integer and travels here as one. */
void* handle;
- /** Win32 only: the `HINSTANCE` the window belongs to, which the surface
- * descriptor asks for beside the HWND. */
+ /** What the window belongs to, which the descriptor asks for beside it:
+ * the `HINSTANCE` on Win32, the `wl_display*` on Wayland, the `Display*`
+ * on Xlib. */
void* instance = nullptr;
};