Skip to content

Commit 3e91032

Browse files
committed
fix(ios): keep macro packages, provisioned debug builds and old output paths working
- Pass SWIFT_ENABLE_EXPLICIT_MODULES=NO when Package.resolved pins swift-syntax (i.e. a package ships macros), so Xcode 26 builds of those apps keep working. Other apps still leave it to Xcode and share DerivedData with it; build.xcconfig still wins either way. - Archive and export debug device builds when --provision, mobileProvisionIdentifier or --i-cloud-container-environment is set, so the export method, extension profiles and iCloud environment still apply. - Copy the built .app/.ipa to platforms/ios/build/<Config>-<sdk>/ as well (an APFS clone), so CI scripts and Detox binaryPath settings that use the old location keep working. A failed copy only warns. - Podfile build settings hook: skip non-numeric deployment targets instead of letting Gem::Version raise, and walk installer.generated_projects so generate_multiple_pod_projects setups get the settings too. - Move the DerivedData/compilation-cache path helpers into lib/services/ios/ios-build-paths.ts so importing them doesn't load ios-project-service, and put findDevice above getDeviceByIdentifier's JSDoc instead of between them.
1 parent 2b11b86 commit 3e91032

10 files changed

Lines changed: 435 additions & 77 deletions

‎lib/common/mobile/mobile-core/devices-service.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,7 @@ export class DevicesService
522522
}
523523

524524
/**
525-
* Returns device that matches an identifier.
526-
* The identifier is expected to be the same as the running device declares it (emulator-5554 for android or GUID for ios).
527-
* @param identifier running emulator or device identifier
525+
* Finds a device by identifier, display name or emulator image identifier.
528526
*/
529527
private findDevice(deviceOption: string): Mobile.IDevice {
530528
return _.find(
@@ -538,6 +536,11 @@ export class DevicesService
538536
);
539537
}
540538

539+
/**
540+
* Returns device that matches an identifier.
541+
* The identifier is expected to be the same as the running device declares it (emulator-5554 for android or GUID for ios).
542+
* @param identifier running emulator or device identifier
543+
*/
541544
public getDeviceByIdentifier(identifier: string): Mobile.IDevice {
542545
const searchedDevice = _.find(
543546
this.getDeviceInstances(),

‎lib/services/cocoapods-service.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,12 @@ end`.trim();
254254
(value, key) =>
255255
` config.build_settings[${toRubyString(key)}] = ${toRubyString(value)}`,
256256
);
257-
if (deploymentTarget) {
257+
// Only numeric versions are compared: Gem::Version.new raises on values
258+
// like $(RECOMMENDED_IPHONEOS_DEPLOYMENT_TARGET), which are left alone.
259+
if (deploymentTarget && /^\d+(\.\d+)*$/.test(deploymentTarget)) {
258260
configLines.push(
259261
` current = config.build_settings["IPHONEOS_DEPLOYMENT_TARGET"]`,
260-
` if current.nil? || Gem::Version.new(current) < Gem::Version.new(${toRubyString(deploymentTarget)})`,
262+
` if current.nil? || (Gem::Version.correct?(current) && Gem::Version.new(current) < Gem::Version.new(${toRubyString(deploymentTarget)}))`,
261263
` config.build_settings["IPHONEOS_DEPLOYMENT_TARGET"] = ${toRubyString(deploymentTarget)}`,
262264
` end`,
263265
);
@@ -271,9 +273,15 @@ end`.trim();
271273
buildSettingsPodfile,
272274
[
273275
"post_install do |installer|",
274-
" installer.pods_project.targets.each do |target|",
275-
" target.build_configurations.each do |config|",
276-
...configLines,
276+
// With generate_multiple_pod_projects, pod targets live in their
277+
// own projects rather than in pods_project.
278+
" projects = installer.respond_to?(:generated_projects) ? installer.generated_projects.to_a : []",
279+
" projects = [installer.pods_project] if projects.empty?",
280+
" projects.compact.each do |project|",
281+
" project.targets.each do |target|",
282+
" target.build_configurations.each do |config|",
283+
...configLines.map((line) => ` ${line}`),
284+
" end",
277285
" end",
278286
" end",
279287
"end",

‎lib/services/ios-project-service.ts‎

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ import { injector } from "../common/yok";
5858
import { INotConfiguredEnvOptions } from "../common/definitions/commands";
5959
import { IProjectChangesInfo } from "../definitions/project-changes";
6060
import { ITempService } from "../definitions/temp-service";
61+
import {
62+
DERIVED_DATA_RELATIVE_PATH,
63+
getCompilationCachePath,
64+
getDerivedDataPath,
65+
} from "./ios/ios-build-paths";
6166

6267
interface INativeSourceCodeGroup {
6368
name: string;
@@ -70,31 +75,6 @@ export const SimulatorPlatformSdkName = "iphonesimulator";
7075
export const VisionDevicePlatformSdkName = "xros";
7176
export const VisionSimulatorPlatformSdkName = "xrsimulator";
7277

73-
const DERIVED_DATA_RELATIVE_PATH = path.join(
74-
constants.BUILD_DIR,
75-
"DerivedData",
76-
);
77-
78-
/**
79-
* With a workspace-relative DerivedData location, Xcode appends the workspace
80-
* name to it, so this matches what Xcode uses and lets CLI and Xcode builds
81-
* share one cache.
82-
*/
83-
export const getDerivedDataPath = (
84-
projectRoot: string,
85-
projectName: string,
86-
): string => path.join(projectRoot, DERIVED_DATA_RELATIVE_PATH, projectName);
87-
88-
/**
89-
* Lives next to the platform folder rather than in it, so regenerating
90-
* platforms/ios still reuses unchanged compiles; deleting platforms/ clears it.
91-
*/
92-
export const getCompilationCachePath = (
93-
platformsDir: string,
94-
platformName: string,
95-
): string =>
96-
path.join(platformsDir, ".cache", platformName, "CompilationCache");
97-
9878
const FRAMEWORK_EXTENSIONS = [".framework", ".xcframework"];
9979

10080
const getPlatformSdkName = (buildData: IBuildData): string => {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import * as path from "path";
2+
import * as constants from "../../constants";
3+
4+
export const DERIVED_DATA_RELATIVE_PATH = path.join(
5+
constants.BUILD_DIR,
6+
"DerivedData",
7+
);
8+
9+
/**
10+
* With a workspace-relative DerivedData location, Xcode appends the workspace
11+
* name to it, so this matches what Xcode uses and lets CLI and Xcode builds
12+
* share one cache.
13+
*/
14+
export const getDerivedDataPath = (
15+
projectRoot: string,
16+
projectName: string,
17+
): string => path.join(projectRoot, DERIVED_DATA_RELATIVE_PATH, projectName);
18+
19+
/**
20+
* Lives next to the platform folder rather than in it, so regenerating
21+
* platforms/ios still reuses unchanged compiles; deleting platforms/ clears it.
22+
*/
23+
export const getCompilationCachePath = (
24+
platformsDir: string,
25+
platformName: string,
26+
): string =>
27+
path.join(platformsDir, ".cache", platformName, "CompilationCache");
28+
29+
/**
30+
* Where builds put their .app/.ipa before DerivedData moved into the
31+
* platforms folder. CI scripts and Detox configs still point here.
32+
*/
33+
export const getLegacyBuildOutputPath = (
34+
projectRoot: string,
35+
buildOutputPath: string,
36+
): string =>
37+
path.join(projectRoot, constants.BUILD_DIR, path.basename(buildOutputPath));
38+
39+
/**
40+
* Xcode keeps one Package.resolved per workspace: the CocoaPods workspace when
41+
* there is one, otherwise the project's embedded workspace.
42+
*/
43+
export const getPackageResolvedPaths = (
44+
projectRoot: string,
45+
projectName: string,
46+
): string[] => [
47+
path.join(
48+
projectRoot,
49+
`${projectName}.xcworkspace`,
50+
"xcshareddata",
51+
"swiftpm",
52+
"Package.resolved",
53+
),
54+
path.join(
55+
projectRoot,
56+
`${projectName}.xcodeproj`,
57+
"project.xcworkspace",
58+
"xcshareddata",
59+
"swiftpm",
60+
"Package.resolved",
61+
),
62+
];

‎lib/services/ios/spm-service.ts‎

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { injector } from "../../common/yok";
22
import { IProjectConfigService, IProjectData } from "../../definitions/project";
33
import { IPlatformData } from "../../definitions/platform";
4-
import { getDerivedDataPath } from "../ios-project-service";
4+
import {
5+
getDerivedDataPath,
6+
getPackageResolvedPaths,
7+
} from "./ios-build-paths";
58
import { IFileSystem } from "../../common/declarations";
69
import { ITerminalSpinnerService } from "../../definitions/terminal-spinner-service";
710
import { color } from "../../color";
@@ -540,23 +543,10 @@ export class SPMService implements ISPMService {
540543
platformData: IPlatformData,
541544
projectData: IProjectData,
542545
): boolean {
543-
const candidates = [
544-
path.join(
545-
platformData.projectRoot,
546-
`${projectData.projectName}.xcworkspace`,
547-
"xcshareddata",
548-
"swiftpm",
549-
"Package.resolved",
550-
),
551-
path.join(
552-
platformData.projectRoot,
553-
`${projectData.projectName}.xcodeproj`,
554-
"project.xcworkspace",
555-
"xcshareddata",
556-
"swiftpm",
557-
"Package.resolved",
558-
),
559-
];
546+
const candidates = getPackageResolvedPaths(
547+
platformData.projectRoot,
548+
projectData.projectName,
549+
);
560550
return (
561551
candidates.some((p) => this.$fs.exists(p)) &&
562552
this.$fs.exists(

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

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import { IFileSystem } from "../../common/declarations";
1313
import { injector } from "../../common/yok";
1414
import * as _ from "lodash";
1515

16-
import { getDerivedDataPath } from "../ios-project-service";
16+
import {
17+
getDerivedDataPath,
18+
getPackageResolvedPaths,
19+
} from "./ios-build-paths";
1720

1821
export class XcodebuildArgsService implements IXcodebuildArgsService {
1922
constructor(
@@ -116,12 +119,21 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
116119

117120
/**
118121
* Debug device builds use a plain build, like Xcode's Run, so both share
119-
* one set of intermediates; archives are only needed for release.
122+
* one set of intermediates. Archiving is still needed for release, and
123+
* whenever -exportArchive has to apply options a plain build can't: an
124+
* explicit provisioning profile (which also selects the export method and
125+
* the extensions' profiles) or an iCloud container environment.
120126
*/
121127
public shouldArchiveDeviceBuild(
122128
buildConfig: IBuildConfig & { buildForAppStore?: boolean },
123129
): boolean {
124-
return !!(buildConfig.release || buildConfig.buildForAppStore);
130+
return !!(
131+
buildConfig.release ||
132+
buildConfig.buildForAppStore ||
133+
buildConfig.provision ||
134+
buildConfig.mobileProvisionIdentifier ||
135+
buildConfig.iCloudContainerEnvironment
136+
);
125137
}
126138

127139
private async getArchitecturesArgs(
@@ -220,17 +232,19 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
220232
// https://github.com/CocoaPods/CocoaPods/issues/7003
221233

222234
// Passed as a command-line build setting so it also reaches package
223-
// targets, but only when the app sets it: any value Xcode wouldn't use
224-
// itself stops CLI and Xcode builds from reusing each other's output.
225-
// Early Xcode 26 releases fail on macro packages with explicit modules
226-
// ("Unable to resolve module dependency: 'SwiftSyntax'"); setting it to
227-
// NO in build.xcconfig works around that.
235+
// targets. Xcode 26 builds macro packages with explicit modules and
236+
// fails with "Unable to resolve module dependency: 'SwiftSyntax'", so
237+
// those apps default to NO. Otherwise it is left to Xcode: any value
238+
// Xcode wouldn't use itself stops CLI and Xcode builds from reusing
239+
// each other's output.
228240
// ref: https://forums.swift.org/t/xcode-26-unable-to-find-module-dependency/80516
229241
const explicitModulesProperty = "SWIFT_ENABLE_EXPLICIT_MODULES";
230-
const explicitModulesValue = this.$xcconfigService.readPropertyValue(
231-
BUILD_SETTINGS_FILE_PATH,
232-
explicitModulesProperty,
233-
);
242+
const explicitModulesValue =
243+
this.$xcconfigService.readPropertyValue(
244+
BUILD_SETTINGS_FILE_PATH,
245+
explicitModulesProperty,
246+
) ||
247+
(this.hasSwiftMacroPackages(platformData, projectData) ? "NO" : null);
234248
if (explicitModulesValue) {
235249
extraArgs.push(`${explicitModulesProperty}=${explicitModulesValue}`);
236250
}
@@ -267,6 +281,43 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
267281
return ["-project", xcodeprojPath, ...extraArgs];
268282
}
269283

284+
/**
285+
* Macro targets are built against swift-syntax, so a resolved swift-syntax
286+
* pin means at least one package ships macros.
287+
*/
288+
private hasSwiftMacroPackages(
289+
platformData: IPlatformData,
290+
projectData: IProjectData,
291+
): boolean {
292+
return getPackageResolvedPaths(
293+
platformData.projectRoot,
294+
projectData.projectName,
295+
).some((packageResolvedPath) => {
296+
if (!this.$fs.exists(packageResolvedPath)) {
297+
return false;
298+
}
299+
300+
let resolved: any;
301+
try {
302+
resolved = this.$fs.readJson(packageResolvedPath);
303+
} catch (err) {
304+
this.$logger.trace(`Unable to parse ${packageResolvedPath}: `, err);
305+
return false;
306+
}
307+
308+
// Package.resolved v1 nests pins under "object" and names the URL
309+
// "repositoryURL"; v2 and later use top-level pins with "location".
310+
const pins: any[] = resolved?.pins ?? resolved?.object?.pins ?? [];
311+
return pins.some(
312+
(pin) =>
313+
pin?.identity?.toLowerCase() === "swift-syntax" ||
314+
/\/swift-syntax(\.git)?\/?$/i.test(
315+
pin?.location ?? pin?.repositoryURL ?? "",
316+
),
317+
);
318+
});
319+
}
320+
270321
private getBuildLoggingArgs(): string[] {
271322
return this.$logger.getLevel() === "INFO" ? ["-quiet"] : [];
272323
}

0 commit comments

Comments
 (0)