Skip to content

Build iOS Rust code as an XCFramework.#4396

Merged
skhamis merged 2 commits intomainfrom
ios-rust-xcframework
Aug 20, 2021
Merged

Build iOS Rust code as an XCFramework.#4396
skhamis merged 2 commits intomainfrom
ios-rust-xcframework

Conversation

@skhamis
Copy link
Copy Markdown
Contributor

@skhamis skhamis commented Aug 20, 2021

Continuation of #4225 -- but this time merging into main.

This is an attempt to make our iOS build process more compatible with
M1 Mac build environments, and easier to consume via Swift Packages.

In our existing iOS build setup, we compile together all of the Rust
code and all of the wrapping Swift code into a single module named
"MozillaAppServices". This is a bit of a violation of clean package
separation, because it means that we risk name conflicts in the Swift
code between different components.

In this new setup, we don't pre-compile any of the Swift code. Instead
we build only the Rust code, package it up along with its associated headers,
and tell Swift to treat this as a module named "MozillaRustComponents".
Each individual Swift wrapper can then import MozillaRustComponents
and get access to the low-level FFI functions that it needs.

An additional benefit of this setup is that we can distribute it as
a .xcframework bundle for easy consumption on different platforms,
and we can build it without using Xcode.

Pull Request checklist

  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGES_UNRELEASED.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due dilligence applied in selecting them.

This is an attempt to make our iOS build process more compatible with
M1 Mac build environments, and easier to consume via Swift Packages.

In our existing iOS build setup, we compile together all of the Rust
code and all of the wrapping Swift code into a single module named
"MozillaAppServices". This is a bit of a violation of clean package
separation, because it means that we risk name conflicts in the Swift
code between different components.

In this new setup, we don't pre-compile any of the Swift code. Instead
we build only the Rust code, package it up along with its associated headers,
and tell Swift to treat this as a module named "MozillaRustComponents".
Each individual Swift wrapper can then `import MozillaRustComponents`
and get access to the low-level FFI functions that it needs.

An additional benefit of this setup is that we can distribute it as
a `.xcframework` bundle for easy consumption on different platforms,
and we can build it without using Xcode.
@skhamis skhamis requested a review from a team August 20, 2021 02:48
Copy link
Copy Markdown
Contributor

@tarikeshaq tarikeshaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

It builds and works! (we'll follow up with a PR on the https://github.com/mozilla/rust-components-swift side to track a version of A-S with those changes - which we had to do to get this to build successfully)

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

Merging #4396 (5d008fe) into main (6c839a3) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4396   +/-   ##
=======================================
  Coverage   76.00%   76.00%           
=======================================
  Files          46       46           
  Lines        4193     4193           
=======================================
  Hits         3187     3187           
  Misses       1006     1006           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6c839a3...5d008fe. Read the comment docs.

@skhamis skhamis merged commit e1abe5a into main Aug 20, 2021
@skhamis skhamis deleted the ios-rust-xcframework branch August 20, 2021 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants