Stream: wit-bindgen

Topic: variant type is omitted if not used


view this post on Zulip anb (Sep 10 2025 at 06:34):

Hi, I'm not sure if this is intended, but giving the follow snippet, the compiler will "no Foo in my::test::test" unless the test-fn is uncommented. And this only applies to variant but not enum.

wit_bindgen::generate!({
    inline: r"
        package my:test;

        interface test {
            variant foo {
                a,
            }
            enum bar {
                a,
            }
            /// test-fn: func(val: foo);
        }

        world the-world {
            import test;
        }
    ",
});

use my::test::test::Bar;
use my::test::test::Foo;

view this post on Zulip Alex Crichton (Sep 10 2025 at 14:37):

This is expected, but if you don't want this behavior you can pass generate_unused_types: true to the macro (documented here)

view this post on Zulip anb (Sep 10 2025 at 14:56):

Thank you Alex, as always. How could I miss the obvious setting, and was also looking at the wrong docs at wasmtime/component/bindgen.

Edit: Looks like the option works only for the guest(wit-bindgen), but not the host(wasmtime::component::bindgen).

view this post on Zulip Alex Crichton (Sep 10 2025 at 15:03):

It's true yeah the two codebases have diverged over time and while we try to keep them similar they aren't the exact same


Last updated: Dec 06 2025 at 07:03 UTC