diff --git a/packages/flutter_tools/lib/src/ios/xcode_build_settings.dart b/packages/flutter_tools/lib/src/ios/xcode_build_settings.dart index 6aadfdb50d..08a6d0fc6b 100644 --- a/packages/flutter_tools/lib/src/ios/xcode_build_settings.dart +++ b/packages/flutter_tools/lib/src/ios/xcode_build_settings.dart @@ -184,10 +184,15 @@ Future> _xcodeBuildSettingsLines({ // NOTE: this assumes that local engine binary paths are consistent with // the conventions uses in the engine: 32-bit iOS engines are built to // paths ending in _arm, 64-bit builds are not. - // - // Skip this step for macOS builds. - if (!useMacOSConfig) { - String arch; + + String arch; + if (useMacOSConfig) { + if (localEngineName.contains('_arm64')) { + arch = 'arm64'; + } else { + arch = 'x86_64'; + } + } else { if (localEngineName.endsWith('_arm')) { arch = 'armv7'; } else if (localEngineName.contains('_arm64')) { @@ -197,8 +202,8 @@ Future> _xcodeBuildSettingsLines({ } else { arch = 'arm64'; } - xcodeBuildSettings.add('ARCHS=$arch'); } + xcodeBuildSettings.add('ARCHS=$arch'); } if (!useMacOSConfig) { diff --git a/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart b/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart index 93a4acd1df..57e83a75e6 100644 --- a/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart @@ -677,13 +677,13 @@ Information about project "Runner": }); group('updateGeneratedXcodeProperties', () { - Artifacts localArtifacts; + Artifacts localIosArtifacts; FakePlatform macOS; FileSystem fs; setUp(() { fs = MemoryFileSystem.test(); - localArtifacts = Artifacts.test(localEngine: 'out/ios_profile_arm'); + localIosArtifacts = Artifacts.test(localEngine: 'out/ios_profile_arm'); macOS = FakePlatform(operatingSystem: 'macos'); fs.file(xcodebuild).createSync(recursive: true); }); @@ -746,7 +746,7 @@ Build settings for action build and target plugin2: expect(config.readAsStringSync(), contains('EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386\n')); expect(fakeProcessManager, hasNoRemainingExpectations); }, overrides: { - Artifacts: () => localArtifacts, + Artifacts: () => localIosArtifacts, Platform: () => macOS, FileSystem: () => fs, ProcessManager: () => fakeProcessManager, @@ -790,7 +790,7 @@ Build settings for action build and target plugin2: expect(config.readAsStringSync(), contains('EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386 arm64\n')); expect(fakeProcessManager, hasNoRemainingExpectations); }, overrides: { - Artifacts: () => localArtifacts, + Artifacts: () => localIosArtifacts, Platform: () => macOS, FileSystem: () => fs, ProcessManager: () => fakeProcessManager, @@ -846,7 +846,7 @@ Build settings for action build and target plugin2: expect(config.readAsStringSync(), contains('EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386 arm64\n')); expect(fakeProcessManager, hasNoRemainingExpectations); }, overrides: { - Artifacts: () => localArtifacts, + Artifacts: () => localIosArtifacts, Platform: () => macOS, FileSystem: () => fs, ProcessManager: () => fakeProcessManager, @@ -856,14 +856,14 @@ Build settings for action build and target plugin2: void testUsingOsxContext(String description, dynamic Function() testMethod) { testUsingContext(description, testMethod, overrides: { - Artifacts: () => localArtifacts, + Artifacts: () => localIosArtifacts, Platform: () => macOS, FileSystem: () => fs, ProcessManager: () => FakeProcessManager.any(), }); } - testUsingOsxContext('sets ARCHS=armv7 when armv7 local engine is set', () async { + testUsingOsxContext('sets ARCHS=armv7 when armv7 local iOS engine is set', () async { const BuildInfo buildInfo = BuildInfo.debug; final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project')); await updateGeneratedXcodeProperties( @@ -886,6 +886,60 @@ Build settings for action build and target plugin2: expect(buildPhaseScriptContents.contains('EXCLUDED_ARCHS'), isFalse); }); + testUsingContext('sets ARCHS=arm64 when arm64 local host engine is set', () async { + const BuildInfo buildInfo = BuildInfo.debug; + final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project')); + await updateGeneratedXcodeProperties( + project: project, + buildInfo: buildInfo, + useMacOSConfig: true, + ); + + final File config = fs.file('path/to/project/macos/Flutter/ephemeral/Flutter-Generated.xcconfig'); + expect(config.existsSync(), isTrue); + + final String contents = config.readAsStringSync(); + expect(contents.contains('ARCHS=arm64\n'), isTrue); + + final File buildPhaseScript = fs.file('path/to/project/macos/Flutter/ephemeral/flutter_export_environment.sh'); + expect(buildPhaseScript.existsSync(), isTrue); + + final String buildPhaseScriptContents = buildPhaseScript.readAsStringSync(); + expect(buildPhaseScriptContents.contains('export "ARCHS=arm64"'), isTrue); + }, overrides: { + Artifacts: () => Artifacts.test(localEngine: 'out/host_profile_arm64'), + Platform: () => macOS, + FileSystem: () => fs, + ProcessManager: () => FakeProcessManager.any(), + }); + + testUsingContext('sets ARCHS=x86_64 when x64 local host engine is set', () async { + const BuildInfo buildInfo = BuildInfo.debug; + final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project')); + await updateGeneratedXcodeProperties( + project: project, + buildInfo: buildInfo, + useMacOSConfig: true, + ); + + final File config = fs.file('path/to/project/macos/Flutter/ephemeral/Flutter-Generated.xcconfig'); + expect(config.existsSync(), isTrue); + + final String contents = config.readAsStringSync(); + expect(contents.contains('ARCHS=x86_64\n'), isTrue); + + final File buildPhaseScript = fs.file('path/to/project/macos/Flutter/ephemeral/flutter_export_environment.sh'); + expect(buildPhaseScript.existsSync(), isTrue); + + final String buildPhaseScriptContents = buildPhaseScript.readAsStringSync(); + expect(buildPhaseScriptContents.contains('export "ARCHS=x86_64"'), isTrue); + }, overrides: { + Artifacts: () => Artifacts.test(localEngine: 'out/host_profile'), + Platform: () => macOS, + FileSystem: () => fs, + ProcessManager: () => FakeProcessManager.any(), + }); + testUsingOsxContext('does not exclude arm64 simulator when there are no plugins', () async { const BuildInfo buildInfo = BuildInfo.debug; final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));