field::execute_cost / execute_target / execute_operation push the running effect (handler, description, stable index, phase 1 / 2 / 3, chain link) on core.ygol_running at step 0 and pop it when the function finishes; the innermost entry is the effect that asks. effect::ygol_script_index is stamped in card::add_effect while the card loads (initial_effect.size()), 0xffff otherwise. The export writes 22 bytes; a handler the asking player does not control and that is not face-up answers code 0, index 0xffff, description 0. Export gates 335 / 856 / 850 -> 336 / 857 / 851. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
147 lines
8.7 KiB
Docker
147 lines
8.7 KiB
Docker
# syntax=docker/dockerfile:1.7
|
|
# Builds ygol-engine for Linux x64 and Android arm64 from this repo, with the gates the
|
|
# Windows build has (build/windows.ps1). Build context: the repo root.
|
|
# docker build -f build/Dockerfile --target linux -o out/linux-x64 . libygol-engine.so, ygoserver, engine.json
|
|
# docker build -f build/Dockerfile --target android -o out/android-arm64 . libygol-engine.so, engine.json
|
|
# build/linux.sh and build/android.sh run these; --build-arg VERSION=<tag> is what
|
|
# ygol_engine_version() returns ("local" when not given).
|
|
|
|
ARG VERSION=local
|
|
|
|
# --- tools: Ubuntu 22.04, pinned by digest. Its glibc (2.35) is the floor of the outputs: they run on
|
|
# Ubuntu 22.04, Debian bookworm and anything newer. (Debian bookworm would set the floor at 2.36;
|
|
# bullseye, glibc 2.31, is end of life and its package pool is gone.) The C/C++ toolchain, premake
|
|
# 5.0.0-beta8 bootstrapped from its tag. libevent's configure is the generated one in server/event
|
|
# (build-aux/ included), so no autotools.
|
|
FROM ubuntu:22.04@sha256:5ec03bb3441e8b0bf3b4f9cd4629a1ae763010dc3035bb8da3ae6cf026486401 AS base
|
|
RUN apt-get update \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
|
build-essential binutils ca-certificates curl file python3 unzip uuid-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
RUN curl -fsSL -o /tmp/premake.tgz https://github.com/premake/premake-core/archive/refs/tags/v5.0.0-beta8.tar.gz \
|
|
&& echo "2a55195fd2b27e5aa3de8ff6d22cdb127232a86f801d06e7f673d30a0eba09ac /tmp/premake.tgz" | sha256sum -c - \
|
|
&& tar xzf /tmp/premake.tgz -C /tmp && make -C /tmp/premake-core-5.0.0-beta8 -f Bootstrap.mak linux \
|
|
&& cp /tmp/premake-core-5.0.0-beta8/bin/release/premake5 /usr/local/bin/ && rm -rf /tmp/premake*
|
|
|
|
# --- Android NDK r23b (23.1.7779620, the build id in the shipped .so), before the sources and the
|
|
# gate scripts so neither changing re-downloads it.
|
|
FROM base AS android-tools
|
|
RUN curl -fsSL -o /tmp/ndk.zip https://dl.google.com/android/repository/android-ndk-r23b-linux.zip \
|
|
&& echo "f47ec4c4badd11e9f593a8450180884a927c330d /tmp/ndk.zip" | sha1sum -c - \
|
|
&& unzip -q /tmp/ndk.zip -d /opt && rm /tmp/ndk.zip
|
|
ENV NDK_DIR=/opt/android-ndk-r23b ANDROID_API_LEVEL=26
|
|
|
|
# --- the gates, as files (a stage of their own so a change here rebuilds no tool layer).
|
|
FROM scratch AS gates
|
|
|
|
# The contract header is a copy of two sources; refuse to build when it drifted (same check as windows.ps1).
|
|
COPY <<'EOF' /contract-check
|
|
#!/usr/bin/env python3
|
|
import re, sys
|
|
c = open('/src/contract/ocgapi.h').read().replace('\r\n', '\n')
|
|
core = open('/src/core/ocgapi.h').read().replace('\r\n', '\n')
|
|
s = c.find('// --- server exports')
|
|
e = c.find('// --- end server exports ---\n')
|
|
if s < 0 or e < 0: sys.exit('contract/ocgapi.h has no server exports block')
|
|
e += len('// --- end server exports ---\n')
|
|
block, rest = c[s:e], c[:s] + c[e:]
|
|
rest = re.sub(r'\A// contract/ocgapi.h:.*?\n(?=/\*)', '', rest, flags=re.S)
|
|
rest = re.sub(r'\n\n#endif /\* OCGAPI_H_ \*/\n\Z', '\n#endif /* OCGAPI_H_ */\n', rest)
|
|
if rest != core: sys.exit('contract/ocgapi.h differs from core/ocgapi.h outside the server exports block; update the contract copy')
|
|
decl = re.compile(r'^\s*YGOSERVER_API\s+\S.*;')
|
|
server = [l.strip() for l in open('/src/server/gframe/serverapi.h') if decl.match(l)]
|
|
contract = [l.strip() for l in block.split('\n') if decl.match(l)]
|
|
if not server: sys.exit('no YGOSERVER_API declarations found in gframe/serverapi.h')
|
|
if server != contract: sys.exit('contract/ocgapi.h server exports block differs from gframe/serverapi.h:\n serverapi.h: %s\n contract: %s' % (' | '.join(server), ' | '.join(contract)))
|
|
print('contract/ocgapi.h matches core/ocgapi.h + serverapi.h (%d server exports)' % len(server))
|
|
EOF
|
|
|
|
# export-gate <nm> <lib> <expected> <version> <out dir>: the plain C exports of the library (dynamic,
|
|
# defined, no leading underscore: C++ symbols are _Z-mangled; sqlite3_*, lua_*, event_*, ... count,
|
|
# as they do on Windows), every name declared in contract/ocgapi.h among them, the count exactly
|
|
# <expected>; then engine.json with protocol and capabilities READ from the server source, never
|
|
# typed in, and binding = the version (the C# binding is released with the engine under one tag).
|
|
COPY <<'EOF' /export-gate
|
|
#!/usr/bin/env python3
|
|
import re, subprocess, sys
|
|
nm, lib, expected, version, out = sys.argv[1], sys.argv[2], int(sys.argv[3]), sys.argv[4], sys.argv[5]
|
|
text = subprocess.run([nm, '--dynamic', '--defined-only', '--extern-only', lib], check=True, capture_output=True, text=True).stdout
|
|
names = sorted({f[2] for f in (l.split() for l in text.splitlines()) if len(f) == 3 and not f[2].startswith('_')})
|
|
api = sorted({m.group(2) for m in (re.match(r'^\s*(OCGCORE_API|YGOSERVER_API) [^(]*[ *]([A-Za-z_0-9]+)\(', l) for l in open('/src/contract/ocgapi.h')) if m})
|
|
missing = [a for a in api if a not in names]
|
|
print('%s: exports: %d (expected %d); contract names: %d, missing: %s' % (lib, len(names), expected, len(api), ', '.join(missing) or 'none'))
|
|
if missing or len(names) != expected: sys.exit('export gate failed; do NOT ship this build')
|
|
h = open('/src/server/gframe/network.h').read()
|
|
m = re.search(r'^constexpr uint16_t FEATURE_PROTOCOL = (\d+);', h, re.M)
|
|
if not m: sys.exit('FEATURE_PROTOCOL not found in gframe/network.h')
|
|
protocol = int(m.group(1))
|
|
bits = {k: int(v, 16) for k, v in re.findall(r'^constexpr uint32_t (FEATURE_[A-Z_]+) = (0x[0-9A-Fa-f]+);', h, re.M)}
|
|
exprs = []
|
|
for f in ('single_duel.cpp', 'tag_duel.cpp'):
|
|
m = re.search(r'^\s*cap\.flags = (.+?);', open('/src/server/gframe/' + f).read(), re.M)
|
|
if not m: sys.exit('cap.flags line not found in gframe/' + f)
|
|
exprs.append(re.sub(r'\s', '', m.group(1)))
|
|
if exprs[0] != exprs[1]: sys.exit('single_duel.cpp and tag_duel.cpp advertise different capability flags')
|
|
capabilities = 0
|
|
for n in exprs[0].split('|'):
|
|
if n not in bits: sys.exit('capability %s has no constexpr uint32_t in gframe/network.h' % n)
|
|
capabilities |= bits[n]
|
|
open(out + '/engine.json', 'w').write('{\n "version": "%s",\n "exports": %d,\n "protocol": %d,\n "capabilities": %d,\n "binding": "%s"\n}\n' % (version, len(names), protocol, capabilities, version))
|
|
print('engine.json: version %s, exports %d, protocol %d, capabilities 0x%X, binding %s' % (version, len(names), protocol, capabilities, version))
|
|
EOF
|
|
|
|
# --- sources + gates. obj/ bin/ build/ are wiped so a dirty checkout can never hand the build a stale
|
|
# object (the 2026-08-26 story in the Unity repo's CLAUDE.md).
|
|
FROM base AS linux-src
|
|
COPY --from=gates --chmod=755 / /usr/local/bin/
|
|
COPY core /src/core
|
|
COPY server /src/server
|
|
COPY contract /src/contract
|
|
WORKDIR /src/server
|
|
RUN contract-check && rm -rf obj bin build
|
|
|
|
FROM android-tools AS android-src
|
|
COPY --from=gates --chmod=755 / /usr/local/bin/
|
|
COPY core /src/core
|
|
COPY server /src/server
|
|
COPY contract /src/contract
|
|
WORKDIR /src/server
|
|
RUN contract-check && rm -rf obj bin build
|
|
|
|
# --- Linux x64: upstream's Linux server recipe with every dependency built from the vendored sources
|
|
# (BUILD_ALL), libevent configured by its own configure for the host. Two builds from one tree: the
|
|
# library (SERVER_PRO3_SUPPORT, project ygoserver -> libygol-engine.so) and the plain server
|
|
# executable (project ygopro, with the zip support and tag surrender confirm PRO3 turns on, so both
|
|
# carry the same rules), renamed ygoserver. obj/ is wiped between them: different defines.
|
|
FROM linux-src AS linux-build
|
|
ARG VERSION
|
|
ENV BUILD_ALL=1 LOG_IN_CHAT=1 USE_SIMD=best
|
|
RUN sh ./.ci/configure-libevent.sh > /dev/null
|
|
RUN SERVER_PRO3_SUPPORT=1 YGOL_ENGINE_VERSION=$VERSION premake5 gmake \
|
|
&& make -C build config=release -j"$(nproc)" ygoserver \
|
|
&& mkdir -p /out && cp bin/release/libygol-engine.so /out/ \
|
|
&& rm -rf obj bin build
|
|
RUN SERVER_ZIP_SUPPORT=1 SERVER_TAG_SURRENDER_CONFIRM=1 premake5 gmake \
|
|
&& make -C build config=release -j"$(nproc)" ygopro \
|
|
&& cp bin/release/ygopro /out/ygoserver
|
|
RUN file /out/libygol-engine.so /out/ygoserver \
|
|
&& export-gate nm /out/libygol-engine.so 857 "$VERSION" /out
|
|
|
|
FROM scratch AS linux
|
|
COPY --from=linux-build /out/ /
|
|
|
|
# --- Android arm64: upstream's exec_android_pro3 job (the Unity repo's Tools/YGOLegacy/android recipe):
|
|
# libevent configured with the NDK's clang, premake's android_arm64 platform, API level 26.
|
|
FROM android-src AS android-build
|
|
ARG VERSION
|
|
ENV BUILD_ALL=1 LOG_IN_CHAT=1 USE_SIMD=best SERVER_PRO3_SUPPORT=1
|
|
RUN sh ./.ci/configure-libevent.sh > /dev/null
|
|
RUN YGOL_ENGINE_VERSION=$VERSION premake5 gmake \
|
|
&& make -C build config=release_android_arm64 -j"$(nproc)" ygoserver \
|
|
&& mkdir -p /out && cp bin/android_arm64/release/libygol-engine.so /out/
|
|
RUN file /out/libygol-engine.so \
|
|
&& export-gate "$NDK_DIR"/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-nm /out/libygol-engine.so 851 "$VERSION" /out
|
|
|
|
FROM scratch AS android
|
|
COPY --from=android-build /out/ /
|