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

Add C ABI target with support for iOS and Android #4774

Closed
wants to merge 0 commits into from
Closed

Add C ABI target with support for iOS and Android #4774

wants to merge 0 commits into from

Conversation

ospfranco
Copy link
Contributor

@ospfranco ospfranco commented Mar 15, 2024

This is part of an effort to potentially bring Prisma to the mobile world via React Native and Expo.

React native can directly bind C++ functions to JS. Rust can expose functions via C ABI. Therefore I have added a new target for the query engine that exposes this functionality via C-style calls.

This target also aiming for Android and iOS has added some conditional compilation to other parts of the engine. So it is not an isolated change, therefore it's important to do a thorough review.

Some merge artifacts might have remained, so let me know if you find anything.

@ospfranco ospfranco self-assigned this Mar 15, 2024
@ospfranco ospfranco requested a review from a team as a code owner March 15, 2024 08:35
@ospfranco ospfranco requested review from jkomyno and removed request for a team March 15, 2024 08:35
@CLAassistant
Copy link

CLAassistant commented Mar 15, 2024

CLA assistant check
All committers have signed the CLA.

@ospfranco ospfranco requested a review from SevInf March 15, 2024 08:35
Cargo.toml Outdated Show resolved Hide resolved
libs/query-engine-common/Cargo.toml Outdated Show resolved Hide resolved
libs/query-engine-common/src/engine.rs Outdated Show resolved Hide resolved
libs/query-engine-common/src/error.rs Outdated Show resolved Hide resolved
libs/user-facing-errors/src/common.rs Outdated Show resolved Hide resolved
query-engine/query-engine-wasm/example/example.js Outdated Show resolved Hide resolved
query-engine/query-engine-wasm/example/package.json Outdated Show resolved Hide resolved
schema-engine/core/src/lib.rs Outdated Show resolved Hide resolved
schema-engine/core/src/state.rs Outdated Show resolved Hide resolved
schema-engine/core/src/state.rs Outdated Show resolved Hide resolved
renovate.json Outdated Show resolved Hide resolved
@medz

This comment has been minimized.

@medz medz mentioned this pull request Mar 18, 2024
6 tasks
Copy link
Contributor

@Weakky Weakky left a comment

Choose a reason for hiding this comment

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

Partial review ; More incoming tomorrow!

query-engine/driver-adapters/executor/src/rn.ts Outdated Show resolved Hide resolved
query-engine/driver-adapters/executor/src/rn.ts Outdated Show resolved Hide resolved
query-engine/driver-adapters/executor/src/rn.ts Outdated Show resolved Hide resolved
// .await
}

async unsafe fn apply_migrations(&self, migration_folder_path: *const c_char) -> Result<(), Error> {
Copy link
Contributor

Choose a reason for hiding this comment

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

While I understand that pulling in the entire schema engine was way too big to simply handle that, it does look like a lot of duplicated logic that we will have to maintain long-term. I don't want this to be blocking the merge of the PR, but we should def. add some TODO here to think about how to pull in bits of logic from the schema engine to handle this, without having to pull in the entire crate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup definitely, at the same time, the use case will be different. Handling errors will be done differently on thousands of devices at the same time. While on the server the person doing the migration has hands-on keyboard, on mobile this will need to have a lot more failsafe to allow apps to start in case of a failed migration.

I haven't completely thought through was this means since this is a completely new use case for Prisma.

For now I will add the TODO but it might actually make sense to keep it separated.

query-engine/query-engine-c-abi/src/engine.rs Outdated Show resolved Hide resolved
query-engine/query-engine-c-abi/src/engine.rs Outdated Show resolved Hide resolved
query-engine/query-engine-c-abi/src/engine.rs Outdated Show resolved Hide resolved
query-engine/query-engine-c-abi/src/engine.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@Weakky Weakky left a comment

Choose a reason for hiding this comment

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

Great job, this is quite a lot of work! @SevInf and I have left a bunch of comments. Don't hesitate to ask us for help if anything's unclear or you don't understand what we're asking you. There is still the matter of the tests to figure out before we merge this. Let's discuss this in Slack.

query-engine/query-engine-c-abi/src/error.rs Outdated Show resolved Hide resolved
query-engine/query-engine-c-abi/src/functions.rs Outdated Show resolved Hide resolved
query-engine/query-engine-c-abi/src/lib.rs Outdated Show resolved Hide resolved
query-engine/query-engine-c-abi/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is mostly a duplicate of query-engine-node-api. We now have 3 versions of the roughly the same file. We won't ask you to DRY these 3 loggers, this is mostly a note for us to remember to do it. I've created an issue here https://github.com/prisma/team-orm/issues/1054

query-engine/query-engine-c-abi/src/migrations.rs Outdated Show resolved Hide resolved
query-engine/query-engine-c-abi/src/migrations.rs Outdated Show resolved Hide resolved
query-engine/query-engine-node-api/Cargo.toml Outdated Show resolved Hide resolved
schema-engine/core/src/state.rs Outdated Show resolved Hide resolved
@ospfranco ospfranco requested a review from Weakky March 21, 2024 06:55
Copy link

codspeed-hq bot commented Mar 22, 2024

CodSpeed Performance Report

Merging #4774 will not alter performance

Comparing ospfranco:main (15d11aa) with main (93f79ec)

Summary

✅ 11 untouched benchmarks

@SevInf
Copy link
Contributor

SevInf commented Mar 22, 2024

@ospfranco native QE tests should be fixed by now, to make driver adapters pass you need to pull in latest main

@ospfranco ospfranco closed this Mar 26, 2024
@ospfranco ospfranco mentioned this pull request Mar 26, 2024
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.

9 participants