Skip to content

Commit 8058b36

Browse files
authored
Merge pull request #70 from jsturtevant/fix-multiple-oci-targets
Use the identity of the current wit property to save file
2 parents 393f3e3 + f433c80 commit 8058b36

File tree

8 files changed

+86
-20
lines changed

8 files changed

+86
-20
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ bin/
22
obj/
33
.vs/
44
artifacts/
5-
test/WasmComponentSdkTest/testapps/OciWit/wit
5+
test/WasmComponentSdkTest/testapps/OciWit/wit/*.wasm
66
*.binlog
77
.DS_Store

Directory.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
<PrebuiltWitBindgenVersion>0.40.0</PrebuiltWitBindgenVersion>
1515
<PrebuildWkgVersion>0.10.0</PrebuildWkgVersion>
1616

17+
<!-- test artifacts -->
18+
<WasmtimeVersion>30.0.2</WasmtimeVersion>
19+
1720
</PropertyGroup>
1821
</Project>

src/WitBindgen/build/BytecodeAlliance.Componentize.DotNet.WitBindgen.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
</PropertyGroup>
5858
<Message Condition="'%(Wit.Registry)' != ''" Importance="high" Text="Pulling OCI %(Wit.Registry) to %(Wit.RelativeDir)..." />
5959
<MakeDir Condition="'%(Wit.Registry)' != '' AND !Exists('%(Wit.RelativeDir)')" Directories="%(Wit.RelativeDir)" />
60-
<Exec Condition="'%(Wit.Registry)' != ''" Command="$(WkgExe) oci pull %(Wit.Registry) --output $(WitOciFile)" />
60+
<Exec Condition="'%(Wit.Registry)' != ''" Command="$(WkgExe) oci pull %(Wit.Registry) --output %(Wit.Identity)" />
6161
</Target>
6262

6363
<Target Name="WitCompile_GetDependencies" DependsOnTargets="WitCompile_InvokeTool">

test/WasmComponentSdkTest/WasmComponentSdkTest/SimpleProducerConsumerTest.cs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ public void CanBuildComponentWithWitPackage()
4141
public void CanComposeImportWithExport()
4242
{
4343
var composed = FindModulePath("../testapps/SimpleConsumer", "composed.wasm");
44-
var stdout = ExecuteCommandComponent(composed);
44+
var (stdout, stderr, code) = ExecuteCommandComponent(composed);
45+
if (code != 0) {
46+
Assert.Fail(stderr);
47+
}
4548
Assert.StartsWith("Hello, world on Wasm", stdout);
4649
Assert.Contains("123 + 456 = 579", stdout);
4750
}
@@ -50,15 +53,28 @@ public void CanComposeImportWithExport()
5053
public void CanBuildAppFromOci()
5154
{
5255
var composed = FindModulePath($"../testapps/OciWit/bin/{Config}", "ociwit.wasm");
53-
var stdout = ExecuteCommandComponent(composed);
56+
var (stdout, stderr, code) = ExecuteCommandComponent(composed, "-S http");
57+
if (code != 0) {
58+
Assert.Fail(stderr);
59+
}
5460
Assert.StartsWith("Oci is awesome!", stdout);
5561
}
5662

57-
private static string ExecuteCommandComponent(string componentFilePath)
63+
private static (string, string, int) ExecuteCommandComponent(string componentFilePath)
64+
{
65+
return ExecuteCommandComponent(componentFilePath, string.Empty);
66+
}
67+
68+
private static (string, string, int) ExecuteCommandComponent(string componentFilePath, string wasmtime_args)
5869
{
59-
var startInfo = new ProcessStartInfo(WasmtimeExePath, $"-W component-model {componentFilePath}") { RedirectStandardOutput = true };
60-
var stdout = Process.Start(startInfo)!.StandardOutput.ReadToEnd();
61-
return stdout;
70+
var startInfo = new ProcessStartInfo(WasmtimeExePath, $" {wasmtime_args} {componentFilePath}") { RedirectStandardOutput = true, RedirectStandardError = true };
71+
var process = Process.Start(startInfo) ?? throw new InvalidOperationException("Failed to start process.");
72+
process.WaitForExit();
73+
int code = process.ExitCode;
74+
var stdout = process.StandardOutput.ReadToEnd();
75+
var stderr = process.StandardError.ReadToEnd();
76+
77+
return (stdout, stderr, code);
6278
}
6379

6480
private static string GetWitInfo(string componentFilePath)
@@ -92,14 +108,17 @@ private static string FindModulePath(string searchDir, string filename)
92108
if (matches.Count() == 1)
93109
{
94110
return Path.GetFullPath(matches.Single());
95-
}
96-
else if (matches.Count() == 2 && matches.Any(x => Path.GetFullPath(x).Contains($"wasi-wasm\\native"))) {
97-
return Path.GetFullPath(matches.First(x => Path.GetFullPath(x).Contains($"wasi-wasm\\native")));
98111
}
99-
else if (matches.Count() == 2 && matches.Any(x => Path.GetFullPath(x).Contains($"wasi-wasm/native"))) {
100-
return Path.GetFullPath(matches.First(x => Path.GetFullPath(x).Contains($"wasi-wasm/native")));
112+
else if (matches.Count() == 2 && matches.Any(x => Path.GetFullPath(x).Contains($"wasi-wasm\\native")))
113+
{
114+
return Path.GetFullPath(matches.First(x => Path.GetFullPath(x).Contains($"wasi-wasm\\native")));
101115
}
102-
else {
116+
else if (matches.Count() == 2 && matches.Any(x => Path.GetFullPath(x).Contains($"wasi-wasm/native")))
117+
{
118+
return Path.GetFullPath(matches.First(x => Path.GetFullPath(x).Contains($"wasi-wasm/native")));
119+
}
120+
else
121+
{
103122
throw new Exception($"Failed to get modules path, matched {matches.Count()} entries for directory {resolvedSearchDir} and filename {filename}.");
104123
}
105124
}
Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,48 @@
11
using CommandWorld.wit.exports.wasi.cli.v0_2_0;
2+
using MyFuncsWorld;
3+
using System.Text;
24

3-
public class RunImpl : IRun
5+
namespace ProxyWorld.wit.exports.wasi.http.v0_2_0
46
{
5-
public static void Run()
7+
using ProxyWorld.wit.imports.wasi.http.v0_2_0;
8+
public class IncomingHandlerImpl : IIncomingHandler
69
{
7-
Console.WriteLine("Oci is awesome!");
10+
public static void Handle(ITypes.IncomingRequest request, ITypes.ResponseOutparam responseOut)
11+
{
12+
var content = Encoding.ASCII.GetBytes("Hello, from C#!");
13+
var headers = new List<(string, byte[])> {
14+
("content-type", Encoding.ASCII.GetBytes("text/plain")),
15+
("content-length", Encoding.ASCII.GetBytes(content.Count().ToString()))
16+
};
17+
var response = new ITypes.OutgoingResponse(ITypes.Fields.FromList(headers));
18+
var body = response.Body();
19+
ITypes.ResponseOutparam.Set(responseOut, Result<ITypes.OutgoingResponse, ITypes.ErrorCode>.Ok(response));
20+
using (var stream = body.Write())
21+
{
22+
stream.BlockingWriteAndFlush(content);
23+
}
24+
ITypes.OutgoingBody.Finish(body, null);
25+
}
826
}
927
}
28+
namespace CommandWorld.wit.exports.wasi.cli.v0_2_0
29+
{
30+
public class RunImpl : IRun
31+
{
32+
public static void Run()
33+
{
34+
Console.WriteLine("Oci is awesome!");
35+
}
36+
}
37+
}
38+
39+
namespace MyFuncsWorld
40+
{
41+
public class MyFuncsWorldImpl : IMyFuncsWorld
42+
{
43+
public static int GetNumber()
44+
{
45+
return 123;
46+
}
47+
}
48+
}

test/WasmComponentSdkTest/testapps/OciWit/OciWit.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
<ItemGroup>
2020
<Wit Remove="**\*.wit" />
21-
<Wit Include="wit/wit.wasm" World="command" Registry="ghcr.io/webassembly/wasi/cli:0.2.0" />
21+
<Wit Include="wit"/>
22+
<Wit Include="wit/cli.wasm" World="command" Registry="ghcr.io/webassembly/wasi/cli:0.2.0" />
23+
<Wit Include="wit/http.wasm" World="proxy" Registry="ghcr.io/webassembly/wasi/http:0.2.0" />
2224
</ItemGroup>
2325

2426
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package test:simple;
2+
3+
world my-funcs {
4+
export get-number: func() -> s32;
5+
}

test/WasmtimeCliFetcher/FetchWasmtime.targets

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<WasmtimeVersion>21.0.1</WasmtimeVersion>
4-
53
<WasmtimeTarget Condition="$([MSBuild]::IsOSPlatform('Windows'))">mingw</WasmtimeTarget>
64
<WasmtimeTarget Condition="$([MSBuild]::IsOSPlatform('Linux'))">linux</WasmtimeTarget>
75
<WasmtimeTarget Condition="$([MSBuild]::IsOSPlatform('OSX'))">macos</WasmtimeTarget>

0 commit comments

Comments
 (0)