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

Allow to embed Rust in native sources #2351

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

WojciechMazur
Copy link
Contributor

@WojciechMazur WojciechMazur commented Aug 21, 2021

After sugestion of @ekrich and some discussion with Scala tooling team in @VirtusLab we've come up with implementation allowing to embed Rust sources in native sources of SN durring our last hacking session.
Current solution supports both compilation of simple programs using rustc as well as more complicated projects using external dependencies using crates.io. It would allow for bootsrapping frameworks calling Rust from Scala Native. Some additional abstractions might be needed to introduce in order to fullfill Rusts memory management contract - especially read-only references, as well as to provide bindings for rust allowing to allocate memory inside Scala Native's GC, most of that might be possible to introduce as third-party library.

It's worth to note that compilation of Rust sources currently always creates static libraries instead of object files, this solution has it's drawbacks - especially larger size of created artifacts, however it allows us to use Rust's std library, which might be problematic to provide on it's own. Due to this decision we needed to introduce some additional types, that would keep track either given source is object file or static library.

@armanbilge
Copy link
Member

armanbilge commented Feb 16, 2022

We were discussing this PR in Discord today. @ekrich mentioned that it was in good shape but there wasn't much interest. So I wanted to make sure to express my interest 😁

The appeal of this would be to help integrate/bind with Tokio which is the modern answer to libuv (e.g., Node.js uses libuv but Deno uses Tokio). Specifically, the goal would be to use Tokio to provide a Native implementation of the cross-platform fs2 I/O APIs, which already support both JVM and Node.js. Cross-building these APIs almost immediately unlocks other popular libs such as http4s and skunk which are pure-crosses built on top of fs2.

Thanks for pursuing these initiatives!

@ahjohannessen
Copy link

@WojciechMazur This PR is exciting :) What is the status on this?

let str: &str = c_str.to_str().unwrap();
return str == "Hello Rust";
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Missing a return here.

#[no_mangle]
pub extern "C" fn isEven(x: i32) -> bool {
x % 2 == 0
}
Copy link
Member

Choose a reason for hiding this comment

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

Missing return here too.

@armanbilge
Copy link
Member

I'm working on refreshing this PR in #2566.

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.

None yet

4 participants