Swiftpack.co - mozilla/rust-components-swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by mozilla.
mozilla/rust-components-swift 90.0.0
Swift Package for distributing Mozilla's Rust-based application components
⭐️ 6
🕓 Yesterday
.package(url: "https://github.com/mozilla/rust-components-swift.git", from: "90.0.0")

Swift Package for Mozilla's Rust Components

This repository is a Swift Package for distributing releases of Mozilla's various Rust-based application components. It provides the Swift source code packaged in a format understood by the Swift package manager, and depends on a pre-compiled binary release of the underlying Rust code published from [mozilla/application-services](https://raw.github.com/mozilla/rust-components-swift/main/ https://github.com/mozilla/application-service).

For more information, please consult:

  • application-services ADR-0003, which describes the overall plan for distributing Rust-based components as Swift packages.
  • The Swift Package Manager docs and GitHub repo, which explain the details of how Swift Packages work (and hence why this repo is set up the way it is).
  • The ios-rust crate which is currently responsible for publishing the pre-built MozillaRustComponents.xcframework.zip bundle on which this repository depends.


Here's a diagram of how this repository relates to the application-services repository and its release artifacts:

A box diagram describing how the rust-components-swift repo, applicaiton-services repo, and MozillaRustComponents XCFramework interact

Key points:

  • The application-services repo publishes a binary artifact MozillaRustComponents.xcframework.zip containing the Rust code and FFI definitions for all components, compiled together into a single library.
  • The Package.swift file references MozillaRustComponents.xcframework.zip as a Swift binary target.
  • The Package.swift file defines an individual module for the Swift wrapper code of each component.
    • Each module references its Swift source code directly as files in the repo.
    • Each module depends on MozillaRustComponentsWrapper which wraps MozillaRustComponents to provide the pre-compiled Rust code.

Cutting a new release

Whenever a new release of the underlying components is availble, we need to tag a new release in this repo to make them available to Swift components. To do so:

  • Edit Package.swift to update the URL and checksum of MozillaRustComponents.xcframework.zip.
  • Run ./make_tag.sh --as-version {APP_SERVICES_VERSION} X.Y.Z to create the new tag.
  • Run git push origin X.Y.Z to publish it to GitHub.

Adding a new component

To add a new component to be distributed via this repo, you'll need to:

  • Add its Rust code and .h files to the build for the MozillaRustComponents.xcframework.zip bundle, following the docs for the ios-rust crate.
  • If the component needs to dynamically generate any Swift code (e.g. for UniFFI bindings, or Glean metrics), add logic for doing so to the ./generate.sh script in this repository.
    • Swift packages can't dynamically generate code at build time, so we use the ./generate.sh script to do it ahead-of-time when publishing a release.
  • Edit ./Package.swift to add the new component.
    • Add a new library product for the component under "products".
    • Add a corresponding target for the component under "targets".
      • Make sure it depends on "MozillaRustComponentsWrapper" to pull in the pre-compiled Rust code, as well as on any third-party Swift packages that it may require.
  • Follow the instructions below to test it out locally.

That's it! The component will be included in the next release of this package.

Testing locally

Swift Packages can only be installed from a git repository, but luckily it is possible to use a local checkout for a git repository for local testing.

You may also need to follow the instructions for [locally testing the ios-rust crate](https://raw.github.com/mozilla/rust-components-swift/main/ https://github.com/mozilla/application-services/blob/f3228cf1295154d144be64fc0945c9b3e93a07de/megazords/ios-rust/README.md#testing-locally) if you need to test changes in the underlying Rust code.

To test out some local changes to this repo:

  • Make your changes in a local checkout and commit them.
  • Make a new tag via ./make_tag.sh -f 0.0.1.
    • (You won't push this tag anywhere, but using a very low version number helps guard against any adverse consequences if it does accidentally escape your local machine).
  • In a consuming application, delete the Swift Package dependency on https://github.com/mozilla/rust-components-swift and replace it with a dependency on file:///path/to/your/local/checkout/rust-components-swift at the 0.0. release.

Testing against a local application-services checkout

To run against a local application services checkout, the make_tag.sh script supports setting a local path using a -l flag, for example:

./make_tag -l ../application-services 0.0.1

That's it! The consuming application should be able to import the package from your local checkout.


Stars: 6
Last commit: Yesterday
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Related Packages

Release Notes

2 days ago

90.0.0 (2022-01-25)


⚠️ Breaking Changes ⚠️

  • Places has been completely UniFFI-ed


⚠️ Breaking Changes ⚠️

  • The bundled version of Glean has been updated to v43.0.2. See the Glean Changelog for full details. BREAKING CHANGE: Pass build info into initialize, which contains the build date. A suitable instance is generated by glean_parser in GleanMetrics.GleanBuild.info.


What's new

  • The Nimbus SDK now support application version targeting, where experiment creators can set app_version|versionCompare({VERSION}) >= 0 and the experiments will only target users running VERSION or higher. (#4752)
    • The versionCompare transform will return a positive number if app_version is greater than VERSION, a negative number if app_version is less than VERSION and zero if they are equal
    • VERSION must be passed in as a string, for example: app_version|versionCompare('95.!') >= 0 will target users who are on any version starting with 95 or above (95.0, 95.1, 95.2.3-beta, 96 etc..)

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics