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

Consider publishing the Rust code in this repo as a crate #178

Open
landonxjames opened this issue Aug 31, 2023 · 4 comments
Open

Consider publishing the Rust code in this repo as a crate #178

landonxjames opened this issue Aug 31, 2023 · 4 comments

Comments

@landonxjames
Copy link

We have a need to generate Python component bindings from a Typescript application. I've been able to do that by building the Rust code in this repository and using jco to create TS bindings for it (see below). But that requires vendoring the Rust code or generated WASM binary in our application. If the core Rust code in this repo were published as a crate we could use Cargo to handle the dependency management with less worries about keeping the wasmtime-py module up to date.

import * as bindgen from './pybindgencomponent.mjs';
import * as fs from 'fs';
import { ensureDirSync } from 'fs-extra';
import * as path from 'path';

const outdir = 'pybindings';

const contents = fs.readFileSync('../my-component-nowasi.wasm', null);
const result = bindgen.generate("pybindings", contents);
for (const [filename, contents] of result) {
    const fullpath = path.join(outdir, filename);
    console.log(`Writing ${fullpath}`);
    ensureDirSync(path.dirname(fullpath));
    fs.writeFileSync(fullpath, contents);
}
$ node demo.mjs
Writing pybindings/__init__.py
Writing pybindings/exports/__init__.py
Writing pybindings/exports/mytypes.py
Writing pybindings/imports/__init__.py
Writing pybindings/imports/http_client.py
Writing pybindings/intrinsics.py
Writing pybindings/root.core0.wasm
Writing pybindings/root.core1.wasm
Writing pybindings/root.core2.wasm
@alexcrichton
Copy link
Member

Would it be possible to use a git dependency on this repository? From a Cargo dependency perspective I think that should work, and it would likely entail exporting a few things, but that should be ok

@landonxjames
Copy link
Author

A git dependency would be a bit tough for our use-case since we will be providing this to end users and would prefer to always be pinned to an explicit release. One of my more python savvy teammates suggested using pip and pulling the wasm module out of the downloaded zip, so that should work for our purposes at the moment. But long term would love to see all the binding generators published separately from their primary language bindings!

@alexcrichton
Copy link
Member

For the pinning, would tags perhaps work out? Either that or specific revisions (or having a Cargo.lock) would suffice for pinning things.

I'm not 100% sure what your build system and integration would look like however, so I could easily be missing something.

@landonxjames
Copy link
Author

Apologies for the lack of reply, just getting back around to this as some other work took me away from it.

We ended up combining your suggestion of a GH dependency + the tag targeting with the (nightly) artifact dependencies cargo feature to get something working.

Would still like to see the crates published to crates.io to keep things in step with the rest of the ecosystem (ex: js-component-bindgen) and to enable publishing other crates that rely on wasmtime-py.

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