rules_swift
rules_swift copied to clipboard
Swift Macro Test - build issue - when it depends on the universal plugin
When swift_test depends on the universal plugin, build fails with the following error:
examples/xplatform/macros/StringifyMacroTests.swift:18:8: error: missing required module 'SwiftCompilerPlugin'
import StringifyMacroPlugin
^
examples/xplatform/macros/StringifyMacroTests.swift:18:8: error: missing required module 'SwiftCompilerPlugin'
import StringifyMacroPlugin
Repro
bazel test //examples/xplatform/macros:stringify_macro_test
swift_test(
name = "stringify_macro_test",
srcs = ["StringifyMacroTests.swift"],
deps = [
":stringify_macro_universal", // build is successful when it depends on the ":stringify_macro"
"@SwiftSyntax",
"@SwiftSyntax//:SwiftSyntaxBuilder",
"@SwiftSyntax//:SwiftSyntaxMacros",
],
)
We can fix this by adding "@SwiftSyntax//:SwiftCompilerPlugin", as one of the deps, but then we see the following errors:
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
ld: warning: duplicate -rpath '/usr/lib/swift' ignored
ld: warning: ignoring file 'bazel-out/darwin_x86_64-fastbuild-ST-6f7624269444/bin/external/SwiftSyntax/libSwiftSyntaxMacroExpansion.a[2](MacroExpansion.swift.o)': found architecture 'x86_64', required architecture 'arm64'
ld: warning: ignoring file 'bazel-out/darwin_x86_64-fastbuild-ST-6f7624269444/bin/external/SwiftSyntax/libSwiftCompilerPlugin.a[2](CompilerPlugin.swift.o)': found architecture 'x86_64', required architecture 'arm64'
ld: warning: ignoring file 'bazel-out/darwin_x86_64-fastbuild-ST-6f7624269444/bin/external/SwiftSyntax/libSwiftBasicFormat.a[5](BasicFormat+Extensions.swift.o)': found architecture 'x86_64', required architecture 'arm64'
ld: warning: ignoring file 'bazel-out/darwin_x86_64-fastbuild-ST-6f7624269444/bin/external/SwiftSyntax/libSwiftBasicFormat.a[4](Trivia+FormatExtensions.swift.o)': found architecture 'x86_64', required architecture 'arm64'
ld: warning: ignoring file 'bazel-out/darwin_x86_64-fastbuild-ST-6f7624269444/bin/external/SwiftSyntax/libSwiftBasicFormat.a[3](SyntaxProtocol+Formatted.swift.o)': found architecture 'x86_64', required architecture 'arm64'
ld: warning: ignoring file
The compilation on darwin_arm64, has an -Ipath pointing to x86_64 directory
-Ibazel-out/darwin_arm64-fastbuild/bin/external/SwiftSyntax \
-Ibazel-out/darwin_arm64-fastbuild/bin/examples/xplatform/macros \
-Ibazel-out/darwin_x86_64-fastbuild-ST-6f7624269444/bin/examples/xplatform/macros
Yea you should depend on the non-universal one for your test bundle. If you build a universal test bundle then you'll get the universal plugin for free as well.
I think the core issue here is that we're just propagating everything from the universal plugin impl https://github.com/bazelbuild/rules_swift/blob/61df2d5e9f549fa47bfe38fae7829408d16bafed/swift/swift_compiler_plugin.bzl#L287-L291 when what the swift_test expects is just the current arch it's building for. We could probably fix that with some custom logic here https://github.com/bazelbuild/rules_swift/blob/61df2d5e9f549fa47bfe38fae7829408d16bafed/swift/internal/swift_binary_test.bzl#L284-L292 but I would recommend just depending on the main plugin instead (maybe we should make swift_test depending on the universal plugin impossible).