Try to reuse bindgen from LyraApi C# package

This commit is contained in:
SeanOMik 2024-11-07 22:57:31 -05:00
parent faa5387f93
commit fcf4f54e34
Signed by: SeanOMik
GPG Key ID: FEC9E2FC15235964
4 changed files with 24 additions and 7 deletions

View File

@ -1,4 +1,4 @@
workspace = { members = [ "common-api", "witguest"] }
workspace = { members = [ "./guests/rust/common-api", "./guests/rust/witguest"] }
[package]
name = "wittest"
@ -16,5 +16,5 @@ lyra-ecs = { path = "./lyra-engine/crates/lyra-ecs" }
slab = "0.4.9"
thiserror = "2.0.0"
common-api = { path = "./common-api" }
common-api = { path = "./guests/rust/common-api" }
anyhow = "1.0.93"

View File

@ -2,9 +2,10 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using ExampleWorld.wit.imports.lyra.api;
//using ExampleWorld.wit.imports.lyra.api;
using LyraApi;
using LyraApi.Ecs;
using ImportsWorld.wit.imports.lyra.api;
[StructLayout(LayoutKind.Sequential)]
struct Vec3(float x, float y, float z) : IComponent
@ -83,7 +84,6 @@ public class ExampleWorldImpl : IExampleWorld
var world = new World(gameWorld);
Entity entity = world.Spawn(pos);
//IEcs.Entity entity = gameWorld.Spawn(GetBytes(pos), infos);
Console.WriteLine("C#: Spawned {0}", entity.Id);
IEcs.EcsDynamicView res = gameWorld.View(infos);

View File

@ -14,7 +14,7 @@
<IlcExportUnmanagedEntrypoints>true</IlcExportUnmanagedEntrypoints>
</PropertyGroup>
<!-- Copy WIT files from LyraApi to lyra-api wit folder -->
<!-- Copy WIT files from LyraApi to lyra-api wit folder. -->
<Target Name="CopyFolderOnBuild" BeforeTargets="WitCompile_InvokeTool">
<ItemGroup>
<MyFiles Include="..\LyraApi\wit\**\*.wit" />
@ -22,6 +22,23 @@
<Copy SourceFiles="@(MyFiles)" DestinationFolder="wit\deps\lyraapi\%(RecursiveDir)" />
</Target>
<!-- Remove bindgen of LyraApi WIT .-->
<Target Name="RemoveBindgenLyraApi" AfterTargets="WitCompile_InvokeTool">
<ItemGroup>
<FilesToDelete Include="obj\Debug\net*\wasi-wasm\wit_bindgen\*.lyra.api.*.cs"/>
</ItemGroup>
<Delete Files="@(FilesToDelete)" />
</Target>
<!-- Reuse bindgen from LyraApi package instead of using local bindgen. -->
<Target Name="UpdateLyraApiReferences" AfterTargets="WitCompile_InvokeTool; RemoveBindgenLyraApi">
<Exec Condition="'$(OS)' == 'Unix'" Command="find obj/Debug -type f -wholename '*wit_bindgen/*.cs' -exec sed -i 's/ExampleWorld\.wit\.imports\.lyra\.api/ImportsWorld.wit.imports.lyra.api/g' {} \;" />
<Exec Condition="'$(OS)' == 'Windows_NT'" Command="powershell -Command &quot;Get-ChildItem -Path 'obj\Debug' -Recurse -Filter '*.cs' ^
| Where-Object { $_.FullName -match 'wit_bindgen' } ^
| ForEach-Object { (Get-Content -Path $_.FullName) -replace 'ExampleWorld\.wit\.imports\.lyra\.api', 'ImportsWorld.wit.imports.lyra.api' ^
| Set-Content -Path $_.FullName }&quot;" />
</Target>
<ItemGroup>
<PackageReference Include="BytecodeAlliance.Componentize.DotNet.Wasm.SDK" Version="0.4.0-preview00007" />
</ItemGroup>

View File

@ -24,7 +24,7 @@ pub(crate) mod lyra_engine {
wasmtime::component::bindgen!({
world: "example",
path: "witguest/wit",
path: "guests/rust/witguest/wit",
async: true,
with: {
@ -436,7 +436,7 @@ async fn main() -> wasmtime::Result<()> {
// Load the component from disk
//let bytes = std::fs::read("target/wasm32-wasip1/debug/witguest-component.wasm")?;
let bytes = std::fs::read("dotnet-guest-test/bin/Debug/net9.0/wasi-wasm/native/dotnet-guest-test.wasm")?;
let bytes = std::fs::read("guests/csharp/dotnet-guest-test/bin/Debug/net9.0/wasi-wasm/native/dotnet-guest-test.wasm")?;
let component = wasmtime::component::Component::new(&engine, bytes)?;
let (script_en, (world_res_a, world_res_b)) = {