Repository navigation
[SwiftBuild] Keep macro implementation products as build-time dependencies in SwiftPM PIF generation #776
Description
Description
Follow-up from #773.
Swift macro implementation products are compile-time tools, but SwiftPM's generated PIF can treat a macro implementation target like a target-side dependency for WASI builds. In the minimum reproducer, ReproMacrosImpl is a macro implementation target and intentionally contains this guard:
#if os(WASI)
#error("ReproMacrosImpl must not be compiled for the WASI target")
#endifClientTests depends only on Client, which uses the macro declaration from ReproMacros. The macro implementation should be available as a host build tool for macro expansion, but it should not be compiled as a WASI target-side product.
Updated reproducer zip: https://gist.githubusercontent.com/kateinoigakukun/ba21c654a675032aa77906877c906e53/raw/b457bfba4389d1bacd730f0475020c0ee04844f0/updated-776-macro-build-dependency-linux-2026-06-12.zip
The updated zip preserves the original repro package and original repro.sh, and also includes repro-linux-2026-06-12.sh plus adaptation notes for running the same reproducer with the Linux June 12 snapshot toolchain and Swift SDK.
Expected behavior
Macro implementation targets should remain host/build-time dependencies. SwiftBuild should not build a WASI-side ReproMacrosImpl--...-testable variant for this transitive macro path, and macro implementation artifacts should not contaminate target-side WASI products.
The native and SwiftBuild backends should both build the package tests for the WASI Swift SDK. Macro-dependent tests should still get the direct macro testable variants they need, without pulling the macro implementation into the target-side WASI build.
Actual behavior
With the June 12, 2026 development snapshot and swift-DEVELOPMENT-SNAPSHOT-2026-06-12-a_wasm, the native backend succeeds and SwiftBuild still reproduces the original failure.
Observed in the latest verification:
native exit: 0
swiftbuild exit: 1
swiftbuild testable macro mentions: 24
SwiftBuild plans/compiles a WASI testable macro implementation variant:
ReproMacrosImpl--3E7BE6D87A4DC5F2-testable
and fails with:
Sources/ReproMacrosImpl/ReproMacrosImpl.swift:6:8: error: ReproMacrosImpl must not be compiled for the WASI target
6 | #error("ReproMacrosImpl must not be compiled for the WASI target")
Steps to reproduce
-
Download and unzip
https://gist.githubusercontent.com/kateinoigakukun/ba21c654a675032aa77906877c906e53/raw/b457bfba4389d1bacd730f0475020c0ee04844f0/updated-776-macro-build-dependency-linux-2026-06-12.zip. -
Enter the package directory:
cd 776-macro-build-dependency -
On this Linux verification machine, run the adapted script:
./repro-linux-2026-06-12.sh
The adapted script uses:
/home/ubuntu/.local/share/swiftly/toolchains/main-snapshot-2026-06-12/usr/bin/swift swift-DEVELOPMENT-SNAPSHOT-2026-06-12-a_wasm -
On a machine matching the original macOS-style repro assumptions, the original script is still available:
./repro.sh
-
The script runs the same comparison for both build systems:
swift build --package-path "$ROOT" --scratch-path "$WORK/native" --swift-sdk "$SWIFT_SDK_ID" --build-system native --build-tests -v swift build --package-path "$ROOT" --scratch-path "$WORK/swiftbuild" --swift-sdk "$SWIFT_SDK_ID" --build-system swiftbuild --build-tests -v
-
Expected reproducer result for the current bug: native exits
0; SwiftBuild exits nonzero with the WASI-sideReproMacrosImpl#error.
Swift Package Manager version/commit hash
Swift Package Manager - Swift 6.5.0-dev
Swift & OS version (output of swift --version ; uname -a)
Swift version 6.5-dev (LLVM 18d2bfb70c14d89, Swift c13d82e5987aecb)
Target: x86_64-unknown-linux-gnu
Build config: +assertions
Linux swift-dev.fugu.katei.dev 6.8.0-94-generic #96-Ubuntu SMP PREEMPT_DYNAMIC Fri Jan 9 20:36:55 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Activity
--build-system swiftbuildcompatibility issues #773[-]Keep macro implementation products as build-time dependencies in SwiftPM PIF generation[/-][+][SwiftBuild] Keep macro implementation products as build-time dependencies in SwiftPM PIF generation[/+]kateinoigakukun commentedon Jun 23, 2026
Minimum reproducer zip is here:
776-macro-build-dependency.zipHow to reproduce:
curl -L -O https://gist.githubusercontent.com/kateinoigakukun/ba21c654a675032aa77906877c906e53/raw/d6090f208812103144ec581b60cd9d9a12734f7c/776-macro-build-dependency.zip unzip 776-macro-build-dependency.zip cd 776-macro-build-dependency ./repro.shEnvironment used to validate these repros:
~/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2026-05-27-a.xctoolchainTOOLCHAINS=org.swift.64202605271aswift --version:Apple Swift version 6.5-dev (LLVM 8f81a64f6a8bcf6, Swift 4d0c97fa5b05711)DEVELOPMENT-SNAPSHOT-2026-05-27-a-wasm32-unknown-wasip1repro.shuses the explicit snapshot toolchain above, not the globalswiftonPATH.Observed on this environment:
--build-system native: passed (Build complete!) because the macro implementation stayed host-only--build-system swiftbuild: compiledReproMacrosImplfor the WASI side and hit#error("ReproMacrosImpl must not be compiled for the WASI target")kateinoigakukun commentedon Jun 23, 2026
Verified with the minimum reproducer from the issue gist on Linux using the requested June 12 snapshot.
/workspace/swiftpm-swiftbuild-issues/swb-jskit-776776-macro-build-dependency.zipcd /workspace/swiftpm-swiftbuild-issues/swb-jskit-776/776-macro-build-dependency && ./repro-linux-2026-06-12.sh 2>&1 | tee ../repro.log/home/ubuntu/.local/share/swiftly/toolchains/main-snapshot-2026-06-12/usr/bin/swiftSwift version 6.5-dev (LLVM 18d2bfb70c14d89, Swift c13d82e5987aecb)swift-DEVELOPMENT-SNAPSHOT-2026-06-12-a_wasmrepro.shtorepro-linux-2026-06-12.shand only replaced the macOS.xctoolchain/Info.plist/PlistBuddylookup with the requested Linux Swift binary plus the requested SDK ID. The package and native/swiftbuild build commands were left unchanged.Result:
--build-system native: exit0--build-system swiftbuild: exit1ReproMacrosImpl--3E7BE6D87A4DC5F2-testableerror: ReproMacrosImpl must not be compiled for the WASI target/workspace/swiftpm-swiftbuild-issues/swb-jskit-776/repro.log/workspace/swiftpm-swiftbuild-issues/swb-jskit-776/776-macro-build-dependency/native.log/workspace/swiftpm-swiftbuild-issues/swb-jskit-776/776-macro-build-dependency/swiftbuild.log/workspace/swiftpm-swiftbuild-issues/swb-jskit-776/adaptation-notes.mdConclusion: still reproducible with the original failure mode, so I am leaving this issue open.
kateinoigakukun commentedon Jun 23, 2026
swiftlang/swift-package-manager#10224