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

failed to merge package wasi:[email protected] into existing copy #52

Open
pavelsavara opened this issue Nov 29, 2024 · 2 comments
Open

Comments

@pavelsavara
Copy link

I'm trying to export wasi:http incoming-handler and import wasi:http outgoing-handler in the same component.
But the export and the import are each in different C object files and I'm passing two .wit files via -Wl,--component-type.

I separately use

world wasi-http {
  import outgoing-handler;
}

And

world wasi-http {
  export incoming-handler;
}

For each of them I use wit-bindgen c-sharp -w wasi-http -r native-aot --internal wasi-http-0.2.0/wit
And get 2 different .wit files, both named WasiHttpWorld_component_type.wit but in different folders.

Difference between them is

interface incoming-handler {
  use types.{incoming-request, response-outparam};

  handle: func(request: incoming-request, response-out: response-outparam);
}

world wasi-http {
  import wasi:io/[email protected];
  import wasi:clocks/[email protected];
  import wasi:io/[email protected];
  import wasi:io/[email protected];
  import types;

  export incoming-handler;
}

vs

interface outgoing-handler {
  use types.{outgoing-request, request-options, future-incoming-response, error-code};

  handle: func(request: outgoing-request, options: option<request-options>) -> result<future-incoming-response, error-code>;
}

world wasi-http {
  import wasi:io/[email protected];
  import wasi:clocks/[email protected];
  import wasi:io/[email protected];
  import wasi:io/[email protected];
  import types;
  import outgoing-handler;
}

The rest of the file is identical (each containing the same used types).

Simplified link command is like

wasm-component-ld --verbose -m wasm32 -Lwasi-sdk/share/wasi-sysroot/lib/wasm32-wasip2 \
--component-type WasiHttpHandler/WasiHttpWorld_component_type.wit \
--component-type WasiHttpClient/WasiHttpWorld_component_type.wit \
-o Wasi.HttpServer.Sample.wasm

The interesting part of verbose log is

wasm-ld: createHeader: DATA body=4786023 total=4786028
wasm-ld: createHeader: CUSTOM(component-type:wasip2__wasi_libc) body=10759 total=10762
wasm-ld: -- writeMapFile
wasm-ld: -- openFile
wasm-ld: writing: C:\Users\PAVELS~1\AppData\Local\Temp\.tmp68sdsS
wasm-ld: -- writeSections
wasm-ld: writing TABLE
wasm-ld: writing ELEM
wasm-ld: writing CUSTOM(component-type:wasip2__wasi_libc) offset=10479636 size=10762 chunks=1
wasm-ld: writing CODE offset=34990 size=5658618
wasm-ld:  headersize=5
wasm-ld:  codeheadersize=2
wasm-ld: writing GLOBAL
wasm-ld: writing MEMORY
wasm-ld: writing FUNCTION
wasm-ld: writing IMPORT
wasm-ld: writing TYPE
wasm-ld: writing DATA offset=5693608 size=4786028 body=4786023
wasm-ld: writing EXPORT
error: failed to merge package `wasi:[email protected]` into existing copy
@pavelsavara
Copy link
Author

I use wasm-component-ld 0.5.6 as part of wasi-sdk v24

@alexcrichton
Copy link
Member

Thanks! I believe the underlying issue here is bytecodealliance/wasm-tools#1897 which I hope to get to at some point in the future. For now though the only workaround is to permute the order of things and hope it gets fixed, but that's not great naturally :(

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