This is a Tuist based project that presents a behaviour I could not fully explain. I'm pretty sure it dependes on how Binary targets are defined and compiled, and I'm wondering if there is a simple solution (maybe with a build flag)
-
Two Swift packages under modules
-
Apps with the same code base but different Project.swift defintions
Under the
Modulesfolder are two packages- LocalSwiftPackageFlag - a simple pacakge exposing a protocol (MyConfiguration) an enum (SecurityClient) and a pure function (castAndGetAppID). The
castAndGetAppIDis the testing function. It casts theSecurityClienttype into the protocolMyConfigurationtype ((SecurityClient.self as? MyConfiguration.Type)) - LocalSwiftPackageBootstrap - a lean module that conforms the
SecurityClientto theMyConfigurationprotocol
- LocalSwiftPackageFlag - a simple pacakge exposing a protocol (MyConfiguration) an enum (SecurityClient) and a pure function (castAndGetAppID). The
Note the protocol defines a static propery - and this is where I think the difference of the behaviour I''m going to describe
Under the Apps folder are 3 applications. The applications run the same code. The difference is in the way the applications are importing modules described above
- AppSPM - under the folder
JustWithSPMthere is a simple old-school project file that defines and uses the two package using SPM directly - AppDependencies - under the folder
WithDepdendenciesDotSwiftthere is a simple project file that defines and uses the two package using Dependencies.swift - as external dependenceis - AppDependencies2 - under the folder
WithDepdendenciesDotSwiftConformanceAtTheAppLevelthere is a simple project file that defines and uses the two package using Dependencies.swift - as external dependenceis
All the applications are running the same code - calling print("DB: \(String(describing: Flag.castAndGetAppID()))") at the end of the didFinishLaunchingWithOptions of the AppDelegate.
The issue is, for the AppDependencies the casting fails, for the AppSPM the casting succeeds.
I added the AppDependencies2 to show that if I move the code from the LocalSwiftPackageBootstrap package to the app level, the casting succeeds.
To run and see the diffrrence:
- Clone the repo
- Install Tuist
- Run
tuist installfrom the root of the repo - Run
tuist generatefrom the root of the repo - Run the applicaitons and see the console log out put with the
DB:prefix