Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Themis a static framework #731

Merged
merged 2 commits into from
Oct 27, 2020

Conversation

ilammy
Copy link
Collaborator

@ilammy ilammy commented Oct 27, 2020

Tell CocoaPods to build ObjCThemis as a 'static framework'. That is, your usual framework bundle but with a static library inside, not a dynamic one as you would have normally use.

Using static linkage greatly simplifies our life on iOS platforms which tend to be very picky about dynamic linkage and loading of frameworks. These issues are not really visible until you archive the app for distribution, actually install it on the device, and try launching it. Debugging these issues takes enormous amount amount of time which we don't have. Let Apple engineers fiddle with dynamic linkage for system frameworks. That at least makes sense.

Using static linkage for Themis has advantages, such as improved startup time (no extra symbol resolution) and improved app size (unused parts of Themis and its dependencies could be cut out by the linker). As Themis is distributed under a permissive license, there are no legal downsides of including it as an integral part of an application, it does not have to be a completely separate binary.

On the other hand, there are not many advantages of dynamic linkage. We don't get to share the memory and storage as Themis is not a system framework. The only real advantage is that it's easier to verify that Themis binaries have not been tampered with and to check Themis version, but iOS deployment process is know to heavily process the binaries, making this point mostly moot.

Checklist

  • Change is covered by automated tests
  • The coding guidelines are followed
  • Changelog is updated

Required reviews:

First of all, to get this thing out of sight, remove all trailing
whitespace that got recently added to the file.
Tell CocoaPods to build ObjCThemis as a 'static framework'. That is,
your usual framework bundle but with a static library inside, not a
dynamic one as you would have normally use.

Using static linkage greatly simplifies our life on iOS platforms which
tend to be very picky about dynamic linkage and loading of frameworks.
These issues are not really visible until you archive the app for
distribution, actually install it on the device, and try launching it.
Debugging these issues takes enormous amount amount of time which we
don't have. Let Apple engineers fiddle with dynamic linkage for system
frameworks. That at least makes sense.

Using static linkage for Themis has advantages, such as improved startup
time (no extra symbol resolution) and improved app size (unused parts of
Themis and its dependencies could be cut out by the linker). As Themis
is distributed under a permissive license, there are no legal downsides
of including it as an integral part of an application, it does not have
to be a completely separate binary.

On the other hand, there are not many advantages of dynamic linkage.
We don't get to share the memory and storage as Themis is not a system
framework. The only real advantage is that it's easier to verify that
Themis binaries have not been tampered with and to check Themis version,
but iOS deployment process is know to heavily process the binaries,
making this point mostly moot.
@ilammy ilammy added O-iOS 📱 Operating system: iOS O-macOS 💻 Operating system: macOS W-SwiftThemis 🔶 Wrapper: SwiftThemis, Swift API W-ObjCThemis 🎨 Wrapper: ObjCThemis, Objective-C API M-CocoaPods Package manager: CocoaPods, Objective-C and Swift, iOS and macOS labels Oct 27, 2020
@Lagovas
Copy link
Collaborator

Lagovas commented Oct 27, 2020

improved startup time (no extra symbol resolution)

wow, interesting. didn't know about that. did you read about it or measured it somehow?

@ilammy
Copy link
Collaborator Author

ilammy commented Oct 27, 2020

@Lagovas,

wow, interesting. didn't know about that. did you read about it or measured it somehow?

I don't have iOS devices so I cannot measure it properly. It's a pretty marginal gain in our case, at best, but it's a common suggestion to avoid having lots of dynamic frameworks.

The speedup here is gained by skipping all the dynamic linking and loading time. If dynamic frameworks are used, the app has to locate, verify, load Themis, resolve symbols used by the app, then move on to locating, verifying, loading, and resolving OpenSSL symbols. If static frameworks are used them everything has been pre-linked into the application and does not affect loading time much.

@ilammy ilammy merged commit 3f858f4 into cossacklabs:master Oct 27, 2020
@ilammy ilammy deleted the cocoapods/static-framework branch October 27, 2020 12:44
@vixentael
Copy link
Contributor

then move on to locating, verifying, loading, and resolving OpenSSL symbols.

.. and crash because rpath is wrong :D

ilammy added a commit to ilammy/themis that referenced this pull request Oct 28, 2020
* Clean up whitespace

First of all, to get this thing out of sight, remove all trailing
whitespace that got recently added to the file.

* Make Themis a static framework

Tell CocoaPods to build ObjCThemis as a 'static framework'. That is,
your usual framework bundle but with a static library inside, not a
dynamic one as you would have normally use.

Using static linkage greatly simplifies our life on iOS platforms which
tend to be very picky about dynamic linkage and loading of frameworks.
These issues are not really visible until you archive the app for
distribution, actually install it on the device, and try launching it.
Debugging these issues takes enormous amount amount of time which we
don't have. Let Apple engineers fiddle with dynamic linkage for system
frameworks. That at least makes sense.

Using static linkage for Themis has advantages, such as improved startup
time (no extra symbol resolution) and improved app size (unused parts of
Themis and its dependencies could be cut out by the linker). As Themis
is distributed under a permissive license, there are no legal downsides
of including it as an integral part of an application, it does not have
to be a completely separate binary.

On the other hand, there are not many advantages of dynamic linkage.
We don't get to share the memory and storage as Themis is not a system
framework. The only real advantage is that it's easier to verify that
Themis binaries have not been tampered with and to check Themis version,
but iOS deployment process is know to heavily process the binaries,
making this point mostly moot.

(cherry picked from commit 3f858f4)

Signed-off-by: Alexei Lozovsky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M-CocoaPods Package manager: CocoaPods, Objective-C and Swift, iOS and macOS O-iOS 📱 Operating system: iOS O-macOS 💻 Operating system: macOS W-ObjCThemis 🎨 Wrapper: ObjCThemis, Objective-C API W-SwiftThemis 🔶 Wrapper: SwiftThemis, Swift API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants