rules_swift icon indicating copy to clipboard operation
rules_swift copied to clipboard

On Xcode 15, binaries depending on swift_proto_library fail to link with error: duplicate -rpath '/usr/lib/swift'

Open AttilaTheFun opened this issue 2 years ago • 6 comments
trafficstars

You can reproduce this for yourself in the master branch of rules_swift with an Xcode 15 toolchain on macOS Sonoma.

Just build the GRPC echo_server example:

logan@Logans-MacBook-Pro rules_swift % bazel build //examples/xplatform/grpc:echo_server
INFO: Analyzed target //examples/xplatform/grpc:echo_server (11 packages loaded, 1208 targets configured).
INFO: Found 1 target...
ERROR: /Users/logan/Developer/Bazel/rules_swift/examples/xplatform/grpc/BUILD:58:13: Linking examples/xplatform/grpc/echo_server failed: (Exit 1): cc_wrapper.sh failed: error executing command (from target //examples/xplatform/grpc:echo_server) external/local_config_apple_cc/cc_wrapper.sh @bazel-out/darwin_arm64-fastbuild/bin/examples/xplatform/grpc/echo_server-2.params

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: fatal warning(s) induced error (-fatal_warnings)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error in child process '/usr/bin/xcrun'. 1
Target //examples/xplatform/grpc:echo_server failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 2.201s, Critical Path: 2.01s
INFO: 5 processes: 3 internal, 1 darwin-sand

AttilaTheFun avatar Nov 12 '23 19:11 AttilaTheFun

Just wanted to call out that the example has -fatal_warnings. If you didn't have this it's just a warning, not a failure.

brentleyjones avatar Nov 12 '23 21:11 brentleyjones

https://github.com/bazelbuild/apple_support/pull/286

keith avatar Nov 13 '23 18:11 keith

To add some more context. The warning for me shows only when building test targets:

  • No warning: bazelisk build --config=public-ios //SharedModules/QRCodeKit:QRCodeKit
  • With warning: bazelisk build --config=public-ios //SharedModules/QRCodeKit:QRCodeKitUnitTests

The -no_warn_duplicate_libraries flag does not help here (probably you knew this already :D but online seems like the rpath and the library duplications are mixed, and so are their workarounds - so just clarifying)

The rpath shows twice despite the amount of dependencies. Attached below couple of examples.

Building test target with 2 dependencies: Screenshot 2024-05-03 at 01 13 45

Building test target with more than 2 dependencies: Screenshot 2024-05-03 at 01 30 50

acecilia avatar May 03 '24 00:05 acecilia

Looking at the flags pattern:

-L__BAZEL_XCODE_DEVELOPER_DIR__/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator
-L/usr/lib/swift
-Wl,-objc_abi_version,2
-Wl,-rpath,/usr/lib/swift

Maybe origin is here 🤔

acecilia avatar May 03 '24 01:05 acecilia

@acecilia just curious, do you still see this issue with the new swift proto library implementation?

AttilaTheFun avatar May 03 '24 01:05 AttilaTheFun

Mmm my comment was more generic, just about building targets. I do not have knowledge about protos 😞

Maybe my comment is out of context in this protos-specific issue 🤔

acecilia avatar May 03 '24 17:05 acecilia