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

Distribute Pomsky as a native library #62

Open
lppedd opened this issue Jan 1, 2023 · 5 comments
Open

Distribute Pomsky as a native library #62

lppedd opened this issue Jan 1, 2023 · 5 comments

Comments

@lppedd
Copy link

lppedd commented Jan 1, 2023

Distributing Pomsky not only in the CLI format, but also as a native library (.so, .dll), allows tools to compile and receive an output in a standardized format which can be interpreted through interfaces like JNI or JNA.
Example usage: compilation and error reporting inside of an IDE.

I think a project like this https://github.com/Dushistov/flapigen-rs might come handy.

@Aloso
Copy link
Member

Aloso commented Jan 2, 2023

My idea was to add a CLI flag to print compilation results as JSON, which could be used by IDEs. However, that is not implemented yet.

But to make your IDE extension work, I think all you need is jni-rs. You can follow this tutorial (maybe there are better ones, this is just the first one I found) and make a crate that exports a Java_Pomsky_compile function for the JNI. Then you just need to map Rust types to Java types. For example, a CompileError can be returned as two integers for the Span and a string.

By the way, I was planning to look at your lexer and BNF grammar but didn't have time until now. I'll try to give you some feedback tomorrow.

@lppedd
Copy link
Author

lppedd commented Jan 2, 2023

@Aloso JSON is a good idea. However, are we sure it's ok performance wise? I would like to call it every time there is an edit, like in the playground, and it has to report errors as fast as possible.
Playground uses a WASM module, so it's basically a native interaction.

If I make a crate, do I have to recompile each time a new version comes out? I believe the answer is yes, which means it becomes a bit cumbersome.

@lppedd
Copy link
Author

lppedd commented Jan 2, 2023

This is how an IDE would handle this situation.

  1. Allow the user to select a CLI executable
  2. Extract the Pomsky version from the CLI
  3. If the user enables the enhanced error reporting, the native library is downloaded through Github
  4. A native call is performed and errors are overlayed

@Aloso
Copy link
Member

Aloso commented Jan 2, 2023

Creating a process takes less than a millisecond on recent hardware, I think, so it's not that expensive to call pomsky's CLI. But to get the best performance, using something like JNI would be better. Yes, that requires recompiling the dynamic library every time a new version comes out, but maybe that can be automated somewhat.

@lppedd
Copy link
Author

lppedd commented Jan 2, 2023

@Aloso just keep in mind extensions should just inherit from the tool. If extensions have to carry their own compiled versions of Pomsky, it becomes a binary hell.

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