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

Update docs for plugins #832

Merged
merged 4 commits into from
Nov 20, 2024
Merged

Update docs for plugins #832

merged 4 commits into from
Nov 20, 2024

Conversation

jeffcharles
Copy link
Collaborator

Description of the change

Updates documentation with new project architecture and how to extend Javy with plugins.

Why am I making this change?

Part of #768. The documentation was a bit out-of-date.

Checklist

  • I've updated the relevant CHANGELOG files if necessary. Changes to javy-cli and javy-plugin do not require updating CHANGELOG files.
  • I've updated the relevant crate versions if necessary. Versioning policy for library crates
  • I've updated documentation including crate documentation if necessary.

Wasm module. Then you need to run

```
javy init-plugin <path_to_plugin> -o <path_to_initialized_module>`
Copy link
Member

Choose a reason for hiding this comment

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

🎉

Comment on lines 73 to 94
The Wasm API the Javy CLI expects Javy plugins to expose is the following:
- Exported `initialize_runtime() -> ()` function. This will initialize a mutable
global containing the Javy runtime for use by `compile_src` and `invoke`.
- Exported
`canonical_abi_realloc(orig_ptr: i32, orig_len: i32, new_ptr: i32, new_len: i32) -> ptr: i32`
function. This is used to allocate memory in the plugin module.
- Exported `compile_src(src_ptr: i32, src_len: i32) -> bytecode_wide_ptr: i32`
function. This is used to compile JavaScript source code to QuickJS bytecode.
The return pointer points to a tuple of
`(bytecode_ptr: i32, bytecode_len: i32)` in the plugin instance's linear
memory.
- Exported
`invoke(bytecode_ptr: i32, bytecode_len: i32, fn_name_ptr: i32, fn_name_len: i32) -> ()`
function. This is used to evaluate the JavaScript code and optionally to
call an exported JS function if `fn_name_ptr` is not `0`.
- Custom section named `import_namespace` containing a UTF-8 encoded string.
This is used to determine the namespace that will be used for the Wasm
imports in dynamically linked modules built with this plugin.

The `javy-plugin-api` crate will export implementations of all required exported
functions except `initialize_runtime`. `import_namespace!` will define the
`import_namespace` custom section.
Copy link
Member

Choose a reason for hiding this comment

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

Minor nit: what do you think of putting this information inside a table to improve readability? It'll for sure be less readable in markdown format, but potentially more readable when rendered.

Copy link
Collaborator Author

@jeffcharles jeffcharles Nov 19, 2024

Choose a reason for hiding this comment

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

I don't think a table would help make it more readable. The explanation text would just be super squished. Maybe headers instead? That's how most documentation sites would render methods/functions.

@jeffcharles jeffcharles merged commit 2a46db3 into main Nov 20, 2024
7 checks passed
@jeffcharles jeffcharles deleted the jc.update-docs-for-plugins branch November 20, 2024 14:28
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.

2 participants