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

Is it possible to have a hybrid shell e.g. Rust+Swift/Kotlin #165

Open
ntangldev opened this issue Dec 7, 2023 · 4 comments
Open

Is it possible to have a hybrid shell e.g. Rust+Swift/Kotlin #165

ntangldev opened this issue Dec 7, 2023 · 4 comments

Comments

@ntangldev
Copy link

I have an iOS project that is already using Rust libraries via FFI.

I have been looking for a solution to better structure this App as it grows. I'm expecting to integrate more Rust libraries.

I took this route to simplify migrating the App to Android and Desktop.

Crux looks like a great solution for the functional core.

The rust libraries I am currently using provide database and file sync capabilities.

I can support the capabilities in Swift and route Requests to the third party Rust libraries where necessary.

This does not seem optimal, is there any support for a hybrid shell with some requests getting routed to rust implementations and some to Swift/Kotlin?

@StuartHarris
Copy link
Member

Hey there, my sincere apologies for slow response (have been on annual leave). I think the idea of having shell-side capability implementations in Rust is interesting (if I understand you correctly). This would, I guess, raise the abstraction level of the capability, encouraging a fatter shell-side implementation. My personal preference is to make the shell-side implementation as thin (and therefore as generic) as possible. This encourages as much logic as possible to be pushed to the core (or a core, if you want to keep the logic separate/resuable). But I suspect this may not always be practical (if it requires rewriting an existing library, for example, to push the logic inwards and the side-effects outwards).
I think we need to think a bit about how that might be implemented so that it would still work for Wasm (web) targets.

@ntangldev
Copy link
Author

ntangldev commented Dec 19, 2023

Thank you for the response, I was wondering if composable applications might be a useful here, but could not find any examples or docs.

My thought was that nested Apps might support a rust shell or pass the capability request to a parent App. The outer most App would continue to route unsatisfied capabilities to one of the runtime host shells.

I seems like this would allow each App to be tested in isolation, tests could still validate capability calls.

When an App is nested in a parent App, only the capabilities that the parent App calls would be tested?

For my use case, the render capability would call out to the host shell. At the moment all other capabilities would be serviced by Rust modules.

I don't have the bandwidth to develop/test identical capabilities in multiple languages.

@StuartHarris
Copy link
Member

StuartHarris commented Dec 19, 2023

Right, got you. Yeah, I think that if the shell-side of a component becomes a mission to write in multiple languages, it may indicate that the capability is too high-level.
I have an example of an app that nests a reusable core, which effectively uses a core as a high-level "pseudo capability" that orchestrates a couple of low-level Capabilities. The child core has it's own tests, and can be reused in any Crux app. In this example, the parent exposes events that delegate to the child (but you could just expose one event that wraps the child events at the expense of the shell having to do the wrapping). Does this help?

@ntangldev
Copy link
Author

Thanks, I'll try that pattern.

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

No branches or pull requests

2 participants