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!

1 Like

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).

Xcode 11.3 supports now SPM with custom Xcode configurations.

5 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?

Update:

Still having the same problem on the initial machine (which has the latest Catalina 10.15.2).

BUT archive & export of exactly the same project are working just normally on another machine which still has Catalina 10.15.1 :roll_eyes: Same version of Xcode (11.3) is on both. I tried deleting derrived data, restarting Xcode and the computer multiple times, but nothing helped. I guess I'll just have to buy a new machine and never update the other one. I'll try tomorrow on the 3rd machine which also has 10.15.2. I hope it's something weird about the latest macOS update, otherwise I wouldn't know what to think anymore.

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.

Terms of Service

Privacy Policy

Cookie Policy