Skip to content

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

Closed

Description

@landonxjames

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

Activity

  1. alexcrichton commented on Sep 5, 2023

    @alexcrichton
    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

  2. landonxjames commented on Sep 7, 2023

    @landonxjames
    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!

  3. alexcrichton commented on Sep 13, 2023

    @alexcrichton
    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.

  4. landonxjames commented on Nov 10, 2023

    @landonxjames
    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.

  5. added a commit that references this issue on Nov 5, 2025
    93261d0
  6. added a commit that references this issue on Nov 5, 2025
    ea51991
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions