From 1ac606b4b212738e366a2b8b42b1d45d843c8018 Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Mon, 1 Jul 2024 13:18:22 +0200 Subject: [PATCH 1/6] add first test import msbuild as submodule fix ci refactor/rename tasks --- .github/workflows/dotnet.yml | 12 +++-- .gitmodules | 3 ++ MSBuildWasm.sln | 6 --- examples/ExampleProject/ExampleProject.csproj | 4 +- msbuild | 1 + src/WasmExec.cs | 2 +- src/WasmTask.cs | 46 +++++++++++++------ test/WasmTasksTests/WasmTask_Tests.cs | 13 +++++- test/WasmTasksTests/WasmTasksTests.csproj | 13 ++++-- 9 files changed, 69 insertions(+), 31 deletions(-) create mode 100644 .gitmodules create mode 160000 msbuild diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 217f7cb..9c6a97a 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -10,8 +10,7 @@ on: branches: [ "main" ] jobs: - build: - + test: runs-on: ubuntu-latest steps: @@ -20,9 +19,12 @@ jobs: uses: actions/setup-dotnet@v4 with: dotnet-version: 8.0.x + - name: build MSBuild for unit test .dll + run: ./msbuild/build.sh - name: Restore dependencies run: dotnet restore - - name: Build - run: dotnet build --no-restore + - name: Publish + run: + dotnet publish - name: Test - run: dotnet test --no-build --verbosity normal + run: dotnet test --no-build diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..10f8c7c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "msbuild"] + path = msbuild + url = https://github.com/dotnet/msbuild diff --git a/MSBuildWasm.sln b/MSBuildWasm.sln index c247626..e171ad4 100644 --- a/MSBuildWasm.sln +++ b/MSBuildWasm.sln @@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExampleProject", "examples\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WasmTasksTests", "test\WasmTasksTests\WasmTasksTests.csproj", "{94FE5153-34D6-4F93-9792-7408AD89945D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Playground", "Playground\Playground.csproj", "{047F357B-00C5-49E1-B577-A17D5CFBD02E}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,10 +27,6 @@ Global {94FE5153-34D6-4F93-9792-7408AD89945D}.Debug|Any CPU.Build.0 = Debug|Any CPU {94FE5153-34D6-4F93-9792-7408AD89945D}.Release|Any CPU.ActiveCfg = Release|Any CPU {94FE5153-34D6-4F93-9792-7408AD89945D}.Release|Any CPU.Build.0 = Release|Any CPU - {047F357B-00C5-49E1-B577-A17D5CFBD02E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {047F357B-00C5-49E1-B577-A17D5CFBD02E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {047F357B-00C5-49E1-B577-A17D5CFBD02E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {047F357B-00C5-49E1-B577-A17D5CFBD02E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/examples/ExampleProject/ExampleProject.csproj b/examples/ExampleProject/ExampleProject.csproj index 3b5f622..0acb85b 100644 --- a/examples/ExampleProject/ExampleProject.csproj +++ b/examples/ExampleProject/ExampleProject.csproj @@ -11,8 +11,8 @@ - - + + diff --git a/msbuild b/msbuild new file mode 160000 index 0000000..a9c95c7 --- /dev/null +++ b/msbuild @@ -0,0 +1 @@ +Subproject commit a9c95c7251503f85493d3f3bb43780ffa8104589 diff --git a/src/WasmExec.cs b/src/WasmExec.cs index 9905baa..b23c165 100644 --- a/src/WasmExec.cs +++ b/src/WasmExec.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; using Microsoft.Build.Framework; -namespace WasmWasiTasks +namespace MSBuildWasm { public class WasmExec : Microsoft.Build.Utilities.Task, IWasmTask { diff --git a/src/WasmTask.cs b/src/WasmTask.cs index ea228cb..f026178 100644 --- a/src/WasmTask.cs +++ b/src/WasmTask.cs @@ -28,6 +28,18 @@ public class WasmTask : Microsoft.Build.Utilities.Task, IWasmTask public bool EnableIO { get; set; } = true; + readonly string outputPath = Path.GetFullPath("output.txt"); + readonly string errorPath = Path.GetFullPath("output.txt"); + readonly string tmpPath = Path.GetFullPath("tmp"); + + const string executeFunctionName = "execute"; + const string outDirName = "wasmtaskoutput"; + + public WasmTask() + { + + } + public override bool Execute() { try @@ -51,14 +63,13 @@ public override bool Execute() } if (HomeDir != null) { - var dir = Directory.CreateDirectory("wasmtaskoutput"); + var dir = Directory.CreateDirectory(outDirName); wasiConfigBuilder = wasiConfigBuilder.WithPreopenedDirectory(dir.FullName, "/out"); } - if (EnableIO) { - wasiConfigBuilder = wasiConfigBuilder.WithStandardOutput("output.txt") - .WithStandardError("error.txt"); + wasiConfigBuilder = wasiConfigBuilder.WithStandardOutput(outputPath) + .WithStandardError(errorPath); } using var store = new Store(engine); @@ -67,7 +78,11 @@ public override bool Execute() Instance instance = linker.Instantiate(store, module); - Action fn = instance.GetAction("execute"); // TBD parameters + Action fn = instance.GetAction(executeFunctionName); + //dynamic instance = + + //var instancedifferent = instance.GetFunction(); + if (fn == null) { @@ -86,19 +101,24 @@ public override bool Execute() { if (EnableTmp) { - Directory.Delete("tmp", true); + Directory.Delete(tmpPath, true); } if (EnableIO) { // TODO unique filenames - string output = File.ReadAllText("output.txt"); - string error = File.ReadAllText("error.txt"); - - Log.LogMessage(MessageImportance.High, $"Output: {output}"); - Log.LogMessage(MessageImportance.Normal, $"Error: {error}"); + if (File.Exists(outputPath)) + { + string output = File.ReadAllText(outputPath); + Log.LogMessage(MessageImportance.High, $"Output: {output}"); + File.Delete(outputPath); + } - File.Delete("output.txt"); - File.Delete("error.txt"); + if (File.Exists(errorPath)) + { + string error = File.ReadAllText(errorPath); + Log.LogMessage(MessageImportance.Normal, $"Error: {error}"); + File.Delete(errorPath); + } } } diff --git a/test/WasmTasksTests/WasmTask_Tests.cs b/test/WasmTasksTests/WasmTask_Tests.cs index 8ca20a2..993ee32 100644 --- a/test/WasmTasksTests/WasmTask_Tests.cs +++ b/test/WasmTasksTests/WasmTask_Tests.cs @@ -2,15 +2,26 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using Microsoft.Build.UnitTests.Shared; using MSBuildWasm; +using Xunit; +using Shouldly; +using Microsoft.Build.UnitTests; namespace WasmTasksTests { public class WasmTask_Tests { [Fact] - public void Execute_WithDefaultSettings_ShouldSucceed() + public void ExecuteTemplate_WithDefaultSettings_ShouldSucceed() { + IWasmTask task = new WasmTask { + BuildEngine = new MockEngine(), + WasmFilePath = "../../../../../examples/rust_template/target/wasm32-wasi/release/rust_template.wasm" + }; + + task.Execute().ShouldBeTrue(); } } diff --git a/test/WasmTasksTests/WasmTasksTests.csproj b/test/WasmTasksTests/WasmTasksTests.csproj index 46cc899..10d798a 100644 --- a/test/WasmTasksTests/WasmTasksTests.csproj +++ b/test/WasmTasksTests/WasmTasksTests.csproj @@ -11,13 +11,20 @@ - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + $(MSBuildThisFileDirectory)\..\..\msbuild\artifacts\bin\Microsoft.Build.UnitTests.Shared\Debug\net8.0\Microsoft.Build.UnitTests.Shared.dll + From ec1b7f0aa974f6cdc4ffe6eb57bc8a424b5fe7b2 Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Mon, 1 Jul 2024 13:26:11 +0200 Subject: [PATCH 2/6] init msbuild submodule in ci --- .github/workflows/dotnet.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 9c6a97a..debb663 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -15,10 +15,17 @@ jobs: steps: - uses: actions/checkout@v4 + with: + submodules: 'true' - name: Setup .NET uses: actions/setup-dotnet@v4 with: dotnet-version: 8.0.x + - name: Initialize submodules + run: | + git submodule init + git submodule update + - name: build MSBuild for unit test .dll run: ./msbuild/build.sh - name: Restore dependencies From 516d5ea3ad3c0a366b88080d90c2999e12e88827 Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Mon, 1 Jul 2024 13:52:34 +0200 Subject: [PATCH 3/6] stable version for build --- .github/workflows/dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index debb663..dcf63e3 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -20,7 +20,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 8.0.201 - name: Initialize submodules run: | git submodule init From 72e8fa6402ee1676955820ca72ee21ee63de4b2e Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Tue, 2 Jul 2024 11:06:49 +0200 Subject: [PATCH 4/6] fix workflow to run examples --- .github/workflows/dotnet.yml | 12 +++++++----- .gitignore | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index dcf63e3..6a19eed 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -20,18 +20,20 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.201 + dotnet-version: 8.0.x - name: Initialize submodules run: | git submodule init git submodule update - + - name: install standalone wasmtime + run: curl https://wasmtime.dev/install.sh -sSf | bash - name: build MSBuild for unit test .dll run: ./msbuild/build.sh - name: Restore dependencies run: dotnet restore - name: Publish - run: - dotnet publish + run: dotnet publish src - name: Test - run: dotnet test --no-build + run: dotnet test + - name: Examples + run: dotnet build examples diff --git a/.gitignore b/.gitignore index 1bda89d..8fa4ac2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ bin/ obj/ .vs -Playground/ \ No newline at end of file +Playground/ +/MSBuildWasmLocal.sln From b5f4f5361b17e0a61da89b3fa1f2555dcefff91c Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Tue, 2 Jul 2024 11:25:48 +0200 Subject: [PATCH 5/6] fix wasmtime install --- .github/workflows/dotnet.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 6a19eed..ce82764 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -26,7 +26,10 @@ jobs: git submodule init git submodule update - name: install standalone wasmtime - run: curl https://wasmtime.dev/install.sh -sSf | bash + run: | + curl https://wasmtime.dev/install.sh -sSf | bash + echo "::add-path::$HOME/.wasmtime/bin" + wasmtime --version - name: build MSBuild for unit test .dll run: ./msbuild/build.sh - name: Restore dependencies From 04bc06cdb1988ef88dcfbc71ec3d13e43704f824 Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Tue, 2 Jul 2024 11:27:46 +0200 Subject: [PATCH 6/6] fix wasmtime install --- .github/workflows/dotnet.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index ce82764..ab52200 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -28,7 +28,8 @@ jobs: - name: install standalone wasmtime run: | curl https://wasmtime.dev/install.sh -sSf | bash - echo "::add-path::$HOME/.wasmtime/bin" + echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH + export PATH=$HOME/.wasmtime/bin:$PATH wasmtime --version - name: build MSBuild for unit test .dll run: ./msbuild/build.sh