Resolving Swift Package via Multiple Protocols

I am not sure if it's right to automatically checkout submodules for the root package. In general, SwiftPM avoids performing git operations on the root package (there might not even be a git repository).

1 Like

An alternative solution might involve using URL rewriting provided in Git. We use this on developer machines to rewrite all SSH connections to HTTPS for GitHub to deal with restrictive proxies.

2 Likes

.netrc support being discussed here also: SPM support basic auth for non-git binary dependency hosts.

This is such a great solution/suggestion/workaround. For the first time my private SwiftPM dependencies resolve in my CI. A quick before_script step in my GitLab CI configuration to call git config and it works :tada:.

swiftpm_build:
  stage: build
  before_script:
    - "git config --global url.$CI_SERVER_PROTOCOL://gitlab-ci-token:$CI_JOB_TOKEN@$CI_SERVER_HOST/.insteadOf git@$CI_SERVER_HOST:"
    - swift package resolve
  script:
    - swift build -c release
  tags:
    - swift-5.0

Then the dark times... xcodebuild. Why xcodebuild? Because that's how you run SwiftPM tests on iOS. I do not make the rules. I just work here.

xcodebuild:
  stage: build
  variables:
    DESTINATION: platform=iOS Simulator,name=iPad Pro (9.7 inch),OS=10.3.1
  before_script:
    - "git config --global url.$CI_SERVER_PROTOCOL://gitlab-ci-token:$CI_JOB_TOKEN@$CI_SERVER_HOST/.insteadOf git@$CI_SERVER_HOST:"
    - xcodebuild -resolvePackageDependencies
  script:
    - xcodebuild -enableCodeCoverage YES -scheme "$XCODE_SCHEME" -destination "$DESTINATION" build-for-testing
  tags:
    - swift-5.0
    - iOS-10.3.1
Resolve Package Graph

Fetching git@private.gitlab.instance.local:group/dependency.git


Resolved source packages:
  SwiftPMProject: /Users/buildbot/SwiftPMProject

xcodebuild: error: Could not resolve package dependencies:
  The repository could not be found. Make sure a valid repository exists at the specified location and try again.

So apparently xcodebuild does its own package resolution outside of Git. :man_shrugging:

So close to nirvana.

Regardless, thanks @monocularvision

1 Like

Passing -usePackageSupportBuiltinSCM to xcodebuild should work here. By default, Xcode uses its own SCM subsystem for fetching packages, but this option makes it use the one in libSwiftPM, so it should behave similar to swift build at that point.

2 Likes

@NeoNacho thank you; that did work.

Though for any intrepid reader that makes there way here. The -usePackageSupportBuiltinSCM did not work on Xcode/xcodebuild 11.3.1. On 11.3.1 when the tests are run apparently the dependency is not on the @rpath.

It may work on some other version but I just jumped to 11.5.0 and it worked there.

Terms of Service

Privacy Policy

Cookie Policy