fix: mac bundle now proper arm64

This commit is contained in:
2026-06-22 15:02:08 +02:00
parent 211271efca
commit d78cb5c07b
5 changed files with 84 additions and 38 deletions

View File

@@ -26,6 +26,11 @@
<string><%= min_system %></string>
<key>NSHighResolutionCapable</key>
<true/>
<!-- Main executable is a shell script (no Mach-O slices), so LaunchServices
otherwise advertises x86_64 and offers Rosetta. All embedded binaries are
arm64; force native execution so the OS never translates the app. -->
<key>LSRequiresNativeExecution</key>
<true/>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>CFBundleURLTypes</key>

View File

@@ -0,0 +1,51 @@
// Native launcher for the BDS2 .app — compiled to a pure arm64 Mach-O by
// mix bds.bundle.macos. A shell-script main executable has no Mach-O slices, so
// LaunchServices advertises x86_64 and offers Rosetta; a real arm64 binary makes
// the bundle unambiguously Apple Silicon.
//
// Mirrors launcher.sh: resolve <Contents>, prepend Frameworks to the dyld
// fallback path, then exec <Contents>/Resources/rel/bin/<release> start.
#include <limits.h>
#include <libgen.h>
#include <mach-o/dyld.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifndef BDS_RELEASE_NAME
#define BDS_RELEASE_NAME "bds"
#endif
int main(void) {
char exec_path[PATH_MAX];
uint32_t size = sizeof(exec_path);
if (_NSGetExecutablePath(exec_path, &size) != 0) return 1;
char resolved[PATH_MAX];
if (realpath(exec_path, resolved) == NULL) return 1;
// resolved = <Contents>/MacOS/bds2 ; climb two dirs to <Contents>.
char macos[PATH_MAX];
strncpy(macos, dirname(resolved), sizeof(macos) - 1);
macos[sizeof(macos) - 1] = '\0';
char *contents = dirname(macos);
char frameworks[PATH_MAX];
snprintf(frameworks, sizeof(frameworks), "%s/Frameworks", contents);
const char *existing = getenv("DYLD_FALLBACK_LIBRARY_PATH");
char fallback[2 * PATH_MAX];
if (existing && *existing)
snprintf(fallback, sizeof(fallback), "%s:%s", frameworks, existing);
else
snprintf(fallback, sizeof(fallback), "%s", frameworks);
setenv("DYLD_FALLBACK_LIBRARY_PATH", fallback, 1);
char bin[PATH_MAX];
snprintf(bin, sizeof(bin), "%s/Resources/rel/bin/%s", contents, BDS_RELEASE_NAME);
execl(bin, BDS_RELEASE_NAME, "start", (char *)NULL);
perror("execl"); // only reached if exec failed
return 127;
}

View File

@@ -1,17 +0,0 @@
#!/bin/sh
# Launcher for <%= name %> (<%= identifier %>).
# Generated by mix bds.bundle.macos — do not edit inside the .app.
#
# Resolves the bundle's own location and execs the embedded Elixir release.
# wxWidgets dylibs live in ../Frameworks and are referenced via @loader_path, so
# the app is self-contained regardless of where the BEAM executable runs from.
set -e
HERE="$(cd "$(dirname "$0")" && pwd)"
APP_CONTENTS="$(cd "$HERE/.." && pwd)"
RELEASE_ROOT="$APP_CONTENTS/Resources/rel"
# Belt-and-suspenders fallback for dyld (primary resolution is @loader_path).
export DYLD_FALLBACK_LIBRARY_PATH="$APP_CONTENTS/Frameworks:${DYLD_FALLBACK_LIBRARY_PATH:-}"
exec "$RELEASE_ROOT/bin/<%= release_name %>" start