From f3787d7f8381caee7176b23824c297d240374a70 Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Sat, 8 Aug 2026 22:22:22 +0200 Subject: [PATCH] Handle xcrun failures via getXCodeSDK/getXCodeClang helpers --- hook/build.dart | 13 ++----------- lib/helpers/extensions/get_xcode_sdk.dart | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/hook/build.dart b/hook/build.dart index 83474b9..aa5d94e 100644 --- a/hook/build.dart +++ b/hook/build.dart @@ -28,11 +28,7 @@ Future main(List args) => build(args, (input, output) async { final iosConfig = codeConfig.iOS; iosSdk = iosConfig.targetSdk; final minVersion = iosConfig.targetVersion; - iosSdkPath = (await Process.run("xcrun", [ - "--sdk", - iosSdk.type, - "--show-sdk-path", - ])).stdout.toString().trim(); + iosSdkPath = await getXCodeSDK(sdkType: iosSdk.type); final archTriple = switch (targetArch) { Architecture.arm64 => "arm64", Architecture.x64 => "x86_64", @@ -45,12 +41,7 @@ Future main(List args) => build(args, (input, output) async { : "$archTriple-apple-ios$minVersion.0"; extraEnv = { "GOOS": "ios", - "CC": (await Process.run("xcrun", [ - "--sdk", - iosSdk.type, - "-f", - "clang", - ])).stdout.toString().trim(), + "CC": await getXCodeClang(sdkType: iosSdk.type), "CGO_CFLAGS": "-isysroot $iosSdkPath -target $iosTargetTriple", "CGO_LDFLAGS": "-isysroot $iosSdkPath -target $iosTargetTriple", }; diff --git a/lib/helpers/extensions/get_xcode_sdk.dart b/lib/helpers/extensions/get_xcode_sdk.dart index 4c09246..4deb73a 100644 --- a/lib/helpers/extensions/get_xcode_sdk.dart +++ b/lib/helpers/extensions/get_xcode_sdk.dart @@ -1,11 +1,22 @@ import "dart:io"; -Future getXCodeSDK() async { - final result = await Process.run("xcrun", ["--show-sdk-path"]); +Future _runXcrun(List args, String errorContext) async { + final result = await Process.run("xcrun", args); if (result.exitCode != 0) { - throw Exception("Failed to get XCode SDK\n${result.stderr}"); + throw Exception("Failed to $errorContext\n${result.stderr}"); } - return result.stdout.trim(); + return result.stdout.toString().trim(); } + +Future getXCodeSDK({String? sdkType}) => _runXcrun([ + if (sdkType != null) ...["--sdk", sdkType], + "--show-sdk-path", +], "get XCode SDK"); + +Future getXCodeClang({String? sdkType}) => _runXcrun([ + if (sdkType != null) ...["--sdk", sdkType], + "-f", + "clang", +], "get XCode clang");