bytecodealliance / componentize-dotnet

Tooling for creating WebAssembly components from C#
Apache License 2.0
19 stars 8 forks source link

Handle wit files that have imports in a folder #22

Closed jsturtevant closed 2 months ago

jsturtevant commented 2 months ago

Given a folder of Wit, some of the wit may import other files.

For example, wit in wasi-http has imports: https://github.com/WebAssembly/wasi-http/tree/main/wit

When you include this in the project you will get:

  Executing wit-bindgen...
EXEC : error : interface or world `imports` not found in package [C:\Users\jstur\projects\component\dotnet9-wasi-http-example\App.csproj]
       --> wit\deps\cli\command.wit:4:11
        |
      4 |   include imports;
        |           ^------
C:\Users\jstur\projects\component\dotnet9-wasi-http-example\.packages\bytecodealliance.componentize.dotnet.witbindgen\0.1.0-preview00003\buil 
d\ByteCodeAlliance.Componentize.DotNet.WitBindgen.targets(79,9): error MSB3073: The command "C:\Users\jstur\projects\component\dotnet9-wasi-h 
ttp-example\.packages\bytecodealliance.componentize.dotnet.witbindgen\0.1.0-preview00003\build\..\tools\win-x64\wit-bindgen.exe c-sharp wit\d 
eps\cli\command.wit  --runtime native-aot --out-dir obj\Debug\net8.0\wasi-wasm\wit_bindgen\" exited with code 1. [C:\Users\jstur\projects\com 
ponent\dotnet9-wasi-http-example\App.csproj]

This is because currently all files are executed individually https://github.com/bytecodealliance/componentize-dotnet/blob/f33ea4382f57e60f39fa34ee27c543a14fbedefc/src/WitBindgen/build/ByteCodeAlliance.Componentize.DotNet.WitBindgen.props#L27

Ideally, we could execute the wit-bindgen command on a folder and only once.

This was found when trying out https://github.com/dicej/dotnet9-wasi-http-example.

See example in https://github.com/dicej/dotnet9-wasi-http-example/compare/main...jsturtevant:dotnet9-wasi-http-example:use-wasm-sdk?expand=1