Swift package manager and custom build configurations

Hello everyone, we are currently trying to move some projects to use Swift Package Manager but we are running into an issue.

When using a custom build configuration different from Debug or Release, the modules coming from SPM are not found.

For example:

  1. We create a brand new project.
  2. We add for exemple Alamofire through SPM
  3. We create a custom build configration, using Duplicate "Debug" Configuration -> We can name it "Test" for example.
  4. Add import Alamofire somewhere.
  5. When building we get No such module 'Alamofire' error.

When reverting back to the "Debug" config there is no problem.

Is there a limitation on package manager that doesn't allow those custom build configs or is there other steps we can take to set it up?

Thanks!

3 Likes

I asked the same question but here Custom build configuration names

Also running into this issue right now :(

@LaurentHBrunet I'm running into the same issue. Do you have a potential workaround?

This is a known issue that Apple folks are tracking internally. Currently, Swift packages default to the "Release" configuration when anything other than Debug and Release is used. In theory, adding $(BUILD_DIR)/Release to SWIFT_INCLUDE_PATHS build setting for the custom configurations should work around this issue but it can lead to some weird errors in case something unexpected gets picked from that directory.

I tried it and it did not work for me. are you sure that this should work?

It seems to work if SWIFT_INCLUDE_PATHS is set to $(BUILD_DIR)/Release${EFFECTIVE_PLATFORM_NAME}

I also added a new user-defined build setting named DEFAULT_CONFIGURATION where I map between all custom build configurations to either "Debug" or "Release". Then I set SWIFT_INCLUDE_PATHS to $(BUILD_DIR)/${DEFAULT_CONFIGURATION}${EFFECTIVE_PLATFORM_NAME} which should work properly both for Debug and Release builds (I hope, since it's still a work in progress on my side).

2 Likes

Xcode 11.3 supports now SPM with custom Xcode configurations.

7 Likes

We just did some testing with Xcode 11.3, and SPM packages don't build in the intended location anymore in archive mode.

Our apps typically have a number of configurations (like Debug, Release, Distribution, Sparkle, and some other), but our libs typically don't (just 2, Debug and Release) which makes it a lot easier to manager (tens of libs, but just 2 configs to maintain). When building archives, we force Distribution build to go into the Release subfolder by using the CONFIGURATION_BUILD_DIR=$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME) (Xcode target)

It looks like SPM integration in Xcode does not honor this setting anymore in Xcode 11.3 (was ok in 11.2, just broke), and the SPM targets are now built in the Distribution subfolder instead of the Release one, where other Xcode targets are, which break the build.

Is there a way to make the SPM targets inherit the appropriate setting from Xcode and restore previous behavior?

With the new Xcode 11.3, I had zero problems building & running an iOS app project with custom build configurations + local Swift packages without any changes in SWIFT_INCLUDE_PATHS. That's great!

However, when I tried to archive & export I realized that I only get "Generic Xcode Archive" which isn't really useful for export and distribution. Any ideas what's causing this issue or how to fix it?

It worked on the 3rd machine. It also works now on my initial machine. I didn't change anything, ghosts just needed a day or two.

Did this break in Xcode 12.5? Suddenly my archives using SPM on 12.5 (with an empty "Imports Path") are failing, as I can see it's not picking up stuff from under our custom build configuration path when archiving. It works for SPMs in general but if the SPM has a .bundle, it fails.

I'm seeing this error for a module that includes a resource bundle:

error: .../Build/Intermediates.noindex/ArchiveIntermediates/App BETA/BuildProductsPath/Trial/TagPicker_AppkitTagPicker.bundle: No such file or directory (in target 'App Trial' from project 'App')

I get this exact same error on archive "<...>.bundle: No such file or directory <...>" using 12.5, 12.5.1, and 13 beta