Skip to content

feat(wasm): Change matrix-sdk-ffi to rely on features over platform targets #5211

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

Merged

Conversation

zzorba
Copy link
Contributor

@zzorba zzorba commented Jun 10, 2025

The system of platform targets was already quite messy, and becoming even worse as we start preparing for Wasm support. Switch to features instead to make this easier to work with.

The idea is that whether than a large number of platform specific checks in the toml file, these should be cfg features that can be enabled/disabled on the various platforms as needed. The xtask build system for the matrix-sdk-ffi bindings has been updated to use this to maintain existing behavior.

The new features are:

  • sentry: whether sentry is included in setup, the rust sentry library does not work on wasm platforms.
  • rustls-tls: whether rustls-tls should be used for network, this was previously implemented with target based conditionals.
  • native-tls: whether native-tls should be used for network, this was previously implemented with target based conditionals.
  • js: whether existing configs meant to run in a wasm environment targeting javascript are needed.

In the future, we will add the following additional features:

  • react-native: used to ensure the uniffi exposed interfaces are the same across platforms. This will be used more in future PRs, and is meant to address a feature requirement of react-native (where native ios+android and web bindings must share a public interface, a limitation of react-native + typescript).
  • sqlite: Will be used to control if sqlite session store is included and exposed.
  • indexeddb: Will be used to control if indexeddb session store is included and exposed.
  • Public API changes documented in changelogs (optional)

Signed-off-by: Daniel Salinas

@jplatte
Copy link
Collaborator

jplatte commented Jun 10, 2025

It would be nice to split the addition of the react-native feature into its own PR (because that's a new feature, everything else is refactors). Also the store backends maybe? Then this could already be reviewed and merged ahead of the remaining changes.

Copy link

codecov bot commented Jun 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.12%. Comparing base (cc7f624) to head (4b83233).
Report is 19 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5211      +/-   ##
==========================================
- Coverage   90.13%   90.12%   -0.01%     
==========================================
  Files         334      334              
  Lines      104717   104717              
  Branches   104717   104717              
==========================================
- Hits        94389    94381       -8     
- Misses       6275     6282       +7     
- Partials     4053     4054       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zzorba zzorba force-pushed the rework_matrix_sdk_ffi_with_features branch 3 times, most recently from f727f83 to 461fe31 Compare June 10, 2025 21:29
@zzorba
Copy link
Contributor Author

zzorba commented Jun 10, 2025

The complement-crypto system just needs to have --feature native-tls added to it, but I'm not sure how that is handled. I opened a PR on that branch, but it will fail until this PR is landed: matrix-org/complement-crypto#189

@zzorba zzorba marked this pull request as ready for review June 10, 2025 22:15
@zzorba zzorba requested a review from a team as a code owner June 10, 2025 22:15
@zzorba zzorba requested review from poljar and removed request for a team June 10, 2025 22:15
@zzorba zzorba changed the title Change matrix-sdk-ffi to rely on features over platform targets feat(wasm): Change matrix-sdk-ffi to rely on features over platform targets Jun 10, 2025
@zzorba zzorba force-pushed the rework_matrix_sdk_ffi_with_features branch 3 times, most recently from b0b65ea to 4b7c823 Compare June 10, 2025 22:48
@zzorba
Copy link
Contributor Author

zzorba commented Jun 10, 2025

@Hywan this contains the recommendations we discussed today, along with its complement-crypto PR in matrix-org/complement-crypto#189

@zzorba zzorba force-pushed the rework_matrix_sdk_ffi_with_features branch from 4b7c823 to 61e67a4 Compare June 11, 2025 00:10
@poljar
Copy link
Contributor

poljar commented Jun 11, 2025

The complement-crypto system just needs to have --feature native-tls added to it, but I'm not sure how that is handled. I opened a PR on that branch, but it will fail until this PR is landed: matrix-org/complement-crypto#189

If you name the branch in complement crypto the same as the one here, complement crypto should™ use the branch for the CI here. Though perhaps that doesn't work for branches on forks.

@zzorba
Copy link
Contributor Author

zzorba commented Jun 11, 2025

Worth a shot, opened up matrix-org/complement-crypto#190 on complement-crypto with the same branch name, though it won't run without someone granting it permission.

@poljar poljar requested review from poljar and removed request for Hywan June 16, 2025 07:37
Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

I left a couple of nits, can you please document the feature flags in the readme and explain why we're using feature flags instead of configuring things for users on a per-platform basis.


[features]
default = ["bundled-sqlite", "unstable-msc4274"]
bundled-sqlite = ["matrix-sdk/bundled-sqlite"]
unstable-msc4274 = ["matrix-sdk-ui/unstable-msc4274"]
# Required when targeting a js environment, like wasm in a browser.
js = ["matrix-sdk-ui/js"]
# Use native-tls system, necessary on ios and wasm platforms.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Use native-tls system, necessary on ios and wasm platforms.
# Use the TLS implementation provided by the host system, necessary on iOS and Wasm platforms.

native-tls = ["matrix-sdk/native-tls", "sentry?/native-tls"]
# Use the rustls-tls system, necessary on android platforms.
rustls-tls = ["matrix-sdk/rustls-tls", "sentry?/rustls"]
# Enable sentry, not compatible with wasm platforms.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Enable sentry, not compatible with wasm platforms.
# Enable sentry, not compatible with Wasm platforms.

@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
<!-- next-header -->

## [Unreleased] - ReleaseDate

- Adjust features in the `matrix-sdk-ffi` crate to expose more platform-specific knobs
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a missing category for this entry and a missing newline and the entry doesn't quite explain what's going on. It's also a breaking feature.

Could we reword this somehow to explain that we're switching from platform specific configuration to feature specific configuration, explaining the rationale here would be helpful to other consumers as well.

Suggested change
- Adjust features in the `matrix-sdk-ffi` crate to expose more platform-specific knobs
- Adjust features in the `matrix-sdk-ffi` crate to expose more platform-specific knobs

@zzorba
Copy link
Contributor Author

zzorba commented Jun 17, 2025

Thank you for the feedback @poljar, I expanded the Changelog with a motivation and backwards compatibility instructions.

I added a similar entry to the README file explaining the current features.

@poljar
Copy link
Contributor

poljar commented Jun 17, 2025

I left a small nit about whitespace in the changelog file, also please resolve the conflicts. After that we can merge this.

@zzorba
Copy link
Contributor Author

zzorba commented Jun 17, 2025

@poljar merge conflicts addressed and last changes updated.

I believe complement-crypto should work with the corresponding PR, the code-coverage break seems to be intermittent?

@zzorba zzorba requested a review from Hywan June 18, 2025 13:23
@zzorba
Copy link
Contributor Author

zzorba commented Jun 18, 2025

@poljar / @Hywan I've removed the "lib" change and placed it in its own PR. Can this be landed now?

Copy link
Collaborator

@jplatte jplatte left a comment

Choose a reason for hiding this comment

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

I don't think this can merge before CI is green, but looks like that's being worked on separately. Changes LGTM.

@zzorba
Copy link
Contributor Author

zzorba commented Jun 18, 2025

Besides the break, the complement crypto won't go green without the corresponding pr, so one will have to break in order to land this

@zzorba zzorba closed this Jun 19, 2025
@zzorba zzorba reopened this Jun 19, 2025
Daniel Salinas and others added 16 commits June 19, 2025 09:31
The system of platform targets was already quite messy, and becoming
even worse as we start preparing for Wasm support. Switch to features
instead to make this easier to work with.
Co-authored-by: Damir Jelić <[email protected]>
Signed-off-by: Daniel Salinas <[email protected]>
Co-authored-by: Damir Jelić <[email protected]>
Signed-off-by: Daniel Salinas <[email protected]>
Co-authored-by: Damir Jelić <[email protected]>
Signed-off-by: Daniel Salinas <[email protected]>
Co-authored-by: Jonas Platte <[email protected]>
Signed-off-by: Daniel Salinas <[email protected]>
Co-authored-by: Jonas Platte <[email protected]>
Signed-off-by: Daniel Salinas <[email protected]>
Co-authored-by: Jonas Platte <[email protected]>
Signed-off-by: Daniel Salinas <[email protected]>
Co-authored-by: Jonas Platte <[email protected]>
Signed-off-by: Daniel Salinas <[email protected]>
@zzorba zzorba force-pushed the rework_matrix_sdk_ffi_with_features branch from d1bedb5 to e3b92a6 Compare June 19, 2025 13:31
@zzorba
Copy link
Contributor Author

zzorba commented Jun 19, 2025

I rebased to try to make the CI happy.

@poljar poljar merged commit 040fd6c into matrix-org:main Jun 19, 2025
44 of 45 checks passed
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