Skip to content

Forward SPM -package-name to dylib recompile#132

Merged
obj-p merged 2 commits intomainfrom
fix/spm-package-name
Apr 21, 2026
Merged

Forward SPM -package-name to dylib recompile#132
obj-p merged 2 commits intomainfrom
fix/spm-package-name

Conversation

@obj-p
Copy link
Copy Markdown
Owner

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

Summary

  • Fix dylib recompile failing with cannot find 'X' in scope when the previewed file references package-scoped symbols from a sibling target — SPM passes -package-name <identity> to every target it builds, but SPMBuildSystem wasn't forwarding it to the raw swiftc invocation.
  • Read the identity out of SPM's own LLBuild manifest (.build/<config>.yaml) rather than recomputing it (SPM uses the lowercased directory basename for path packages, not Package.swift's name:).
  • Derive the manifest path from binPath so --scratch-path / SWIFTPM_BUILD_DIR users are covered.

Regression guard

examples/spm/Sources/ToDoExtras/Formatter.swift now exposes package enum PackageScopedLabel, referenced from Summary.swift in the ToDo target. The existing tier2Compile end-to-end test fails with the exact error from the bug report when the fix is disabled; passes with it in place.

Test plan

  • swift build
  • swift test --filter BuildSystem (59 tests, incl. 6 new for readPackageName / manifestPath)
  • swift test --filter PreviewSessionBuildContextTests (5 tests, incl. updated spmLinksDependencyTargets asserting -package-name spm)
  • Sanity-check: temporarily disabled the fix and confirmed tier2Compile fails with cannot find 'PackageScopedLabel' in scope — the exact symptom from the bug report.

🤖 Generated with Claude Code

obj-p added a commit that referenced this pull request Apr 21, 2026
Address review nits on PR #132:

- trim whitespacesAndNewlines so a stray CRLF manifest doesn't strand
  a trailing \r on the line and defeat the prefix check
- `continue` (not `return nil`) when a matched module-name line lacks
  -package-name, so an SPM variant that emits multiple commands per
  target can still succeed on the args line that carries the flag

No behavioral change against the real SPM manifest shape; defense in
depth only.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
obj-p and others added 2 commits April 20, 2026 21:01
Previewing a file in a Swift package that uses `package`-access symbols
across sibling targets failed with "cannot find 'X' in scope" because the
dylib recompile step omitted `-package-name <identity>`. SPM's package
identity can't be derived from Package.swift's `name:` (it's the lowercased
directory basename for path packages), so read it from the LLBuild manifest
at `.build/<config>.yaml` and thread it through BuildContext.compilerFlags.

The fix is scoped to SPM — Bazel and Xcode gate package access through
different mechanisms. Manifest path is derived from binPath so relocating
`.build` via --scratch-path / SWIFTPM_BUILD_DIR continues to work.

examples/spm's ToDoExtras now exposes a `package`-scoped helper that
Summary.swift references, turning the existing tier2Compile test into a
direct regression guard for this code path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Address review nits on PR #132:

- trim whitespacesAndNewlines so a stray CRLF manifest doesn't strand
  a trailing \r on the line and defeat the prefix check
- `continue` (not `return nil`) when a matched module-name line lacks
  -package-name, so an SPM variant that emits multiple commands per
  target can still succeed on the args line that carries the flag

No behavioral change against the real SPM manifest shape; defense in
depth only.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@obj-p obj-p force-pushed the fix/spm-package-name branch from 9cefbcd to b0fc8a3 Compare April 21, 2026 01:01
@obj-p obj-p merged commit c965deb into main Apr 21, 2026
4 checks passed
@obj-p obj-p deleted the fix/spm-package-name branch April 21, 2026 01:44
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.

1 participant