Skip to content

Commit

Permalink
Merge pull request #60 from jsturtevant/fix-publish-step
Browse files Browse the repository at this point in the history
Fix so that compilation runs in correct order
  • Loading branch information
jsturtevant authored Nov 26, 2024
2 parents 396ccb3 + 0c86722 commit 54c40c8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ wasmtime composed.wasm
While you can run wasm-tools manually, you can also generate this automatically. One way to do this is to [create a new project](./samples/calculator/CalculatorComposed/) and add the following:

```xml
<Target Name="ComposeWasmComponent" AfterTargets="AfterBuild">
<Target Name="ComposeWasmComponent" AfterTargets="Publish">
<PropertyGroup>
<EntrypointComponent>../CalculatorHost/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/calculatorhost.wasm</EntrypointComponent>
<DependencyComponent>../Adder/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/adder.wasm</DependencyComponent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM"/>
</ItemGroup>

<Target Name="ComposeWasmComponent" AfterTargets="AfterBuild">
<Target Name="ComposeWasmComponent" AfterTargets="Publish">
<PropertyGroup>
<EntrypointComponent>../CalculatorHost/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/CalculatorHost.wasm</EntrypointComponent>
<DependencyComponent>../Adder/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/adder.wasm</DependencyComponent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<Target Name="EmitWasmOnBuild" AfterTargets="CopyFilesToOutputDirectory" DependsOnTargets="LinkNativeLlvm;"
Condition="'$(RuntimeIdentifier)' == 'wasi-wasm'">
<Message Importance="high" Text="Emit on build $(ProjectName) " />
</Target>
<!--
This links the publish step with the build so that when a user runs `dotnet build` they get a wasm file.
-->
<Target Name="PublishAfterBuild" AfterTargets="Build" DependsOnTargets="Publish" Condition="'$(RuntimeIdentifier)' == 'wasi-wasm'" />
</Project>
2 changes: 1 addition & 1 deletion test/E2ETest/testapps/E2EConsumer/E2EConsumer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</ItemGroup>

<!-- After build, create the composed component so it can be executed in the test -->
<Target Name="ComposeWasmComponent" AfterTargets="AfterBuild">
<Target Name="ComposeWasmComponent" AfterTargets="Publish">
<PropertyGroup>
<DependencyComponent>../E2EProducer/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/e2eproducer.wasm</DependencyComponent>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void CanComposeImportWithExport()
[Fact]
public void CanBuildAppFromOci()
{
var composed = FindModulePath("../testapps/OciWit", "ociwit.wasm");
var composed = FindModulePath($"../testapps/OciWit/bin/{Config}", "ociwit.wasm");
var stdout = ExecuteCommandComponent(composed);
Assert.StartsWith("Oci is awesome!", stdout);
}
Expand Down Expand Up @@ -89,11 +89,18 @@ private static string FindModulePath(string searchDir, string filename)
}

var matches = Directory.GetFiles(resolvedSearchDir, filename, SearchOption.AllDirectories);
if (matches.Count() != 1)
if (matches.Count() == 1)
{
return Path.GetFullPath(matches.Single());
}
else if (matches.Count() == 2 && matches.Any(x => Path.GetFullPath(x).Contains($"wasi-wasm\\native"))) {
return Path.GetFullPath(matches.First(x => Path.GetFullPath(x).Contains($"wasi-wasm\\native")));
}
else if (matches.Count() == 2 && matches.Any(x => Path.GetFullPath(x).Contains($"wasi-wasm/native"))) {
return Path.GetFullPath(matches.First(x => Path.GetFullPath(x).Contains($"wasi-wasm/native")));
}
else {
throw new Exception($"Failed to get modules path, matched {matches.Count()} entries for directory {resolvedSearchDir} and filename {filename}.");
}

return Path.GetFullPath(matches.Single());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</ItemGroup>

<!-- After build, create the composed component so it can be executed in the test -->
<Target Name="ComposeWasmComponent" AfterTargets="AfterBuild">
<Target Name="ComposeWasmComponent" AfterTargets="Publish">
<PropertyGroup>
<DependencyComponent>../SimpleProducer/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/simpleproducer.wasm</DependencyComponent>
</PropertyGroup>
Expand Down

0 comments on commit 54c40c8

Please sign in to comment.