rules_swift_package_manager
rules_swift_package_manager copied to clipboard
Support `embrace-io/embrace-apple-sdk`.
Related Slack thread.
There are two issues:
- The EmbraceObjCUtilsInternal module has two module map files. The existing
rules_swift_package_managercode treats this as an error. The fix is to warn the client and just use the first one that is found. - The GRDB.swift package, a transitive dependency, defines a
systemLibrarytarget.rules_swift_package_managerdoes not yet support these target types.
@cgrindel what does it take to support packages with system library targets? Is the change complex?
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.
Related to #248
I'll have some time next weekend to attend this issue. Thank you both for references.
SystemLibrary Support Draft PR: #1323
~~Duplicate of #248~~, thanks for working on this @lucasmarcal-faire!
edit: ah I see theres two issues tied with this one
@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_libraryhas.deffiles intextual_hdrsattribute 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
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. 🤔
That linker error looks like
zlibsymbols are missing -- addingsdk_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:iosappon 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.
The Package.swift should be using .linkedLibrary("z") to specify this. Not sure why it works without it in normal SPM.
@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_libraryhas.deffiles intextual_hdrsattribute 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'. 1I 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
FYI. #1594 is merged.
@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.
@cgrindel this is completed and can be closed.