Skip to content

Fix SPM dependency linking and Xcode multi-scheme selection#73

Merged
obj-p merged 1 commit intomainfrom
fix-spm-deps-and-xcode-schemes
Apr 10, 2026
Merged

Fix SPM dependency linking and Xcode multi-scheme selection#73
obj-p merged 1 commit intomainfrom
fix-spm-deps-and-xcode-schemes

Conversation

@obj-p
Copy link
Copy Markdown
Owner

@obj-p obj-p commented Apr 10, 2026

Summary

Fixes #69 and #70.

  • SPM dependency linking (SPM build doesn't include package dependencies in build context #69): After swift build, SPMBuildSystem now archives each dependency target's .o files into lib<Dep>.a and passes -L <binPath> -l<Dep> to the bridge compilation. SPM doesn't create static archives or emit autolink hints for library targets, so the build system stages them explicitly. Covers both sibling targets within the same Package.swift and cross-package dependencies resolved via .package(path:) or .package(url:).

  • Xcode multi-scheme selection (Xcode projects/workspaces don't auto-pick a scheme when multiple are present #70): Adds an optional scheme parameter to preview_start (MCP), --scheme (CLI run/snapshot), and BuildSystemDetector.detect(). When set, pickScheme() validates it against the project's scheme list and returns it (overriding heuristics). When unset, existing behavior is preserved (single-scheme auto-pick, path-component matching). The ambiguous-target error now names the scheme parameter and lists candidates. Also adds BuildSystemError.unknownScheme for when an explicit scheme isn't found.

Test plan

  • PreviewSessionBuildContextTests.spmLinksDependencyTargets — verifies -L, -lToDoExtras (sibling target), and -lLocalDep (cross-package) are in compiler flags, and -lToDo (consumer) is excluded
  • PreviewSessionBuildContextTests.tier2Compile — end-to-end Tier 2 dylib compilation succeeds with import ToDoExtras and import LocalDep in the source tree
  • BuildSystemTests.pickSchemeHonorsRequested — explicit scheme overrides path-component heuristic
  • BuildSystemTests.pickSchemeRejectsUnknownRequested — unknown scheme surfaces clear error with candidates
  • BuildSystemTests.pickSchemeRequestedWinsOverSingle — explicit mismatch throws even with one scheme
  • BuildSystemTests.ambiguousTargetErrorMessage — error text mentions scheme parameter
  • BuildSystemTests.detectorPassesSchemeToXcode — scheme threads through BuildSystemDetector to XcodeBuildSystem
  • All 50 targeted tests pass locally (BuildSystem + PreviewSessionBuildContextTests suites)

🤖 Generated with Claude Code

SPM: After swift build, archive each dependency target's .o files into
lib<Dep>.a and pass -L <binPath> -l<Dep> so the bridge dylib can link
against sibling targets and cross-package dependencies. SPM doesn't
create static archives or emit autolink hints for library targets, so
the build system has to stage them explicitly.

Xcode: Add optional `scheme` parameter threaded from MCP tool schemas
and CLI options through BuildSystemDetector into XcodeBuildSystem.
When set, pickScheme() validates it against the project's scheme list.
When unset, existing heuristics apply (single scheme auto-pick, then
path-component matching). Ambiguous-target error now names the `scheme`
parameter instead of suggesting `projectRoot`.

Adds ToDoExtras (sibling target) and LocalDep (cross-package path dep)
to the SPM example. The existing Tier 2 test now exercises dependency
linking as a regression guard.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@obj-p obj-p force-pushed the fix-spm-deps-and-xcode-schemes branch from 62f79f0 to 4fe1067 Compare April 10, 2026 12:39
@obj-p obj-p merged commit b774fdd into main Apr 10, 2026
4 checks passed
@obj-p obj-p deleted the fix-spm-deps-and-xcode-schemes branch April 10, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SPM build doesn't include package dependencies in build context

1 participant