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

feat(quaint): enable wasm32-unknown-unknown compilation via slim feature flag #4119

Closed
wants to merge 10 commits into from

Conversation

jkomyno
Copy link
Contributor

@jkomyno jkomyno commented Aug 7, 2023

This PR enables compiling quaint to wasm32-unknown-unknown when using the feature flag slim:

cd quaint && cargo build --no-default-features --features slim --target wasm32-unknown-unknown
Context

There is a related PR (#4064) that extracts quaint to a separate quaint-core crate. I had been working on a patch over that but there are several issues with that PR:

  • For structs like QuaintValue, it will need to be defined in quaint-core, but traits like tokio_postgres::ToSql will be implemented in quaint, which is not allowed by Rust because both ToSql and QuaintValue are not part of the crate that implements the trait. We will need to implement a wrapper and change all usages of QuaintValue to the wrapper if we proceed with the extracting quaint-core approach.
  • We will need to rework other crates significantly if we need to selectively import quaint-core / quaint.

I spent 1.5 days working upon #4064 without getting it compiled and therefore I decided to continue with the current approach, which only takes 2 hours to finish the refactor.

In this PR, we mainly refactored the connector part and single.rs of the quaint crate to make it compile in WASM.

  • Firstly, we introduce a new set of features: postgresql-connector, mysql-connector, mysql-connector, and sqlite-connector, which are the switches to import the actual database connector implementation into the quaint crate.
  • Then, we have a new slim feature that is exclusively used by the WASM compilation. Compiling with this feature does not include the connectors but all the code for parsing database URL, transforming SQLs, etc.
  • Lastly, all connector implementation has been split into xxx_common.rs and xxx.rs. All code are copy-pasted with only tiny changes like changing the import qualifier (i.e., tokio_postgres::config::SslMode instead of SslMode). All other things remain unchanged.

Compiling quaint into WASM would be the milestone that enables Prisma running in edge runtime. I think we are 50% done here, and the remaining work is to get other crates on the path to compile and add a new wasm driver.

This is a big refactor that might conflict with ongoing PRs on the quaint crate. Feel free to ping me for rebasing / resolving merge conflicts. Thanks for the reviews in advance!


This PR closes https://github.com/prisma/team-orm/issues/279.

The original PR (with conflicts) is at: #4095.

@jkomyno jkomyno changed the title [helper PR from fork] compile quaint to wasm [helper PR from Neon's fork] compile quaint to wasm Aug 7, 2023
@jkomyno jkomyno mentioned this pull request Aug 7, 2023
@codspeed-hq
Copy link

codspeed-hq bot commented Aug 7, 2023

CodSpeed Performance Report

Merging #4119 will not alter performance

Comparing jkomyno/quaint-wasm (81fc17b) with main (aec118a)

Summary

✅ 11 untouched benchmarks

@jkomyno jkomyno added this to the 5.2.0 milestone Aug 14, 2023
@jkomyno jkomyno changed the title [helper PR from Neon's fork] compile quaint to wasm feat(quaint): enable wasm32-unknown-unknown compilation via slim feature flag Aug 14, 2023
Copy link
Contributor

@tomhoule tomhoule left a comment

Choose a reason for hiding this comment

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

Can we revert the changes to Cargo.lock? It doesn't look like they add much, just noise.

Copy link
Contributor

@tomhoule tomhoule left a comment

Choose a reason for hiding this comment

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

One preliminary thought, is that if we don't regression test this in CI, we're bound to break wasm32-unknown-unknown compilation with a random PR or cargo update.

@tomhoule
Copy link
Contributor

Hi @skyzh — this is awesome work and it is definitely going to be useful when we tackle Wasm, hopefully in the near future. Since we would be merging this code without exercising it, that would amount to merging additional complexity in the form of conditional compilation because it may be useful later, so a few of us discussed yesterday and decided to hold off on merging for now.

We may want to reduce the amounts of feature flags in quaint, and separate the database drivers part of quaint from the pure logic before we tackle this.

@skyzh
Copy link
Contributor

skyzh commented Aug 16, 2023

Thanks for letting me know! Feel free to ping me if there is anything I can help :)

@jkomyno
Copy link
Contributor Author

jkomyno commented Nov 17, 2023

Superseded by #4442.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: edge functions formerly phase 2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants