SPM dependencies in project used outside generated workspace

Hi :slightly_smiling_face:

I have a project with SPM dependencies. When generating the project, there’s a “Dependencies” virtual group added to the generated workspace with the project on which my project is dependent on.
Now - when building the generated workspace, everything works fine. But when building the project itself (which for me is needed as it’s used as a dependency for other projects, and included in other workspaces), since there are no “Dependencies” directory - the SPM dependencies are not found, and the build fails.

To reproduce, one can run this fixture, it has the same issue (and similar configuration):
tuist/fixtures/ios_app_with_spm_dependencies at main · tuist/tuist · GitHub

Is there anything that should be configured differently for my project to build outside the workspace? What should be done differently to be able to use it as a project? And if anyone can explain in a few words how Tuist works in term of translating the SPM dependencies to “Dependencies” folder, or refer to the relevant code/doc, this will also be great

Thanks! :pray:

Just to answer my own question a little bit, in case anyone runs into it in the future - it does work if the project is defined a little bit differently, so that the SPM package is used. If one adds to the project definition:

let project = Project(
    name: "MyProject",
    organizationName: "com.test",
    packages: [
      .package(url: "https://github.com/package1", from: "1.2.3"),
      .package(url: "https://github.com/package2", from: "0.1.2"),
    ],
...

and then use it as a package dependency in the target:

  dependencies: [
    .package(product: "package1"),
    .package(product: "package2"),
  ],

The packages are added via SPM, so the project compiles on it’s own.

The question is still valid though for using dependencies the way they are used in the fixture referenced above

Hey @Tamar :wave:

The reason why the XcodeProj-based dependencies are missing when you depend directly on your isolated project is because they are integrated as separate Xcode projects, so the whole workspace is needed.

You have a couple of ways to solve it:

  • The workaround you posted that falls back to using the SPM integration that doesn’t depend on a full workspace.
  • Ensure your downstream project also integrates Tuist dependencies.
  • If your project is meant to share code across repositories (or boundaries like Tuist and non-Tuist Xcode projects), you should be able to turn it into a local package. Local packages still play well even with the XcodeProj-based integration.

Alternatively, we would need to add support for generating dependencies in a flat manner, that is without generating extra Xcode projects. However, that might be quite complex and I’d lean not doing that unless this would be a need raised by more users.

Is the reason you depend on the Tuist project directly outside of Tuist because you’re in a middle of the migration to Tuist? I’d love to know more about your setup that lead you to this scenario to provide better help :slightly_smiling_face:

2 Likes

Thanks for the reply! It’s partly because the migration is not yet completed, but also - working with workspaces is not a must, many times having project with different targets and dependencies on other projects is sufficient.

So the setup is quite simple - a project which is simple enough to be a project and not a workspace, and it depends on another project, generated with Tuist. One can always change the structure of the projects that depends on the Tuist-generated one, but I would expect it to not be dependent on using workspaces.

For my case, using the workaround mentioned above was sufficient, but maybe it can help someone in the future.