Stream: general

Topic: Package and namespace being renamed when building component


view this post on Zulip Lorenzo (Feb 04 2025 at 06:52):

Hi everyone,

I am facing a weird issue and I'm not quite sure what the relevant tool is -- whether JCO, wkg, warg, etc.

I am trying to wkg wit fetch a package that was published to a warg registry that I am self-hosting. The package is called example:hello, version 0.1.0. Here's the WIT:

package example:hello@0.1.0;

interface greeting {
  greet: func(name: string);
}

world hello {
  export greeting;
}

I am building this with JCO:

jco componentize hello.js --wit wit/ --world-name hello --out hello.wasm

Here's the hello.js file:

export const greet = (name) => {
  console.log(`hello ${name}!`);
};

export const greeting = {
  greet,
};

It compiles seemingly correctly, and I can use this as a dynamic library if I import it with wasmtime and pass my local .wit file.

The problem is that I can't fetch the .wit file with wkg wit fetch. I am trying to fetch it from this other component's .wit:

package example:component;

world a-whole-new-world {
    import example:hello/greeting@0.1.0;

    export add: func(x: s32, y: s32) -> s32;
}

But when I run wkg wit fetch, I get this error:

Error: failed to merge package from directory `/project-path/wit`

Caused by:
    package 'example:hello@0.1.0' not found. known packages:
        root:component

         --> /project-path/wit/component.wit:8:12
          |
        8 |     import example:hello/greeting@0.1.0;
          |            ^------------

So root:component is a known package, but not example:component.

I inspected the published package, hello.wasm, with jco wit hello.wasm:

package root:component;

world root {
  import wasi:io/poll@0.2.3;
  import wasi:clocks/monotonic-clock@0.2.3;
  import wasi:io/error@0.2.3;
  import wasi:io/streams@0.2.3;
  import wasi:http/types@0.2.0;
  import wasi:http/outgoing-handler@0.2.0;
  import wasi:cli/stdin@0.2.3;
  import wasi:cli/stdout@0.2.3;
  import wasi:cli/stderr@0.2.3;
  import wasi:cli/terminal-input@0.2.3;
  import wasi:cli/terminal-output@0.2.3;
  import wasi:cli/terminal-stdin@0.2.3;
  import wasi:cli/terminal-stdout@0.2.3;
  import wasi:cli/terminal-stderr@0.2.3;
  import wasi:clocks/wall-clock@0.2.3;
  import wasi:filesystem/types@0.2.3;
  import wasi:filesystem/preopens@0.2.3;
  import wasi:random/random@0.2.3;

  export example:hello/greeting@0.1.0;
}

So it looks like the problem is that my package is being renamed to root:component, which then has a world and exports my package from that world. But I want to publish the package itself, not for it to be wrapped in another root:component package?

I may be misunderstanding how packages work, not sure.

btw I posted this same issue in the wasmtime channel before I realised there were different channels (lol). Sorry for the duplicate.

view this post on Zulip Victor Adossi (Feb 04 2025 at 07:56):

Hey glad you were able to get jco working and able to use the components your produced.

As far as pushing your WIT up to a registry, did you make to use wkg publish? I'm thinking you might have used wkg publish on the built component, and as you've noticed when you build a component, the WITs are combined (and renamed) so that there is one "root" world.

While you can use it however you'd want, I like to think of the ability to push a component to a registry to be for types-only components -- not components that are fully built with functionality as well (though of course the tooling will work with both.

I think the idiomatic way to right way to solve this is likely to use wkg wit build on your wit/ directory and push that component, not the result of the build (which has one or more WITs unified into the root)


Last updated: Feb 28 2025 at 01:30 UTC