Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
shell: pwsh
run: |
zig build install test-toolchains test-codegen test-deps test-il2cpp test-mod test-sync test-spud `
-Dtarget=x86_64-windows-msvc -Doptimize=ReleaseFast -Dtest-optimize=Debug `
-Dtarget=x86_64-windows-msvc -Doptimize=ReleaseFast -Dstrip=true -Dtest-optimize=Debug `
"-Dstfc_source_state_id=git:${{ github.sha }}" `
"-Dstfc_base_commit=${{ github.sha }}" `
"-Dstfc_build_invocation_id=github:${{ github.run_id }}:${{ github.run_attempt }}:windows" `
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
STFC_WINDOWS_TOOLCHAIN_URL: ${{ vars.STFC_WINDOWS_TOOLCHAIN_URL }}
run: |
zig build fetch-toolchains
zig build install build-tests -Dtarget=x86_64-windows-msvc -Doptimize=ReleaseFast -Dtest-optimize=Debug
zig build install build-tests -Dtarget=x86_64-windows-msvc -Doptimize=ReleaseFast -Dstrip=true -Dtest-optimize=Debug
python3 scripts/verify-windows-binary.py

# The native fixtures need no SDK, so they run on Linux too, where they are cheapest.
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
- name: Build and test
run: |
zig build install launcher test-toolchains test-codegen test-deps test-il2cpp test-mod ${{ matrix.tests }} \
-Dtarget=${{ matrix.target }} -Doptimize=ReleaseFast -Dtest-optimize=Debug --summary all
-Dtarget=${{ matrix.target }} -Doptimize=ReleaseFast -Dstrip=true -Dtest-optimize=Debug --summary all
- name: Verify portable linkage
run: |
scripts/check-mac-linkage.sh zig-out/macOSLauncher.app/Contents/MacOS/macOSLauncher \
Expand Down
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ To reset build outputs, remove `.zig-cache` and `zig-out`. Keep `.cache/toolchai

## Choose build options

`Debug` is the default. Use `-Doptimize=ReleaseFast` for releases.
The default developer build is `ReleaseFast` with debug symbols (`releasedbg`). Use `-Doptimize=Debug` for an
unoptimized debug build. Production packages also pass `-Dstrip=true`.
Windows release builds enable link-time optimization. Disable it with `-Dlto=false`.
The Swift launcher compiles as one module and links after the native archives are ready.
macOS `ReleaseFast` builds batch feature sources to share header parsing; sync sources compile separately.
Expand All @@ -89,11 +90,12 @@ Zig does not support Mach-O LTO, so macOS builds use ordinary optimized compilat

| Option | Effect |
| --- | --- |
| `-Dstrip=true` | Strip debug symbols for a production package. |
| `-Dmoddbg=true` | Define `_MODDBG`: enable debug logging by default, disable sync request timeouts, and add diagnostics. |
| `-Dbg_image=<file>` | Replace the embedded loading image. |
| `-Duse_original_bg=true` | Keep the game's loading background. |
| `-Dmacos-sdk=<path>` | Use an explicit macOS SDK. |
| `-Dtest-optimize=Debug` | Keep test fixtures and their assertions in Debug while sharing dependencies built with `-Doptimize=ReleaseFast`. |
| `-Dtest-optimize=<mode>` | Override the test fixtures' `Debug` default; dependencies still use `-Doptimize`. |

`[patches]` switches work in every build.
For library-only checks, use `zig build il2cpp`, `zig build unity`, or `zig build mods` with the required target.
Expand Down
4 changes: 3 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{
.default_target = .{ .abi = if (builtin.os.tag == .windows) .msvc else null },
});
const optimize = b.standardOptimizeOption(.{});
// Local builds should behave like the shipped mod while retaining symbols for crash reports and debuggers.
const optimize = b.option(std.builtin.OptimizeMode, "optimize", "Prioritize performance, safety, or binary size")
orelse .ReleaseFast;
const options = Options.parse(b);
mod.addUniversal(b, optimize, options);
const ctx = Ctx.init(b, target, optimize, options);
Expand Down
12 changes: 6 additions & 6 deletions scripts/mac-build-test-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ Actions:
clean Remove .zig-cache and zig-out

Options:
-m, --mode MODE debug (default), release, or releasedbg (release with the mod's -Dmoddbg diagnostics)
-m, --mode MODE releasedbg (default; optimized with symbols), debug, or release
-a, --arch ARCH arm64, x86_64 or universal (default: this Mac's)
-l, --launcher Run the launcher bundle instead of the loader
-c, --clean Clean before building
-h, --help Show this help
EOF
}

MODE=debug
MODE=releasedbg
ARCH="$(uname -m)"
ACTION=build
CLEAN=false
Expand All @@ -40,9 +40,9 @@ while (($#)); do
done

case "$MODE" in
debug) OPTIMIZE=Debug MODDBG=false ;;
release) OPTIMIZE=ReleaseFast MODDBG=false ;;
releasedbg) OPTIMIZE=ReleaseFast MODDBG=true ;;
debug) OPTIMIZE=Debug STRIP=false ;;
release) OPTIMIZE=ReleaseFast STRIP=true ;;
releasedbg) OPTIMIZE=ReleaseFast STRIP=false ;;
*) echo "Invalid mode: $MODE (debug, release, releasedbg)" >&2 && exit 1 ;;
esac

Expand Down Expand Up @@ -70,7 +70,7 @@ build() {
target=aarch64
fi
# Keep in step with macos_min in zig/ctx.zig.
zig build install launcher -Dtarget="$target-macos.14.6" -Doptimize="$OPTIMIZE" -Dmoddbg="$MODDBG" \
zig build install launcher -Dtarget="$target-macos.14.6" -Doptimize="$OPTIMIZE" -Dstrip="$STRIP" \
--prefix "$PREFIX"
scripts/assemble-mac-app.sh "$APP" "$PREFIX"
}
Expand Down
8 changes: 4 additions & 4 deletions scripts/package-mac-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ cd "$ROOT"

MODE="${1:-release}"
case "$MODE" in
debug) OPTIMIZE=Debug MODDBG=false ;;
release) OPTIMIZE=ReleaseFast MODDBG=false ;;
releasedbg) OPTIMIZE=ReleaseFast MODDBG=true ;;
debug) OPTIMIZE=Debug STRIP=false ;;
release) OPTIMIZE=ReleaseFast STRIP=true ;;
releasedbg) OPTIMIZE=ReleaseFast STRIP=false ;;
*)
echo "Unknown build mode: $MODE" >&2
exit 1
Expand All @@ -27,7 +27,7 @@ for ARCH in arm64 x86_64; do
TARGET=aarch64
fi
PREFIX="zig-out/$ARCH/$MODE"
zig build install launcher -Dtarget="$TARGET-macos.$MACOS_MIN" -Doptimize="$OPTIMIZE" -Dmoddbg="$MODDBG" \
zig build install launcher -Dtarget="$TARGET-macos.$MACOS_MIN" -Doptimize="$OPTIMIZE" -Dstrip="$STRIP" \
--prefix "$PREFIX"
PREFIXES+=("$PREFIX")
done
Expand Down
6 changes: 0 additions & 6 deletions src/mod/mod.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,6 @@ void InstallFeatures(const Config& config)

int il2cpp_init_Hook(auto original, const char* domain_name)
{
#if _WIN32 && !defined(NDEBUG)
AllocConsole();
FILE* console;
freopen_s(&console, "CONOUT$", "w", stdout);
#endif

// Nothing here may throw into the game: a mod that cannot set itself up leaves the game running without it.
// Keeping the settings pointer is safe here because only the frame tick reloads, and it is not installed yet.
const Config* config = nullptr;
Expand Down
16 changes: 13 additions & 3 deletions zig/ctx.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ pub const macos_min = "14.6";
pub const Options = struct {
/// null keeps the per-target default: on for Windows release builds, off elsewhere.
lto: ?bool,
/// Strip debug information for production packages. Local release builds retain symbols by default.
strip: bool,
moddbg: bool,
use_original_bg: bool,
/// A custom loading screen, relative to the working directory; empty for the built-in one.
bg_image: []const u8,
/// Fixture optimization; null follows -Doptimize.
/// Fixture optimization; null keeps assertions and diagnostics in Debug.
test_optimize: ?OptimizeMode,
msvc_sysroot: ?[]const u8,
macos_sdk: ?[]const u8,
Expand All @@ -31,6 +33,7 @@ pub const Options = struct {
pub fn parse(b: *Build) Options {
return .{
.lto = b.option(bool, "lto", "Enable LTO (Windows release default; unsupported for macOS)"),
.strip = b.option(bool, "strip", "Strip debug symbols from production artifacts") orelse false,
.moddbg = b.option(bool, "moddbg", "Enable diagnostic patch toggles (_MODDBG)") orelse false,
.use_original_bg = b.option(
bool,
Expand All @@ -41,7 +44,7 @@ pub const Options = struct {
.test_optimize = b.option(
OptimizeMode,
"test-optimize",
"Optimization mode for test fixtures (dependencies use -Doptimize)",
"Optimization mode for test fixtures (Debug by default; dependencies use -Doptimize)",
),
.msvc_sysroot = b.option([]const u8, "msvc-sysroot", "Path to an extracted MSVC + Windows SDK toolchain"),
.macos_sdk = b.option([]const u8, "macos-sdk", "Path to a MacOSX.sdk directory"),
Expand Down Expand Up @@ -86,7 +89,10 @@ pub const Ctx = struct {
const copy = ctx.b.allocator.create(Ctx) catch @panic("OOM");
copy.* = ctx.*;
copy.optimize = optimize;
if (optimize == OptimizeMode.Debug) copy.lto = false;
if (optimize == OptimizeMode.Debug) {
copy.lto = false;
copy.options.strip = false;
}
return copy;
}

Expand Down Expand Up @@ -121,9 +127,13 @@ pub const Ctx = struct {
.link_libc = true,
.link_libcpp = if (cpp and !ctx.isWindows()) true else null,
.pic = true,
.strip = ctx.options.strip,
// Zig turns UBSan on in Debug, but a trap inside a game detour takes the client down.
.sanitize_c = .off,
});
// Zig's optimization mode does not define the conventional C/C++ release macro. Keep debug-only runtime
// behavior out of optimized builds even when they retain debug symbols.
if (!ctx.isDebug()) module.addCMacro("NDEBUG", "1");

if (ctx.isWindows()) {
if (ctx.sysroot.msvc_root) |root| {
Expand Down
3 changes: 2 additions & 1 deletion zig/mod.zig
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn addModSources(ctx: *const Ctx, module: *std.Build.Module, flags: []const []co
/// marker; the RC's /D cuts a value at '=', so the whole marker cannot be passed as one define.
fn identityDefines(ctx: *const Ctx) []const []const u8 {
const b = ctx.b;
const mode = if (ctx.options.moddbg) "releasedbg" else if (ctx.isDebug()) "debug" else "release";
const mode = if (ctx.isDebug()) "debug" else if (ctx.options.strip) "release" else "releasedbg";
var flags: std.ArrayList([]const u8) = .empty;
flags.appendSlice(b.allocator, &.{ "/D", b.fmt("STFC_BUILD_MODE=\"{s}\"", .{mode}) }) catch @panic("OOM");
inline for (.{
Expand Down Expand Up @@ -226,6 +226,7 @@ pub fn addUniversal(b: *std.Build, optimize: std.builtin.OptimizeMode, options:
"-Dtarget=" ++ arch ++ "-macos." ++ macos_min,
b.fmt("-Doptimize={s}", .{@tagName(optimize)}),
b.fmt("-Dlto={}", .{options.lto orelse false}),
b.fmt("-Dstrip={}", .{options.strip}),
b.fmt("-Dmoddbg={}", .{options.moddbg}),
b.fmt("-Duse_original_bg={}", .{options.use_original_bg}),
});
Expand Down
3 changes: 2 additions & 1 deletion zig/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const builtin = @import("builtin");
const compat = @import("compat.zig");
const Ctx = @import("ctx.zig").Ctx;
const Lib = @import("ctx.zig").Lib;
const OptimizeMode = @import("ctx.zig").OptimizeMode;
const deps = @import("deps.zig");

/// The libraries the fixtures link. They are the production artifacts, built at -Doptimize.
Expand All @@ -19,7 +20,7 @@ pub const Libs = struct {
/// Register the fixture steps. Fixture code compiles at -Dtest-optimize, so a Debug fixture keeps its assertions
/// while sharing release libraries with the shipped build.
pub fn add(build_ctx: *const Ctx, libs: Libs) void {
const ctx = build_ctx.withOptimize(build_ctx.options.test_optimize orelse build_ctx.optimize);
const ctx = build_ctx.withOptimize(build_ctx.options.test_optimize orelse OptimizeMode.Debug);
const b = ctx.b;
const build_tests = b.step("build-tests", "Compile the tests without running them");
const test_il2cpp = b.step("test-il2cpp", "Build and run the IL2CPP boundary tests (native targets only)");
Expand Down
Loading