Skip to content

Commit 1526f08

Browse files
committed
fix(visionos): build/prepare
1 parent 87cbca9 commit 1526f08

File tree

2 files changed

+67
-44
lines changed

2 files changed

+67
-44
lines changed

lib/commands/build.ts

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
2727
protected $buildController: IBuildController,
2828
$platformValidationService: IPlatformValidationService,
2929
private $buildDataService: IBuildDataService,
30-
protected $logger: ILogger
30+
protected $logger: ILogger,
3131
) {
3232
super(
3333
$options,
3434
$platformsDataService,
3535
$platformValidationService,
36-
$projectData
36+
$projectData,
3737
);
3838
this.$projectData.initializeProjectData();
3939
}
@@ -52,7 +52,7 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
5252
const buildData = this.$buildDataService.getBuildData(
5353
this.$projectData.projectDir,
5454
platform,
55-
this.$options
55+
this.$options,
5656
);
5757
const outputPath = await this.$buildController.prepareAndBuild(buildData);
5858

@@ -63,32 +63,32 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
6363
if (
6464
!this.$platformValidationService.isPlatformSupportedForOS(
6565
platform,
66-
this.$projectData
66+
this.$projectData,
6767
)
6868
) {
6969
this.$errors.fail(
70-
`Applications for platform ${platform} can not be built on this OS`
70+
`Applications for platform ${platform} can not be built on this OS`,
7171
);
7272
}
7373
}
7474

7575
protected async validateArgs(
7676
args: string[],
77-
platform: string
77+
platform: string,
7878
): Promise<boolean> {
7979
if (args.length !== 0) {
8080
this.$errors.failWithHelp(
8181
`The arguments '${args.join(
82-
" "
83-
)}' are not valid for the current command.`
82+
" ",
83+
)}' are not valid for the current command.`,
8484
);
8585
}
8686

8787
const result = await this.$platformValidationService.validateOptions(
8888
this.$options.provision,
8989
this.$options.teamId,
9090
this.$projectData,
91-
platform
91+
platform,
9292
);
9393

9494
return result;
@@ -108,7 +108,7 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
108108
$platformValidationService: IPlatformValidationService,
109109
$logger: ILogger,
110110
$buildDataService: IBuildDataService,
111-
protected $migrateController: IMigrateController
111+
protected $migrateController: IMigrateController,
112112
) {
113113
super(
114114
$options,
@@ -119,7 +119,7 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
119119
$buildController,
120120
$platformValidationService,
121121
$buildDataService,
122-
$logger
122+
$logger,
123123
);
124124
}
125125

@@ -163,7 +163,7 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
163163
protected $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
164164
$buildDataService: IBuildDataService,
165165
protected $logger: ILogger,
166-
private $migrateController: IMigrateController
166+
private $migrateController: IMigrateController,
167167
) {
168168
super(
169169
$options,
@@ -174,7 +174,7 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
174174
$buildController,
175175
$platformValidationService,
176176
$buildDataService,
177-
$logger
177+
$logger,
178178
);
179179
}
180180

@@ -185,12 +185,12 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
185185

186186
if (this.$options.aab) {
187187
this.$logger.info(
188-
AndroidAppBundleMessages.ANDROID_APP_BUNDLE_DOCS_MESSAGE
188+
AndroidAppBundleMessages.ANDROID_APP_BUNDLE_DOCS_MESSAGE,
189189
);
190190

191191
if (this.$options.release) {
192192
this.$logger.info(
193-
AndroidAppBundleMessages.ANDROID_APP_BUNDLE_PUBLISH_DOCS_MESSAGE
193+
AndroidAppBundleMessages.ANDROID_APP_BUNDLE_PUBLISH_DOCS_MESSAGE,
194194
);
195195
}
196196
}
@@ -205,7 +205,7 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
205205
});
206206
}
207207
this.$androidBundleValidatorHelper.validateRuntimeVersion(
208-
this.$projectData
208+
this.$projectData,
209209
);
210210
let canExecute = await super.canExecuteCommandBase(platform);
211211
if (canExecute) {
@@ -233,7 +233,7 @@ export class BuildVisionOsCommand extends BuildIosCommand implements ICommand {
233233
$platformValidationService: IPlatformValidationService,
234234
$logger: ILogger,
235235
$buildDataService: IBuildDataService,
236-
protected $migrateController: IMigrateController
236+
protected $migrateController: IMigrateController,
237237
) {
238238
super(
239239
$options,
@@ -245,15 +245,33 @@ export class BuildVisionOsCommand extends BuildIosCommand implements ICommand {
245245
$platformValidationService,
246246
$logger,
247247
$buildDataService,
248-
$migrateController
248+
$migrateController,
249249
);
250250
}
251251

252+
public async execute(args: string[]): Promise<void> {
253+
await this.executeCore([
254+
this.$devicePlatformsConstants.visionOS.toLowerCase(),
255+
]);
256+
}
257+
252258
public async canExecute(args: string[]): Promise<boolean> {
253-
this.$errors.fail(
254-
'Building for "visionOS" platform is not supported via the CLI. Please open the project in Xcode and build it from there.'
255-
);
256-
return false;
259+
const platform = this.$devicePlatformsConstants.visionOS;
260+
if (!this.$options.force) {
261+
await this.$migrateController.validate({
262+
projectDir: this.$projectData.projectDir,
263+
platforms: [platform],
264+
});
265+
}
266+
267+
super.validatePlatform(platform);
268+
269+
let canExecute = await super.canExecuteCommandBase(platform);
270+
if (canExecute) {
271+
canExecute = await super.validateArgs(args, platform);
272+
}
273+
274+
return canExecute;
257275
}
258276
}
259277

lib/services/ios/xcodebuild-args-service.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import * as _ from "lodash";
1616
import {
1717
DevicePlatformSdkName,
1818
SimulatorPlatformSdkName,
19+
VisionDevicePlatformSdkName,
1920
VisionSimulatorPlatformSdkName,
2021
} from "../ios-project-service";
2122

@@ -26,13 +27,13 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
2627
private $fs: IFileSystem,
2728
private $iOSWatchAppService: IIOSWatchAppService,
2829
private $logger: ILogger,
29-
private $xcconfigService: IXcconfigService
30+
private $xcconfigService: IXcconfigService,
3031
) {}
3132

3233
public async getBuildForSimulatorArgs(
3334
platformData: IPlatformData,
3435
projectData: IProjectData,
35-
buildConfig: IBuildConfig
36+
buildConfig: IBuildConfig,
3637
): Promise<string[]> {
3738
let args = await this.getArchitecturesArgs(buildConfig);
3839

@@ -45,11 +46,11 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
4546
let destination = "generic/platform=iOS Simulator";
4647

4748
let isvisionOS = this.$devicePlatformsConstants.isvisionOS(
48-
buildConfig.platform
49+
buildConfig.platform,
4950
);
5051

5152
if (isvisionOS) {
52-
destination = "platform=visionOS Simulator";
53+
destination = "generic/platform=visionOS Simulator";
5354
if (buildConfig._device) {
5455
destination += `,id=${buildConfig._device.deviceInfo.identifier}`;
5556
}
@@ -67,8 +68,10 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
6768
this.getBuildCommonArgs(
6869
platformData,
6970
projectData,
70-
isvisionOS ? VisionSimulatorPlatformSdkName : SimulatorPlatformSdkName
71-
)
71+
isvisionOS
72+
? VisionSimulatorPlatformSdkName
73+
: SimulatorPlatformSdkName,
74+
),
7275
)
7376
.concat(this.getBuildLoggingArgs())
7477
.concat(this.getXcodeProjectArgs(platformData, projectData));
@@ -79,20 +82,20 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
7982
public async getBuildForDeviceArgs(
8083
platformData: IPlatformData,
8184
projectData: IProjectData,
82-
buildConfig: IBuildConfig
85+
buildConfig: IBuildConfig,
8386
): Promise<string[]> {
8487
const architectures = await this.getArchitecturesArgs(buildConfig);
8588
const archivePath = path.join(
8689
platformData.getBuildOutputPath(buildConfig),
87-
projectData.projectName + ".xcarchive"
90+
projectData.projectName + ".xcarchive",
8891
);
8992
let destination = "generic/platform=iOS";
9093
let isvisionOS = this.$devicePlatformsConstants.isvisionOS(
91-
buildConfig.platform
94+
buildConfig.platform,
9295
);
9396

9497
if (isvisionOS) {
95-
destination = "platform=visionOS";
98+
destination = "generic/platform=visionOS";
9699
if (buildConfig._device) {
97100
destination += `,id=${buildConfig._device.deviceInfo.identifier}`;
98101
}
@@ -113,21 +116,23 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
113116
this.getBuildCommonArgs(
114117
platformData,
115118
projectData,
116-
DevicePlatformSdkName
117-
)
119+
isvisionOS ? VisionDevicePlatformSdkName : DevicePlatformSdkName,
120+
),
118121
)
119122
.concat(this.getBuildLoggingArgs());
120123

121124
return args;
122125
}
123126

124127
private async getArchitecturesArgs(
125-
buildConfig: IBuildConfig
128+
buildConfig: IBuildConfig,
126129
): Promise<string[]> {
127130
const args = [];
128131

129132
if (this.$devicePlatformsConstants.isvisionOS(buildConfig.platform)) {
130-
args.push("ONLY_ACTIVE_ARCH=YES");
133+
// visionOS builds (device/simulator) are arm64-only; rely on destination for arch
134+
// and explicitly exclude x86_64 to avoid accidental selection
135+
args.push("ONLY_ACTIVE_ARCH=YES", "EXCLUDED_ARCHS=x86_64");
131136
return args;
132137
}
133138

@@ -143,11 +148,11 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
143148

144149
public getXcodeProjectArgs(
145150
platformData: IPlatformData,
146-
projectData: IProjectData
151+
projectData: IProjectData,
147152
): string[] {
148153
const xcworkspacePath = path.join(
149154
platformData.projectRoot,
150-
`${projectData.projectName}.xcworkspace`
155+
`${projectData.projectName}.xcworkspace`,
151156
);
152157
// Introduced in Xcode 14+
153158
// ref: https://forums.swift.org/t/telling-xcode-14-beta-4-to-trust-build-tool-plugins-programatically/59305/5
@@ -162,7 +167,7 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
162167
const BUILD_SETTINGS_FILE_PATH = path.join(
163168
projectData.appResourcesDirectoryPath,
164169
platformData.normalizedPlatformName,
165-
constants.BUILD_XCCONFIG_FILE_NAME
170+
constants.BUILD_XCCONFIG_FILE_NAME,
166171
);
167172

168173
// Only include explicit properties from build.xcconfig
@@ -175,7 +180,7 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
175180
const deployTargetProperty = "IPHONEOS_DEPLOYMENT_TARGET";
176181
const deployTargetVersion = this.$xcconfigService.readPropertyValue(
177182
BUILD_SETTINGS_FILE_PATH,
178-
deployTargetProperty
183+
deployTargetProperty,
179184
);
180185
if (deployTargetVersion) {
181186
extraArgs.push(`${deployTargetProperty}=${deployTargetVersion}`);
@@ -184,7 +189,7 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
184189
const swiftUIBootProperty = "NS_SWIFTUI_BOOT";
185190
const swiftUIBootValue = this.$xcconfigService.readPropertyValue(
186191
BUILD_SETTINGS_FILE_PATH,
187-
swiftUIBootProperty
192+
swiftUIBootProperty,
188193
);
189194
if (swiftUIBootValue) {
190195
extraArgs.push(`${swiftUIBootProperty}=${swiftUIBootValue}`);
@@ -196,7 +201,7 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
196201

197202
const xcodeprojPath = path.join(
198203
platformData.projectRoot,
199-
`${projectData.projectName}.xcodeproj`
204+
`${projectData.projectName}.xcodeproj`,
200205
);
201206
return ["-project", xcodeprojPath, ...extraArgs];
202207
}
@@ -208,7 +213,7 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
208213
private getBuildCommonArgs(
209214
platformData: IPlatformData,
210215
projectData: IProjectData,
211-
platformSdkName: string
216+
platformSdkName: string,
212217
): string[] {
213218
let args: string[] = [];
214219

@@ -226,7 +231,7 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
226231
}
227232

228233
private async getArchitecturesFromConnectedDevices(
229-
buildConfig: IiOSBuildConfig
234+
buildConfig: IiOSBuildConfig,
230235
): Promise<string[]> {
231236
const platform = this.$devicePlatformsConstants.iOS.toLowerCase();
232237
await this.$devicesService.initialize({

0 commit comments

Comments
 (0)