rules_swift
rules_swift copied to clipboard
swift_proto_compile fails to build ProtoCompilerPlugin on Linux
Apologies if this is the wrong place to ask this or if it's very obviously user error. I'm finding that I can't get the swift_proto_compile rule to work on Linux due to linking issues when the ProtoCompilerPlugin is being built. I found a very similar issue mentioned here and tried their solution of switching to clang-12, but no luck, as you can see below.
I'm using rules_swift 1.0, bazel 5.20 and swift 5.6.2 and running bazel build --host_swiftcopt=-wmo --swiftcopt=-wmo //... --sandbox_debug --verbose_failures (the -wmo being to bypass the partial_swiftmodule errors).
I notice there's a patch applied when rules_proto is brought in, so I think my next step will be making sure my WORKSPACE is ordered so that I actually get that patch.
[615 / 625] Compiling Swift module @com_github_apple_swift_protobuf//:SwiftProtobuf; 23s remote-cache, worker ... (4 actions running)
[619 / 625] [Prepa] Extracting autolink data for Swift module @com_github_apple_swift_protobuf//:SwiftProtobufPluginLibrary ... (2 actions, 0 running)
warning: '-Xuse-experimental' is deprecated and will be removed in a future release
ERROR: /home/circleci/.cache/bazel/_bazel_circleci/f16e36219ef33c22efc2ad20f3e3775c/external/com_github_apple_swift_protobuf/BUILD.bazel:30:13: Linking external/com_github_apple_swift_protobuf/ProtoCompilerPlugin failed: (Exit 1): process-wrapper failed: error executing command
(cd /home/circleci/.cache/bazel/_bazel_circleci/f16e36219ef33c22efc2ad20f3e3775c/sandbox/processwrapper-sandbox/528/execroot/__main__ && \
exec env - \
PATH=/home/circleci/.cache/bazelisk/downloads/bazelbuild/bazel-5.2.0-linux-x86_64/bin:/home/circleci/.local/bin:/home/circleci/.local/bin/swift-5.6.2-RELEASE-ubuntu20.04/usr/bin:/opt/sbt/bin:/opt/gradle/bin:/opt/apache-maven/bin:/home/circleci/bin:/home/circleci/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
PWD=/proc/self/cwd \
TMPDIR=/tmp \
/home/circleci/.cache/bazel/_bazel_circleci/install/41b71f1bb3ce13f20cfeeb31a9357113/process-wrapper '--timeout=0' '--kill_delay=15' /usr/lib/llvm-12/bin/clang @bazel-out/k8-opt-exec-2B5CBBC6/bin/external/com_github_apple_swift_protobuf/SwiftProtobuf.autolink @bazel-out/k8-opt-exec-2B5CBBC6/bin/external/com_github_apple_swift_protobuf/SwiftProtobufPluginLibrary.autolink @bazel-out/k8-opt-exec-2B5CBBC6/bin/external/com_github_apple_swift_protobuf/ProtoCompilerPlugin.autolink @bazel-out/k8-opt-exec-2B5CBBC6/bin/external/com_github_apple_swift_protobuf/ProtoCompilerPlugin-2.params)
ld.lld: error: undefined hidden symbol: __start_swift5_protocols
>>> referenced by SwiftRT-ELF.cpp
>>> /home/circleci/.local/bin/swift-5.6.2-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
ld.lld: error: undefined hidden symbol: __stop_swift5_protocols
>>> referenced by SwiftRT-ELF.cpp
>>> /home/circleci/.local/bin/swift-5.6.2-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
ld.lld: error: undefined hidden symbol: __start_swift5_protocol_conformances
>>> referenced by SwiftRT-ELF.cpp
>>> /home/circleci/.local/bin/swift-5.6.2-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
ld.lld: error: undefined hidden symbol: __stop_swift5_protocol_conformances
>>> referenced by SwiftRT-ELF.cpp
>>> /home/circleci/.local/bin/swift-5.6.2-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
ld.lld: error: undefined hidden symbol: __start_swift5_type_metadata
>>> referenced by SwiftRT-ELF.cpp
>>> /home/circleci/.local/bin/swift-5.6.2-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
ld.lld: error: undefined hidden symbol: __stop_swift5_type_metadata
>>> referenced by SwiftRT-ELF.cpp
>>> /home/circleci/.local/bin/swift-5.6.2-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
ld.lld: error: undefined hidden symbol: __start_swift5_assocty
>>> referenced by SwiftRT-ELF.cpp
>>> /home/circleci/.local/bin/swift-5.6.2-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
ld.lld: error: undefined hidden symbol: __stop_swift5_assocty
>>> referenced by SwiftRT-ELF.cpp
>>> /home/circleci/.local/bin/swift-5.6.2-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
ld.lld: error: undefined hidden symbol: __start_swift5_replace
>>> referenced by SwiftRT-ELF.cpp
>>> /home/circleci/.local/bin/swift-5.6.2-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
ld.lld: error: undefined hidden symbol: __stop_swift5_replace
>>> referenced by SwiftRT-ELF.cpp
>>> /home/circleci/.local/bin/swift-5.6.2-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
ld.lld: error: undefined hidden symbol: __start_swift5_replac2
>>> referenced by SwiftRT-ELF.cpp
>>> /home/circleci/.local/bin/swift-5.6.2-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
ld.lld: error: undefined hidden symbol: __stop_swift5_replac2
>>> referenced by SwiftRT-ELF.cpp
>>> /home/circleci/.local/bin/swift-5.6.2-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
ld.lld: error: undefined hidden symbol: __start_swift5_builtin
>>> referenced by SwiftRT-ELF.cpp
>>> /home/circleci/.local/bin/swift-5.6.2-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
ld.lld: error: undefined hidden symbol: __stop_swift5_builtin
>>> referenced by SwiftRT-ELF.cpp
>>> /home/circleci/.local/bin/swift-5.6.2-RELEASE-ubuntu20.04/usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Moving the swift_rules_dependencies() and swift_rules_extra_dependencies() calls up in WORKSPACE did not help.
Thanks for filing this! I haven't had cycles to try and track this down. I'm tempted to try and see if clang-14 makes a difference.
I'm also tempted to bring my own LLVM toolchain and am wondering what the interaction might be there.
I can report the issue persists with rules_swift 1.5.1 and Swift 5.7.3.
It looks like https://github.com/apple/swift/issues/60406 might be pointing to the root cause.
Closing as https://github.com/bazelbuild/rules_swift/issues/882 contains the solution: passing --host_linkopt=-z --host_linkopt=nostart-stop-gc
HEAD will start adding this automatically too https://github.com/bazelbuild/rules_swift/commit/a3e479e51b5fe2fb48147ac463a75f4774c61a6b