mirror of
https://github.com/SableClient/Sable.git
synced 2026-12-06 08:42:23 -08:00
fix(build): use full Xcode for macOS builds
This commit is contained in:
6 files changed
+99
-3
No files matched your search
@@ -0,0 +1,2 @@
|
||||
[env]
|
||||
MACOSX_DEPLOYMENT_TARGET = { value = "13.0", force = true }
|
||||
@@ -77,7 +77,7 @@ run = [
|
||||
[tasks."tauri:setup:macos"]
|
||||
description = "Install Xcode"
|
||||
confirm = { message = "Install Xcode? (required for Tauri)", default = "no" }
|
||||
run = "xcode-select --print-path >/dev/null 2>&1 || xcode-select --install"
|
||||
run = '''developer_dir="${DEVELOPER_DIR:-$(xcode-select --print-path 2>/dev/null)}" && test -d "$developer_dir/Platforms/MacOSX.platform/Developer/SDKs" || { echo "Full Xcode with the macOS SDK is required. Install Xcode or set DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer (no sudo required)." >&2; exit 1; }'''
|
||||
|
||||
[tasks."tauri:setup:ios"]
|
||||
description = "Set up iOS Xcode project"
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
"fmt": "oxfmt .",
|
||||
"fmt:check": "oxfmt --check .",
|
||||
"typecheck": "tsc",
|
||||
"tauri": "tauri",
|
||||
"tauri": "node scripts/tauri.js",
|
||||
"tauri:cef": "node scripts/tauri.js cef",
|
||||
"tauri:wry": "node scripts/tauri.js wry",
|
||||
"test": "vitest",
|
||||
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
case "${1:-}" in
|
||||
-p|--print-path)
|
||||
printf '%s\n' "${DEVELOPER_DIR:-}"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
exec /usr/bin/xcode-select "$@"
|
||||
+84
-1
@@ -20,8 +20,10 @@
|
||||
*/
|
||||
|
||||
import { run } from '@tauri-apps/cli';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { existsSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname, join } from 'path';
|
||||
import { delimiter, dirname, join, resolve } from 'path';
|
||||
import process from 'node:process';
|
||||
import { PrefixedLogger, createTextHelpers } from './utils/console-style.js';
|
||||
|
||||
@@ -35,6 +37,85 @@ const cmdlineArgs = process.argv.slice(2);
|
||||
process.chdir(join(__dirname, '..'));
|
||||
|
||||
const DESKTOP = new Set(['wry', 'cef']);
|
||||
const DEFAULT_XCODE_DEVELOPER_DIR = '/Applications/Xcode.app/Contents/Developer';
|
||||
|
||||
function normalizeDeveloperDir(value) {
|
||||
const path = resolve(value);
|
||||
return path.endsWith('.app') ? join(path, 'Contents', 'Developer') : path;
|
||||
}
|
||||
|
||||
function isFullXcodeDeveloperDir(developerDir) {
|
||||
return (
|
||||
existsSync(join(developerDir, 'usr', 'bin', 'xcodebuild')) &&
|
||||
existsSync(join(developerDir, 'Platforms', 'MacOSX.platform', 'Developer', 'SDKs'))
|
||||
);
|
||||
}
|
||||
|
||||
function failMacOSToolchain(reason) {
|
||||
logger.error(
|
||||
`${reason} Install full Xcode or set DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function configureMacOSToolchain() {
|
||||
if (process.platform !== 'darwin') {
|
||||
return;
|
||||
}
|
||||
|
||||
const configuredDeveloperDir = process.env.DEVELOPER_DIR?.trim();
|
||||
let developerDir;
|
||||
if (configuredDeveloperDir) {
|
||||
developerDir = normalizeDeveloperDir(configuredDeveloperDir);
|
||||
if (!isFullXcodeDeveloperDir(developerDir)) {
|
||||
failMacOSToolchain(`Full Xcode was not found at DEVELOPER_DIR=${configuredDeveloperDir}.`);
|
||||
}
|
||||
} else {
|
||||
let selectedDeveloperDir;
|
||||
try {
|
||||
selectedDeveloperDir = execFileSync(
|
||||
'/usr/bin/xcode-select',
|
||||
['--print-path'],
|
||||
{ encoding: 'utf8' },
|
||||
).trim();
|
||||
} catch {
|
||||
selectedDeveloperDir = '';
|
||||
}
|
||||
|
||||
const candidates = [selectedDeveloperDir, DEFAULT_XCODE_DEVELOPER_DIR]
|
||||
.filter(Boolean)
|
||||
.map(normalizeDeveloperDir);
|
||||
developerDir = candidates.find(isFullXcodeDeveloperDir);
|
||||
if (!developerDir) {
|
||||
failMacOSToolchain(
|
||||
'Full Xcode was not found at the selected developer directory or /Applications/Xcode.app.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let sdkRoot;
|
||||
try {
|
||||
sdkRoot = execFileSync(
|
||||
'/usr/bin/xcrun',
|
||||
['--sdk', 'macosx', '--show-sdk-path'],
|
||||
{
|
||||
encoding: 'utf8',
|
||||
env: { ...process.env, DEVELOPER_DIR: developerDir },
|
||||
},
|
||||
).trim();
|
||||
} catch {
|
||||
failMacOSToolchain(`Unable to resolve the macOS SDK from DEVELOPER_DIR=${developerDir}.`);
|
||||
}
|
||||
if (!sdkRoot || !existsSync(sdkRoot)) {
|
||||
failMacOSToolchain(`The macOS SDK was not found from DEVELOPER_DIR=${developerDir}.`);
|
||||
}
|
||||
|
||||
process.env.DEVELOPER_DIR = developerDir;
|
||||
process.env.SDKROOT = sdkRoot;
|
||||
process.env.PATH = [join(__dirname, 'macos-bin'), process.env.PATH]
|
||||
.filter(Boolean)
|
||||
.join(delimiter);
|
||||
}
|
||||
|
||||
async function runTauri(args) {
|
||||
logger.info(`${dim('Running:')} tauri ${args.join(' ')}`);
|
||||
@@ -47,6 +128,8 @@ async function runTauri(args) {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
configureMacOSToolchain();
|
||||
|
||||
if (cmdlineArgs.length === 0 || !DESKTOP.has(cmdlineArgs[0])) {
|
||||
return runTauri(cmdlineArgs);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"targets": "all",
|
||||
"createUpdaterArtifacts": true,
|
||||
"macOS": {
|
||||
"minimumSystemVersion": "13.0",
|
||||
"infoPlist": "Info.plist"
|
||||
},
|
||||
"iOS": {
|
||||
|
||||
Reference in new issue
Block a user