From e52bc62b0af25184dedad92d966633947dd915b7 Mon Sep 17 00:00:00 2001 From: Nikita Skobelevs Date: Tue, 23 Sep 2025 23:15:14 +0300 Subject: [PATCH 1/3] run.sh: force MacOs to run the executable natively when on Apple Silicon --- assets/nix/run.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/assets/nix/run.sh b/assets/nix/run.sh index 5669ec9..28f3bc2 100755 --- a/assets/nix/run.sh +++ b/assets/nix/run.sh @@ -123,7 +123,7 @@ abs_path() { echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" } -# Set executable path and the extension to use for the libdoorstop shared object +# Set executable path and the extension to use for the libdoorstop shared object as well as check whether we're running on Apple Silicon os_type="$(uname -s)" case ${os_type} in Linux*) @@ -148,6 +148,14 @@ case ${os_type} in ;; esac lib_extension="dylib" + + # CPUs for Apple Silicon are in the format "Apple M.." + cpu_type="$(sysctl -n machdep.cpu.brand_string)" + case "${cpu_type}" in + Apple*) + is_apple_silicon=1 + ;; + esac ;; *) # alright whos running games on freebsd @@ -309,4 +317,14 @@ else export DYLD_INSERT_LIBRARIES="${doorstop_name}:${DYLD_INSERT_LIBRARIES}" fi -exec "$executable_path" "$@" +if [ -n "${is_apple_silicon}" ]; then + export ARCHPREFERENCE="arm64,x86_64" + + # We need to use arch for Apple Silicon to allow the executable to be run natively as otherwise if + # the executable is universal, supporting both x86_64 and arm64, MacOs will still run it as x86_64 + # if the parent process is running as x86. + # arch also strips the DYLD_INSERT_LIBRARIES env var so we have to pass that in manually + arch -e DYLD_INSERT_LIBRARIES=$DYLD_INSERT_LIBRARIES "$executable_path" "$@" +else + exec "$executable_path" "$@" +fi From d4b21af1793b82cb68713dd63c3bc915ac971aab Mon Sep 17 00:00:00 2001 From: Nikita Skobelevs Date: Wed, 24 Sep 2025 19:06:24 +0300 Subject: [PATCH 2/3] Fix non-quoted `DYLD_INSERT_LIBRARIES` expansion --- assets/nix/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/nix/run.sh b/assets/nix/run.sh index 28f3bc2..882f569 100755 --- a/assets/nix/run.sh +++ b/assets/nix/run.sh @@ -324,7 +324,7 @@ if [ -n "${is_apple_silicon}" ]; then # the executable is universal, supporting both x86_64 and arm64, MacOs will still run it as x86_64 # if the parent process is running as x86. # arch also strips the DYLD_INSERT_LIBRARIES env var so we have to pass that in manually - arch -e DYLD_INSERT_LIBRARIES=$DYLD_INSERT_LIBRARIES "$executable_path" "$@" + arch -e DYLD_INSERT_LIBRARIES="${DYLD_INSERT_LIBRARIES}" "$executable_path" "$@" else exec "$executable_path" "$@" fi From eb008b9b9c8c0009a44735f7cb162da85cf7113a Mon Sep 17 00:00:00 2001 From: Nikita Skobelevs Date: Wed, 24 Sep 2025 20:05:42 +0300 Subject: [PATCH 3/3] Convert to using `exec arch` --- assets/nix/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/nix/run.sh b/assets/nix/run.sh index 882f569..c840973 100755 --- a/assets/nix/run.sh +++ b/assets/nix/run.sh @@ -324,7 +324,7 @@ if [ -n "${is_apple_silicon}" ]; then # the executable is universal, supporting both x86_64 and arm64, MacOs will still run it as x86_64 # if the parent process is running as x86. # arch also strips the DYLD_INSERT_LIBRARIES env var so we have to pass that in manually - arch -e DYLD_INSERT_LIBRARIES="${DYLD_INSERT_LIBRARIES}" "$executable_path" "$@" + exec arch -e DYLD_INSERT_LIBRARIES="${DYLD_INSERT_LIBRARIES}" "$executable_path" "$@" else exec "$executable_path" "$@" fi