Skip to content

Adds support for Linux ARM GLESv2#2912

Draft
imsys wants to merge 3 commits intonesbox:mainfrom
imsys:build-linux-arm64-gles2
Draft

Adds support for Linux ARM GLESv2#2912
imsys wants to merge 3 commits intonesbox:mainfrom
imsys:build-linux-arm64-gles2

Conversation

@imsys
Copy link
Contributor

@imsys imsys commented Mar 17, 2026

This basically adds supports to many devices of Linux handhelds firmwares, like Rocknix, Knulli and others.

# ========================================================
# Dockerfile to build TIC-80 for TrimUI (AArch64)
# ========================================================

FROM ubuntu:22.04

# Install build dependencies
RUN apt-get update && apt-get install -y \
    cmake git make xz-utils wget curl python3 ruby rake pkg-config \
    && rm -rf /var/lib/apt/lists/*

# Install Arm GNU Toolchain (GCC 10.3.1, AArch64)
WORKDIR /opt
RUN wget https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz \
    && tar -xf gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz \
    && rm gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz

# Define Toolchain Paths
ENV CROSS_ROOT=/opt/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu
ENV PATH="${CROSS_ROOT}/bin:${PATH}"
ENV CROSS_COMPILE=aarch64-none-linux-gnu-

# Install symbol extraction dependencies
RUN apt-get update && apt-get install -y binutils libsdl2-dev libgles2-mesa-dev libegl1-mesa-dev

# Create stub libraries for linking (satisfied by device firmware at runtime)
# We extract the symbol names from the builder's libraries and generate empty C stubs.
# This prevents glibc versioning issues while satisfying the linker.
RUN for lib in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0 /usr/lib/x86_64-linux-gnu/libGLESv2.so.2 /usr/lib/x86_64-linux-gnu/libEGL.so.1; do \
        outname=$(basename $lib | sed 's/-2.0//; s/\.so\..*/.so/') && \
        echo "Generating stubs for $outname from $lib" && \
        nm -D $lib | grep " T " | awk '{print "void " $3 "(){}"}' > stubs.c && \
        ${CROSS_COMPILE}gcc -shared -o ${CROSS_ROOT}/aarch64-none-linux-gnu/libc/usr/lib/$outname stubs.c; \
    done

# --- Fetch TIC-80 ---
WORKDIR /wrk
#RUN git clone https://github.com/nesbox/tic-80.git && \
#    cd tic-80 && git submodule update --init --recursive
COPY . tic-80

# --- Build TIC-80 ---
WORKDIR /wrk/tic-80/build/trimui

RUN cmake ../.. \
      -DCMAKE_SYSTEM_NAME=Linux \
      -DCMAKE_SYSTEM_PROCESSOR=aarch64 \
      -DCMAKE_C_COMPILER=${CROSS_COMPILE}gcc \
      -DCMAKE_CXX_COMPILER=${CROSS_COMPILE}g++ \
      -DCMAKE_SYSROOT=${CROSS_ROOT}/aarch64-none-linux-gnu/libc \
      -DCMAKE_FIND_ROOT_PATH=${CROSS_ROOT}/aarch64-none-linux-gnu/libc \
      -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
      -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
      -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
      -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY \
      -DCMAKE_BUILD_TYPE=Release \
      -DBUILD_PRO=OFF \
      -DBUILD_WITH_ALL=ON \
      -DCMAKE_C_FLAGS_RELEASE="-mcpu=cortex-a53 -Ofast -flto" \
      -DCMAKE_CXX_FLAGS_RELEASE="-mcpu=cortex-a53 -Ofast -flto " \
      -DBUILD_SDL=ON \
      -DBUILD_SDLGPU=ON \
      -DBUILD_EDITORS=OFF \
      -DBUILD_SURF=ON \
      -DPREFER_SYSTEM_SDL2=ON \
      -DBUILD_STATIC=ON \
      -DTIC_DATA_PATH="/userdata/roms/tic80/"

RUN cmake --build . --target tic80 --config Release --parallel

RUN mkdir /output

# then get the file out with:

# docker run --rm -v "$PWD":/output tic-trimui:latest cp /wrk/tic-80/build/trimui/bin/tic80 /output 

RUN ["/bin/bash"]

imsys added 2 commits March 16, 2026 21:46
[Gemini]
1.  **Resolved Nintendo Switch Build**: The issue was that
`PREFER_SYSTEM_SDL2` was defined before the Switch platform block could
override the library preference. I moved all flag definitions in
CMakeLists.txt to the end of the platform detection block. This ensures
the Switch correctly identifies that it should use the system SDL2,
fixing the "Threads are needed" error.
2.  **Fixed GLES/EGL on Native ARM64 runners**: The previous logic
forced GLES on any Linux ARM system, which broke standard Linux ARM
runners that expect desktop OpenGL. I've updated the logic to only
auto-enable `USE_GLES2` and `USE_EGL` when `CMAKE_CROSSCOMPILING` is
`ON`.
*   **Handhelds**: Since your Docker builds cross-compile, they will
still have GLES enabled automatically.
*   **Native CI**: Standard native Linux runners will now default to
desktop OpenGL, fixing the `/usr/bin/ld: cannot find -lGLESv2` error.
3.  **Resolved `INTERFACE_SDL2_SHARED` conflict**: In sdl.cmake, the
`sdlgpu` target was sometimes linking to both `SDL2` and `SDL2-static`
aliases. When those both pointed to the same system shared library,
CMake crashed due to property conflicts. I've consolidated the linking
logic to ensure only one of them is linked, prioritizing the generic
`SDL2` target when using system libraries.
@imsys
Copy link
Contributor Author

imsys commented Mar 17, 2026

I plan to add the linux-arm64-gles2 to the Github CI/CD, but I will wait for the PR #2910 to be closed, as to avoid the git conflict.

There is also some other things I need to test and review.

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