-
Notifications
You must be signed in to change notification settings - Fork 460
Experimental macOS (x86_64) port -- Mono + XQuartz, unlocks waterbox (DS) on macOS #4785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DarthMDev
wants to merge
10
commits into
TASEmulators:master
Choose a base branch
from
DarthMDev:macos-x86_64-port
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4dc0f22
waterboxhost: add macOS (x86_64) support
DarthMDev 3586276
EmuHawk: macOS (x86_64) native-library and graphics handling
DarthMDev ece6b63
macOS: launcher, dependency staging script, and docs
DarthMDev aa99fa4
macOS: Fix keyboard input
DarthMDev 0d7ab8f
macOS: address PR review feedback
DarthMDev 5165af5
macOS: auto-stage native libs after build; migrate Encore to Platform…
DarthMDev cfe0fd9
Remove unnecessary import
DarthMDev 0b426d5
macOS: default the display method to GdiPlus
DarthMDev c83346b
macOS: create the native-lib symlinks in EmuHawkMono.sh
DarthMDev 721fd97
macOS: export MONO_GC_PARAMS with nursery-size=256m to avoid Rosetta …
DarthMDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #!/bin/sh | ||
| # Launcher for EmuHawk on macOS via Mono (x86_64, under Rosetta 2 on Apple Silicon). | ||
| # Mono's System.Windows.Forms is X11-based, so an X server (XQuartz) must be running. | ||
| # See also EmuHawkMono.sh (the Linux equivalent this is modelled on). | ||
| cd "$(dirname "$(realpath "$0")")" | ||
|
|
||
| # Native libs ship in ./dll; also let the loader find Homebrew-provided deps | ||
| # (SDL2, OpenAL, Lua, zstd, libgdiplus, ...) under /usr/local, and XQuartz's X11 | ||
| # libs under /opt/X11/lib (Mono's WinForms dlopens libX11 etc. from there). | ||
| export DYLD_LIBRARY_PATH="$PWD/dll:$PWD:/usr/local/lib:/opt/X11/lib${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}" | ||
| export DYLD_FALLBACK_LIBRARY_PATH="$PWD/dll:$PWD:/usr/local/lib:/opt/X11/lib:/usr/lib${DYLD_FALLBACK_LIBRARY_PATH:+:$DYLD_FALLBACK_LIBRARY_PATH}" | ||
|
YoshiRulz marked this conversation as resolved.
Outdated
|
||
|
|
||
| export MONO_CRASH_NOFILE=1 | ||
| export MONO_WINFORMS_XIM_STYLE=disabled # see https://bugzilla.xamarin.com/show_bug.cgi?id=28047#c9 | ||
| # Mono's default macOS WinForms backend is the Carbon driver, which is unported to 64-bit | ||
| # ("very few parts of Windows.Forms will work properly, or at all"). Force the X11 driver, | ||
| # which renders through XQuartz. | ||
| export MONO_MWF_MAC_FORCE_X11=1 | ||
|
|
||
| # XQuartz: ensure DISPLAY points at a running X server. | ||
| if [ -z "$DISPLAY" ]; then | ||
| export DISPLAY=:0 | ||
| fi | ||
| if ! command -v Xquartz >/dev/null 2>&1 && [ ! -d "/Applications/Utilities/XQuartz.app" ] && [ ! -d "/opt/X11" ]; then | ||
| printf "%s\n" "XQuartz does not appear to be installed; Mono WinForms needs an X11 server. Install with: brew install --cask xquartz" >&2 | ||
| fi | ||
|
|
||
| # Prefer the x86_64 Mono from Homebrew at /usr/local. Invoke it DIRECTLY (not via `arch`): | ||
| # /usr/bin/arch is SIP-protected and strips DYLD_* from the environment, which breaks our | ||
| # library paths. An x86_64-only binary auto-runs under Rosetta 2 when exec'd directly. | ||
| mono_bin="mono" | ||
| if [ -x "/usr/local/bin/mono" ]; then | ||
| mono_bin="/usr/local/bin/mono" | ||
|
YoshiRulz marked this conversation as resolved.
Outdated
|
||
| fi | ||
|
|
||
| # Force the GdiPlus (software) display method: XQuartz's OpenGL is Apple's legacy GLX bridge, | ||
| # which is only GL 2.1 and crashes (CGLSetCurrentContext) under Rosetta. Without this, EmuHawk | ||
|
DarthMDev marked this conversation as resolved.
Outdated
|
||
| # aborts trying to init OpenGL. GdiPlus is full-speed here since the host only blits frames. | ||
| set -- --gdi "$@" | ||
|
|
||
| if (ps -A -o "command" | grep -F "EmuHawk.exe" | grep -Fvq "grep"); then | ||
| printf "(it seems EmuHawk is already running, NOT capturing output)\n" >&2 | ||
| exec $mono_bin EmuHawk.exe "$@" | ||
| fi | ||
| o="$(mktemp -u)" | ||
| e="$(mktemp -u)" | ||
| mkfifo "$o" "$e" | ||
| printf "(capturing output in %s/EmuHawkMono_last*.txt)\n" "$PWD" >&2 | ||
| tee EmuHawkMono_laststdout.txt <"$o" & | ||
| tee EmuHawkMono_laststderr.txt <"$e" | sed "s/.*/$(tput setaf 1)&$(tput sgr0)/" >&2 & | ||
| exec $mono_bin EmuHawk.exe "$@" >"$o" 2>"$e" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/bin/sh | ||
| # Stage the macOS (x86_64 / Rosetta) native-library glue into the EmuHawk output dir. | ||
| # | ||
| # Run this once after building (Dist/BuildRelease.sh) and before launching with | ||
| # Assets/EmuHawkMonoMacOS.sh. It symlinks the Homebrew-provided dependencies (SDL deps, | ||
|
DarthMDev marked this conversation as resolved.
Outdated
|
||
| # OpenAL, Lua, zstd, SQLite, the X11 client stack) and creates the Linux-soname aliases | ||
| # (libX11.so.6, etc.) that BizHawk's P/Invokes and Mono expect, all pointing at the SAME | ||
|
DarthMDev marked this conversation as resolved.
Outdated
|
||
| # Homebrew libX11 so cairo/libgdiplus/WinForms/SDL agree (see notes in EmuHawkMonoMacOS.sh). | ||
| # | ||
| # The dylibs BizHawk itself builds/bundles (libSDL2, libgdiplus, libcimgui, libwaterboxhost) | ||
| # ship in Assets/dll and are copied to output/dll by the build, so they are not handled here. | ||
| # | ||
| # Prereqs (x86_64 Homebrew under Rosetta): | ||
| # brew install mono sdl2 openal-soft lua@5.4 zstd sqlite mono-libgdiplus \ | ||
| # libx11 libxext libxrender libxcursor libxinerama libxi libxrandr \ | ||
| # libxtst libxfixes libxscrnsaver libxau libxdmcp libxcb | ||
| # brew install --cask xquartz | ||
| set -e | ||
|
|
||
| # Target dll dir: arg 1, else ./dll relative to cwd, else output/dll under the repo. | ||
| DLL="${1:-}" | ||
| if [ -z "$DLL" ]; then | ||
| if [ -d "dll" ]; then DLL="dll" | ||
| else DLL="$(cd "$(dirname "$0")/.." && pwd)/output/dll"; fi | ||
| fi | ||
| if [ ! -d "$DLL" ]; then printf "output dll dir not found: %s\n" "$DLL" >&2; exit 1; fi | ||
| cd "$DLL" | ||
|
|
||
| opt() { echo "/usr/local/opt/$1"; } | ||
| link() { # link <target-abs-path> <linkname> | ||
| [ -e "$1" ] && ln -sf "$1" "$2" || printf "WARN missing %s (for %s)\n" "$1" "$2" >&2 | ||
| } | ||
|
|
||
| # Homebrew runtime deps under their canonical names | ||
| link "$(opt lua@5.4)/lib/liblua5.4.dylib" liblua54.dylib | ||
| link "$(opt openal-soft)/lib/libopenal.dylib" libopenal.dylib | ||
| link "$(opt openal-soft)/lib/libopenal.1.dylib" libopenal.1.dylib | ||
| link "$(opt zstd)/lib/libzstd.1.dylib" libzstd.1.dylib | ||
| link "$(opt sqlite)/lib/libsqlite3.dylib" libe_sqlite3.dylib | ||
| link "$(opt sqlite)/lib/libsqlite3.dylib" e_sqlite3.dylib | ||
|
|
||
| # X11 client stack (all from Homebrew, so they share one libX11) | ||
| link "$(opt libx11)/lib/libX11.6.dylib" libX11.6.dylib | ||
| link "$(opt libxext)/lib/libXext.6.dylib" libXext.6.dylib | ||
| link "$(opt libxrender)/lib/libXrender.1.dylib" libXrender.1.dylib | ||
| link "$(opt libxcursor)/lib/libXcursor.1.dylib" libXcursor.1.dylib | ||
| link "$(opt libxinerama)/lib/libXinerama.1.dylib" libXinerama.1.dylib | ||
| link "$(opt libxi)/lib/libXi.6.dylib" libXi.6.dylib | ||
| link "$(opt libxrandr)/lib/libXrandr.2.dylib" libXrandr.2.dylib | ||
| link "$(opt libxtst)/lib/libXtst.6.dylib" libXtst.6.dylib | ||
| link "$(opt libxfixes)/lib/libXfixes.3.dylib" libXfixes.3.dylib | ||
| link "$(opt libxscrnsaver)/lib/libXss.1.dylib" libXss.1.dylib | ||
| link "$(opt libxau)/lib/libXau.6.dylib" libXau.6.dylib | ||
| link "$(opt libxdmcp)/lib/libXdmcp.6.dylib" libXdmcp.6.dylib | ||
| link "$(opt libxcb)/lib/libxcb.1.dylib" libxcb.1.dylib | ||
|
|
||
| # Linux-soname aliases that BizHawk's P/Invokes and Mono hardcode (XlibImports etc.) | ||
| ln -sf libX11.6.dylib libX11.dylib | ||
| ln -sf libX11.6.dylib libX11.so.6 | ||
| ln -sf libXfixes.3.dylib libXfixes.so.3 | ||
| ln -sf libXi.6.dylib libXi.so.6 | ||
| ln -sf libzstd.1.dylib libzstd.so.1 | ||
| ln -sf libgdiplus.0.dylib libgdiplus.dylib | ||
|
|
||
| printf "staged macOS dylib symlinks into %s\n" "$DLL" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #!/bin/sh | ||
| # Build libwaterboxhost for macOS as an x86_64 Mach-O dylib (runs under Rosetta 2 on | ||
| # Apple Silicon). Cross-compiles from any host; only needs rustup + the x86_64-apple-darwin | ||
| # std for a compatible nightly. See build-release.sh for the Linux/.so equivalent. | ||
| # | ||
| # NOTE: this builds the host. Guest-entry on macOS is not yet fully correct; see the | ||
| # TODO[macOS] in src/context/mod.rs (the %gs / TLS scratch mechanism still needs work). | ||
| set -e | ||
| if [ -z "$BIZHAWKBUILD_HOME" ]; then export BIZHAWKBUILD_HOME="$(realpath "$(dirname "$0")/../..")"; fi | ||
| cd "$(dirname "$0")" | ||
|
|
||
| # This crate predates several nightly API changes (try_trait_v2, unsafe intrinsics), so pin | ||
| # a known-good nightly rather than the floating channel in rust-toolchain.toml. | ||
| TOOLCHAIN="${WBX_NIGHTLY:-nightly-2024-10-18}" | ||
| TARGET="x86_64-apple-darwin" | ||
| # Build for an older baseline so the dylib loads on older Macs, not just the build host. | ||
| # (The overall floor is set by the Homebrew deps, currently macOS 14.) | ||
| export MACOSX_DEPLOYMENT_TARGET="${MACOSX_DEPLOYMENT_TARGET:-11.0}" | ||
|
|
||
| rustup toolchain install "$TOOLCHAIN" --profile minimal | ||
| rustup target add --toolchain "$TOOLCHAIN" "$TARGET" | ||
|
|
||
| # cargo invokes a bare `rustc`; if another rustc (e.g. Homebrew's) precedes ~/.cargo/bin on | ||
| # PATH it gets picked and lacks the cross std. Pin RUSTC to the toolchain's rustc explicitly. | ||
| RUSTC_BIN="$(rustup which --toolchain "$TOOLCHAIN" rustc)" | ||
|
|
||
| # Regenerate the interop blobs (needs nasm: `brew install nasm`). The macOS variant | ||
| # (interop_macos.bin) handles %gs differently — see src/context/interop_macos.s. | ||
| if command -v nasm >/dev/null 2>&1; then | ||
| make -C src/context | ||
| fi | ||
|
|
||
| RUSTC="$RUSTC_BIN" cargo "+$TOOLCHAIN" build --release --target "$TARGET" | ||
|
|
||
| OUT="target/$TARGET/release/libwaterboxhost.dylib" | ||
| cp "$OUT" "$BIZHAWKBUILD_HOME/Assets/dll/libwaterboxhost.dylib" | ||
| if [ -e "$BIZHAWKBUILD_HOME/output" ]; then | ||
| cp "$OUT" "$BIZHAWKBUILD_HOME/output/dll/libwaterboxhost.dylib" | ||
| fi | ||
| printf "copied libwaterboxhost.dylib (%s) into Assets/dll\n" "$TARGET" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| interop.bin: interop.s | ||
| nasm -f bin -Wall -o $@ $< | ||
| all: interop.bin interop_macos.bin | ||
|
|
||
| interop.bin: interop.s | ||
| nasm -f bin -Wall -o $@ $< | ||
|
|
||
| interop_macos.bin: interop_macos.s | ||
| nasm -f bin -Wall -o $@ $< |
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.