sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

Support for Sentry as a static lib

Open marandaneto opened this issue 4 years ago • 15 comments
trafficstars

People that have Apps that require Sentry to be a static lib need to update the Xcode project file and compile it on every SDK update, making it harder to Bump the SDK often.

Can we make it possible thru a configuration so it's a bit less painful than now?

I know we used to have Sentry as a static lib but I don't remember why we've changed it, the output of this issue could be just explaining the trade-off and why we've decided to drop it.

marandaneto avatar Apr 21 '21 08:04 marandaneto

This would be really amazing, I'd love to have a cmake or command line thing I can run that would make the xcode project static. I'd just never figured out what these are without manually opening xcode and changing the properties.

Projects like unreal engine really struggle with xcode frameworks and prefer static linked libs.

deathlyrage avatar Apr 22 '21 00:04 deathlyrage

@marandaneto I am looking into integrating iOS SDK but we don't support any of the installation method described here https://docs.sentry.io/platforms/apple/guides/ios/install/ . It would certainly be helpful if we can get a static lib (.a) that I can just link against.

tiwariashish86 avatar May 05 '21 18:05 tiwariashish86

@marandaneto I am looking into integrating iOS SDK but we don't support any of the installation method described here https://docs.sentry.io/platforms/apple/guides/ios/install/ . It would certainly be helpful if we can get a static lib (.a) that I can just link against.

Curious if building from source is an option to you? At least until we add a static lib as a release target.

bruno-garcia avatar May 05 '21 20:05 bruno-garcia

Sure 2 questions : 1. How do I build from source? 2. I would like to build based on last stable release. Can you please point me to commit which was the base for last sentry stable release for iOS?

tiwariashish86 avatar May 05 '21 22:05 tiwariashish86

Sure 2 questions : 1. How do I build from source? 2. I would like to build based on last stable release. Can you please point me to commit which was the base for last sentry stable release for iOS?

You can see our build configuration here: https://github.com/getsentry/sentry-cocoa/blob/741aa6d130e7637b67bf7a6f2ec22a7c8c5511d2/.github/workflows/buildandtest.yml#L39-L46

I suggest pulling the repo at a specific tag (a release we cut) which will help keeping track of what features and bugfixes you've included. It'll help troubleshooting in case you report an error and call out the SDK version (which is kept in sync with the tagged releases).

Latest release is: https://github.com/getsentry/sentry-cocoa/releases/tag/7.0.3

bruno-garcia avatar May 05 '21 23:05 bruno-garcia

Checking build configuration. what is the output of building the repo this way(does it output .a or iOS framework that we can include in our project?)? or are you suggesting building along with our source code(that we do not want to do)?

tiwariashish86 avatar May 06 '21 06:05 tiwariashish86

Also, is there an ETA when we would have static lib support?

tiwariashish86 avatar May 06 '21 16:05 tiwariashish86

We currently build a framework. So this issue can stay open until we add static lib support. My suggestion was that you could try to build a static lib by yourselves, until we ship the feature.

There's no ETA for this feature at this point.

bruno-garcia avatar May 07 '21 20:05 bruno-garcia

We need this for Unity too.

bruno-garcia avatar May 12 '21 14:05 bruno-garcia

Haven't tested this yet, but it seems like one could just duplicate the Sentry target in Sentry.xcodeproj and then set productType to com.apple.product-type.library.static in the .pbxproj? I imagine the less hacky version would use a variable for keeping the sources & headers consistent rather than duplicating

https://github.com/Jarred-Sumner/sentry-cocoa-static/releases/tag/7.7.0

Jarred-Sumner avatar Jan 03 '22 12:01 Jarred-Sumner

@bruno-garcia and @bitsandfoxes, I think you both mentioned we would need this for Unity, and this issue could block you. Is this true?

philipphofmann avatar Jan 18 '22 13:01 philipphofmann

We made it work without the need for a static lib.

bitsandfoxes avatar Jan 18 '22 15:01 bitsandfoxes

I have created a CMake project that makes it possible to build as a static library. If there is interest in this I can make that available.

m-kuhn avatar Aug 07 '22 07:08 m-kuhn

@m-kuhn, yes, please share it with us. That would be lovely.

philipphofmann avatar Aug 30 '22 07:08 philipphofmann

Here you go:

https://github.com/opengisch/QField/tree/master/vcpkg/overlay/sentry-cocoa

It's written for building in vcpkg, but the CMakeFile.txt in there can be separated with minimal changes. Ideally it could even be moved to this repository here. One thing that needs mentioning is the following line https://github.com/opengisch/QField/blob/11b69f9256309bc2c3866c20989d7d935090b66e/vcpkg/overlay/sentry-cocoa/SentryCocoaConfig.cmake.in#L17

The linker needs an extra hint to include all symbols, as some classes get loaded dynamically on runtime and therefore the linker doesn't know that these need to be included at link time.

m-kuhn avatar Aug 30 '22 08:08 m-kuhn

When using SPM or CocoaPods you can use Sentry as a static lib. I'm closing this.

philipphofmann avatar Feb 28 '24 14:02 philipphofmann

@philipphofmann do you have links to how it is solved there? I'm wondering if the approach above is "best practice" or if there are alternative/better ways. Thanks.

m-kuhn avatar Feb 28 '24 15:02 m-kuhn

This should work for CocoaPods

use_frameworks! :linkage => :static

target 'YourApp' do
  pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '8.20.0'
end

For SPM, the default is static, if I'm not mistaken, @brustolin?

philipphofmann avatar Feb 29 '24 13:02 philipphofmann

I wonder mostly how they build with it statically, if it's also using LINKER:-force_load,${_IMPORT_PREFIX}/lib/libsentry_cocoa.a as in https://github.com/getsentry/sentry-cocoa/issues/1062#issuecomment-1231305956 or if there's a different approach.

m-kuhn avatar Feb 29 '24 13:02 m-kuhn

For SPM, the default is static, if I'm not mistaken, @brustolin?

Yes. That's my understanding too. If you add sentry to your project with SPM, when its get symbolicated, its appear as code from your own binary, that indicates it was linked as a static lib.

If Im not mistaken cocoapod without the use_framework is also static by default.

brustolin avatar Feb 29 '24 14:02 brustolin