rules_swift_package_manager icon indicating copy to clipboard operation
rules_swift_package_manager copied to clipboard

Support `embrace-io/embrace-apple-sdk`.

Open cgrindel opened this issue 1 year ago • 6 comments

Related Slack thread.

There are two issues:

  1. The EmbraceObjCUtilsInternal module has two module map files. The existing rules_swift_package_manager code treats this as an error. The fix is to warn the client and just use the first one that is found.
  2. The GRDB.swift package, a transitive dependency, defines a systemLibrary target. rules_swift_package_manager does not yet support these target types.

cgrindel avatar Oct 05 '24 15:10 cgrindel

@cgrindel what does it take to support packages with system library targets? Is the change complex?

adincebic avatar Oct 23 '24 11:10 adincebic

what does it take to support packages with system library targets? Is the change complex?

Probably not. I have not dug into it. I would look at how SPM builds targets linked to these libraries. There is a flag which tells SPM to output its build commands. Then, it is a matter of generating the appropriate targets here.

cgrindel avatar Oct 23 '24 12:10 cgrindel

Related to #248

luispadron avatar Oct 25 '24 15:10 luispadron

I'll have some time next weekend to attend this issue. Thank you both for references.

adincebic avatar Oct 25 '24 15:10 adincebic

SystemLibrary Support Draft PR: #1323

0xLucasMarcal avatar Nov 05 '24 04:11 0xLucasMarcal

~~Duplicate of #248~~, thanks for working on this @lucasmarcal-faire!

edit: ah I see theres two issues tied with this one

luispadron avatar Nov 12 '24 05:11 luispadron

@cgrindel @0xLucasMarcal @luispadron

There is a couple of developments here:

  • Support for system libraries is no longer needed for Embrace SDK as they dropped GRDB.
  • Embrace also no longer have multiple modulemap files.

However there is three outstanding issues:

  • Embrace depends on KSCrash which requires this PR to be merged.
  • After that PR is merged we still need to make sure that cc_library has .def files in textual_hdrs attribute since that's what KSCrash uses.
  • After all of that I am still getting linker errors which I have to investigate:
ERROR: /Users/adincebic/developer.noindex/rules_swift_package_manager/examples/resources_example/Sources/MyApp/BUILD.bazel:24:16: Linking Sources/MyApp/iosapp_bin failed: (Exit 1): wrapped_clang failed: error executing ObjcLink command (from target //Sources/MyApp:iosapp) 
  (cd /private/var/tmp/_bazel_adincebic/7df9a3a4170e6b4114a0416989fc307a/sandbox/darwin-sandbox/1075/execroot/_main && \
  exec env - \
    APPLE_SDK_PLATFORM=iPhoneSimulator \
    APPLE_SDK_VERSION_OVERRIDE=18.2 \
    PATH=/bin:/usr/bin:/usr/local/bin \
    RELATIVE_AST_PATH=true \
    XCODE_VERSION_OVERRIDE=16.2.0.16C5032a \
  bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/apple_support+/crosstool/wrapped_clang @bazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-2491983d010b/bin/Sources/MyApp/iosapp_bin-0.params)
# Configuration: ec9ede77efefff9175db7a929757579fb0cb2f9c6f3d87cdefab3a0f7beaa70b
# Execution platform: @@platforms//host:host

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
ld: warning: Could not parse or use implicit file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore.tbd': cannot link directly with 'SwiftUICore' because product being built is not an allowed client of it
Undefined symbols for architecture arm64:
  "_deflate", referenced from:
      +[KSGZipHelper gzippedData:compressionLevel:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
  "_deflateEnd", referenced from:
      +[KSGZipHelper gzippedData:compressionLevel:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
      +[KSGZipHelper gzippedData:compressionLevel:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
  "_deflateInit2_", referenced from:
      +[KSGZipHelper gzippedData:compressionLevel:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
  "_inflate", referenced from:
      +[KSGZipHelper gunzippedData:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
  "_inflateEnd", referenced from:
      +[KSGZipHelper gunzippedData:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
      +[KSGZipHelper gunzippedData:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
  "_inflateInit2_", referenced from:
      +[KSGZipHelper gunzippedData:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error in child process '/usr/bin/xcrun'. 1

I have isolated repro for the KSCrash https://github.com/adincebic/rules_swift_package_manager/tree/adin/repro-linker-errors-with-KSCrash

NOTE: I based my repro on branch from this PR

Thanks @jflan-dd

adincebic avatar May 04 '25 10:05 adincebic

That linker error looks like zlib symbols are missing -- adding sdk_dylibs = ["z"] to a target would probably fix that.

I tried to reproduce it, but I'm actually able to successfully build bazel build //Sources/MyApp:iosapp on your branch. 🤔

jschear avatar May 05 '25 03:05 jschear

That linker error looks like zlib symbols are missing -- adding sdk_dylibs = ["zlib"] to a target would probably fix that.

I added -lz to linkopts and it fixed it. However the bigger issue is detecting when to link against these kinds of libraries.

I tried to reproduce it, but I'm actually able to successfully build bazel build //Sources/MyApp:iosapp on your branch. 🤔

That's weird because you should have first ran into the missing .def files error:

ERROR: /private/var/tmp/_bazel_adincebic/7df9a3a4170e6b4114a0416989fc307a/external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/BUILD.bazel:96:11: Compiling Sources/KSCrashDemangleFilter/swift/Basic/ManglingUtils.cpp failed: (Exit 1): wrapped_clang_pp failed: error executing CppCompile command (from target @@rules_swift_package_manager++swift_deps+swiftpkg_kscrash//:KSCrashDemangleFilter.rspm_cxx) 
  (cd /private/var/tmp/_bazel_adincebic/7df9a3a4170e6b4114a0416989fc307a/sandbox/darwin-sandbox/438/execroot/_main && \
  exec env - \
    APPLE_SDK_PLATFORM=iPhoneSimulator \
    APPLE_SDK_VERSION_OVERRIDE=18.2 \
    PATH=/bin:/usr/bin:/usr/local/bin \
    XCODE_VERSION_OVERRIDE=16.2.0.16C5032a \
  bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/apple_support+/crosstool/wrapped_clang_pp '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -fno-omit-frame-pointer -O0 -DDEBUG '-std=c++17' '-fdebug-prefix-map=__BAZEL_EXECUTION_ROOT__=.' '-fdebug-prefix-map=__BAZEL_XCODE_DEVELOPER_DIR__=/PLACEHOLDER_DEVELOPER_DIR' -iquote external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash -iquote bazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-2491983d010b/bin/external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash -Ibazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-2491983d010b/bin/external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/KSCrashRecording.rspm_modulemap_modulemap/_ -Ibazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-2491983d010b/bin/external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/KSCrashRecordingCore.rspm_modulemap_modulemap/_ -Ibazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-2491983d010b/bin/external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/KSCrashCore.rspm_modulemap_modulemap/_ -Iexternal/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashCore/include -Ibazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-2491983d010b/bin/external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashCore/include -Iexternal/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashRecordingCore/include -Ibazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-2491983d010b/bin/external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashRecordingCore/include -Iexternal/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashRecording/include -Ibazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-2491983d010b/bin/external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashRecording/include -isystem external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashDemangleFilter/include -isystem bazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-2491983d010b/bin/external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashDemangleFilter/include -isystem external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashRecording/include -isystem bazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-2491983d010b/bin/external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashRecording/include -isystem external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashRecordingCore/include -isystem bazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-2491983d010b/bin/external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashRecordingCore/include -MD -MF bazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-2491983d010b/bin/external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/_objs/KSCrashDemangleFilter.rspm_cxx/ManglingUtils.d '-frandom-seed=bazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-2491983d010b/bin/external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/_objs/KSCrashDemangleFilter.rspm_cxx/ManglingUtils.o' -isysroot __BAZEL_XCODE_SDKROOT__ -F__BAZEL_XCODE_SDKROOT__/System/Library/Frameworks -F__BAZEL_XCODE_DEVELOPER_DIR__/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks -no-canonical-prefixes -pthread -fblocks -fobjc-arc -fPIC '-DSWIFT_PACKAGE=1' '-fmodule-name=KSCrashDemangleFilter' -Iexternal/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashDemangleFilter -Iexternal/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashDemangleFilter/swift -Iexternal/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashDemangleFilter/swift/Basic -Iexternal/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashDemangleFilter/llvm -Iexternal/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashDemangleFilter/llvm/ADT -Iexternal/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashDemangleFilter/llvm/Config -Iexternal/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashDemangleFilter/llvm/Support '-std=gnu++11' -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -target arm64-apple-ios16.0-simulator -c external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashDemangleFilter/swift/Basic/ManglingUtils.cpp -o bazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-2491983d010b/bin/external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/_objs/KSCrashDemangleFilter.rspm_cxx/ManglingUtils.o)
# Configuration: ec9ede77efefff9175db7a929757579fb0cb2f9c6f3d87cdefab3a0f7beaa70b
# Execution platform: @@platforms//host:host

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
external/rules_swift_package_manager++swift_deps+swiftpkg_kscrash/Sources/KSCrashDemangleFilter/swift/Basic/ManglingUtils.cpp:75:10: fatal error: 'StandardTypesMangling.def' file not found
   75 | #include "StandardTypesMangling.def"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Error in child process '/usr/bin/xcrun'. 1
Target //Sources/MyApp:iosapp failed to build
```


This error goes away after I apply changes like in [this PR ](https://github.com/cgrindel/rules_swift_package_manager/pull/1600)

I am building with bazel 8.2.1 and running macOS 15.3.1.

adincebic avatar May 05 '25 05:05 adincebic

The Package.swift should be using .linkedLibrary("z") to specify this. Not sure why it works without it in normal SPM.

brentleyjones avatar May 06 '25 17:05 brentleyjones

@cgrindel @0xLucasMarcal @luispadron

There is a couple of developments here:

  • Support for system libraries is no longer needed for Embrace SDK as they dropped GRDB.
  • Embrace also no longer have multiple modulemap files.

However there is three outstanding issues:

  • Embrace depends on KSCrash which requires this PR to be merged.
  • After that PR is merged we still need to make sure that cc_library has .def files in textual_hdrs attribute since that's what KSCrash uses.
  • After all of that I am still getting linker errors which I have to investigate:
ERROR: /Users/adincebic/developer.noindex/rules_swift_package_manager/examples/resources_example/Sources/MyApp/BUILD.bazel:24:16: Linking Sources/MyApp/iosapp_bin failed: (Exit 1): wrapped_clang failed: error executing ObjcLink command (from target //Sources/MyApp:iosapp) 
  (cd /private/var/tmp/_bazel_adincebic/7df9a3a4170e6b4114a0416989fc307a/sandbox/darwin-sandbox/1075/execroot/_main && \
  exec env - \
    APPLE_SDK_PLATFORM=iPhoneSimulator \
    APPLE_SDK_VERSION_OVERRIDE=18.2 \
    PATH=/bin:/usr/bin:/usr/local/bin \
    RELATIVE_AST_PATH=true \
    XCODE_VERSION_OVERRIDE=16.2.0.16C5032a \
  bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/apple_support+/crosstool/wrapped_clang @bazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min16.0-applebin_ios-ST-2491983d010b/bin/Sources/MyApp/iosapp_bin-0.params)
# Configuration: ec9ede77efefff9175db7a929757579fb0cb2f9c6f3d87cdefab3a0f7beaa70b
# Execution platform: @@platforms//host:host

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
ld: warning: Could not parse or use implicit file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore.tbd': cannot link directly with 'SwiftUICore' because product being built is not an allowed client of it
Undefined symbols for architecture arm64:
  "_deflate", referenced from:
      +[KSGZipHelper gzippedData:compressionLevel:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
  "_deflateEnd", referenced from:
      +[KSGZipHelper gzippedData:compressionLevel:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
      +[KSGZipHelper gzippedData:compressionLevel:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
  "_deflateInit2_", referenced from:
      +[KSGZipHelper gzippedData:compressionLevel:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
  "_inflate", referenced from:
      +[KSGZipHelper gunzippedData:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
  "_inflateEnd", referenced from:
      +[KSGZipHelper gunzippedData:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
      +[KSGZipHelper gunzippedData:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
  "_inflateInit2_", referenced from:
      +[KSGZipHelper gunzippedData:error:] in libKSCrashReportingCore.rspm_objc.lo[3](KSGZipHelper.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error in child process '/usr/bin/xcrun'. 1

I have isolated repro for the KSCrash https://github.com/adincebic/rules_swift_package_manager/tree/adin/repro-linker-errors-with-KSCrash

NOTE: I based my repro on branch from this PR

Thanks @jflan-dd

Yeah, I fixed the two modulemaps on their repo

0xLucasMarcal avatar May 07 '25 13:05 0xLucasMarcal

FYI. #1594 is merged.

cgrindel avatar May 07 '25 15:05 cgrindel

@cgrindel do you mind taking a look at https://github.com/cgrindel/rules_swift_package_manager/pull/1600 since it is also required for Embrace SDK.

adincebic avatar May 07 '25 16:05 adincebic

@cgrindel this is completed and can be closed.

adincebic avatar Jun 30 '25 11:06 adincebic