@@ -480,6 +480,13 @@ protected override bool Read(string filename, Logger logger) {
480480 // Whether to statically link framework in the Podfile.
481481 private const string PREFERENCE_PODFILE_STATIC_LINK_FRAMEWORKS =
482482 PREFERENCE_NAMESPACE + "PodfileStaticLinkFrameworks" ;
483+ // Whether to add Dummy.swift to the generated Xcode project as a workaround to support pods
484+ // with Swift Framework.
485+ private const string PREFERENCE_SWIFT_FRAMEWORK_SUPPORT_WORKAROUND =
486+ PREFERENCE_NAMESPACE + "SwiftFrameworkSupportWorkaroundEnabled" ;
487+ // The Swift Language Version (SWIFT_VERSION) to update to the generated Xcode Project.
488+ private const string PREFERENCE_SWIFT_LANGUAGE_VERSION =
489+ PREFERENCE_NAMESPACE + "SwiftLanguageVersion" ;
483490 // Whether to add an main target to Podfile for Unity 2019.3+.
484491 private const string PREFERENCE_PODFILE_ALWAYS_ADD_MAIN_TARGET =
485492 PREFERENCE_NAMESPACE + "PodfileAlwaysAddMainTarget" ;
@@ -499,6 +506,8 @@ protected override bool Read(string filename, Logger logger) {
499506 PREFERENCE_SKIP_POD_INSTALL_WHEN_USING_WORKSPACE_INTEGRATION ,
500507 PREFERENCE_PODFILE_ADD_USE_FRAMEWORKS ,
501508 PREFERENCE_PODFILE_STATIC_LINK_FRAMEWORKS ,
509+ PREFERENCE_SWIFT_FRAMEWORK_SUPPORT_WORKAROUND ,
510+ PREFERENCE_SWIFT_LANGUAGE_VERSION ,
502511 PREFERENCE_PODFILE_ALWAYS_ADD_MAIN_TARGET ,
503512 PREFERENCE_PODFILE_ALLOW_PODS_IN_MULTIPLE_TARGETS
504513 } ;
@@ -1038,6 +1047,34 @@ public static bool PodfileStaticLinkFrameworks {
10381047 }
10391048 }
10401049
1050+ /// <summary>
1051+ /// Ehether to enable Swift Framework support workaround.
1052+ /// If enabled, iOS Resolver adds a Dummy.swift to the generated Xcode project, and change build
1053+ // properties in order to properly include Swift Standard Libraries.
1054+ /// </summary>
1055+ public static bool SwiftFrameworkSupportWorkaroundEnabled {
1056+ get { return settings . GetBool ( PREFERENCE_SWIFT_FRAMEWORK_SUPPORT_WORKAROUND ,
1057+ defaultValue : false ) ; }
1058+ set {
1059+ settings . SetBool ( PREFERENCE_SWIFT_FRAMEWORK_SUPPORT_WORKAROUND , value ) ;
1060+ }
1061+ }
1062+
1063+ /// <summary>
1064+ /// The value used to set Xcode build property: Swift Language Version (SWIFT_VERSION).
1065+ /// It is default to "5" but Xcode may add or remove options over time.
1066+ /// If blank, iOS Resolver will not override the build property.
1067+ /// Please check the build property "Swift Language Version" options in Xcode project first
1068+ /// before changing this value.
1069+ /// </summary>
1070+ public static string SwiftLanguageVersion {
1071+ get { return settings . GetString ( PREFERENCE_SWIFT_LANGUAGE_VERSION ,
1072+ defaultValue : "5.0" ) ; }
1073+ set {
1074+ settings . SetString ( PREFERENCE_SWIFT_LANGUAGE_VERSION , value ) ;
1075+ }
1076+ }
1077+
10411078 /// <summary>
10421079 /// Whether to add the main target to Podfile for Unity 2019.3+. True by default.
10431080 /// If true, iOS Resolver will add the following lines to Podfile, on top of 'UnityFramework'
@@ -1838,6 +1875,21 @@ public static void OnPostProcessPatchProject(BuildTarget buildTarget,
18381875 PatchProject ( buildTarget , pathToBuiltProject ) ;
18391876 }
18401877
1878+ /// <summary>
1879+ /// Post-processing build step to add dummy swift file
1880+ /// </summary>
1881+ [ PostProcessBuildAttribute ( BUILD_ORDER_PATCH_PROJECT ) ]
1882+ public static void OnPostProcessAddDummySwiftFile ( BuildTarget buildTarget ,
1883+ string pathToBuiltProject ) {
1884+ if ( ! InjectDependencies ( ) ||
1885+ ! PodfileGenerationEnabled ||
1886+ ! PodfileAddUseFrameworks ||
1887+ ! SwiftFrameworkSupportWorkaroundEnabled ) {
1888+ return ;
1889+ }
1890+ AddDummySwiftFile ( buildTarget , pathToBuiltProject ) ;
1891+ }
1892+
18411893 /// <summary>
18421894 /// Get Xcode target names using a method that works across all Unity versions.
18431895 /// </summary>
@@ -1935,13 +1987,50 @@ internal static void PatchProject(
19351987 File . WriteAllText ( pbxprojPath , project . WriteToString ( ) ) ;
19361988 }
19371989
1990+ internal static void AddDummySwiftFile (
1991+ BuildTarget buildTarget , string pathToBuiltProject ) {
1992+ string pbxprojPath = GetProjectPath ( pathToBuiltProject ) ;
1993+ var project = new UnityEditor . iOS . Xcode . PBXProject ( ) ;
1994+ project . ReadFromString ( File . ReadAllText ( pbxprojPath ) ) ;
1995+
1996+ string DUMMY_SWIFT_FILE_NAME = "Dummy.swift" ;
1997+ string DUMMY_SWIFT_FILE_CONTENT =
1998+ "// Generated by External Dependency Manager for Unity\n " +
1999+ "import Foundation" ;
2000+ string dummySwiftPath = Path . Combine ( pathToBuiltProject , DUMMY_SWIFT_FILE_NAME ) ;
2001+ if ( ! File . Exists ( dummySwiftPath ) ) {
2002+ File . WriteAllText ( dummySwiftPath , DUMMY_SWIFT_FILE_CONTENT ) ;
2003+ }
2004+
2005+ foreach ( var target in GetXcodeTargetGuids ( project , includeAllTargets : false ) ) {
2006+ project . AddFileToBuild (
2007+ target ,
2008+ project . AddFile ( DUMMY_SWIFT_FILE_NAME ,
2009+ DUMMY_SWIFT_FILE_NAME ,
2010+ UnityEditor . iOS . Xcode . PBXSourceTree . Source ) ) ;
2011+ if ( ! string . IsNullOrEmpty ( SwiftLanguageVersion ) ) {
2012+ project . SetBuildProperty ( target , "SWIFT_VERSION" , SwiftLanguageVersion ) ;
2013+ }
2014+
2015+ // These build properties are only required for multi-target Xcode project, which is
2016+ // generated from 2019.3+.
2017+ if ( MultipleXcodeTargetsSupported ) {
2018+ project . SetBuildProperty ( target , "CLANG_ENABLE_MODULES" , "YES" ) ;
2019+ project . SetBuildProperty ( target , "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES" , "YES" ) ;
2020+ }
2021+ }
2022+
2023+ File . WriteAllText ( pbxprojPath , project . WriteToString ( ) ) ;
2024+ }
2025+
19382026 /// <summary>
19392027 /// Post-processing build step to generate the podfile for ios.
19402028 /// </summary>
19412029 [ PostProcessBuildAttribute ( BUILD_ORDER_GEN_PODFILE ) ]
19422030 public static void OnPostProcessGenPodfile ( BuildTarget buildTarget ,
19432031 string pathToBuiltProject ) {
19442032 if ( ! InjectDependencies ( ) || ! PodfileGenerationEnabled ) return ;
2033+ Log ( "OnPostProcessGenPodfile!" , level : LogLevel . Error ) ;
19452034 GenPodfile ( buildTarget , pathToBuiltProject ) ;
19462035 }
19472036
0 commit comments