diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 5a481501..895e0bf3 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -15,13 +15,6 @@ "DocFxTocGenerator" ], "rollForward": false - }, - "dotnet-script": { - "version": "1.5.0", - "commands": [ - "dotnet-script" - ], - "rollForward": false } } } \ No newline at end of file diff --git a/.github/gen-test-matrix.ps1 b/.github/gen-test-matrix.ps1 index 8173b3fc..dba1544c 100644 --- a/.github/gen-test-matrix.ps1 +++ b/.github/gen-test-matrix.ps1 @@ -4,8 +4,8 @@ param ( ) $ErrorActionPreference = "Stop"; - -$nugetOrgPkgSrc = "nuget.org"; + +$nugetOrgPkgSrc = "nuget.org"; $operatingSystems = @( [pscustomobject]@{ @@ -16,7 +16,7 @@ $operatingSystems = @( runnerArch = 1; hasFramework = $true; unityMonoArch = @("win32", "win64", "win_arm64"); - unityMonoDll = "mono-2.0-bdwgc.dll"; + unityMonoDll = "mono-2.0-bdwgc.dll"; dllSuffix = ".dll"; }, [pscustomobject]@{ @@ -27,8 +27,8 @@ $operatingSystems = @( runnerArch = 0; hasMono = $true; unityMonoArch = @("linux64"); - unityMonoDll = "limonobdwgc-2.0.so"; # TODO - dllPrefix = "lib"; + unityMonoDll = "limonobdwgc-2.0.so"; # TODO + dllPrefix = "lib"; dllSuffix = ".so"; }, [pscustomobject]@{ @@ -39,8 +39,8 @@ $operatingSystems = @( runnerArch = 0; hasMono = $true; unityMonoArch = @("macos_x64"); - unityMonoDll = "limonobdwgc-2.0.dylib"; - dllPrefix = "lib"; + unityMonoDll = "limonobdwgc-2.0.dylib"; + dllPrefix = "lib"; dllSuffix = ".dylib"; }, [pscustomobject]@{ @@ -52,8 +52,8 @@ $operatingSystems = @( runnerArch = 1; hasMono = $true; unityMonoArch = @("macos_x64", "macos_arm64"); - unityMonoDll = "limonobdwgc-2.0.dylib"; - dllPrefix = "lib"; + unityMonoDll = "limonobdwgc-2.0.dylib"; + dllPrefix = "lib"; dllSuffix = ".dylib"; } ); @@ -96,8 +96,8 @@ $dotnetVersions = @( sdk = "6.0"; tfm = "net6.0"; rids = @("win-x86","win-x64","win-arm64","linux-x64","linux-arm","linux-arm64","osx-x64","osx-arm64"); - pgo = $true; - netMonoPkgVer = "6.0.31" + pgo = $true; + netMonoPkgVer = "6.0.31" netMonoNugetSrc = $nugetOrgPkgSrc; }, [pscustomobject]@{ @@ -105,8 +105,8 @@ $dotnetVersions = @( sdk = "7.0"; tfm = "net7.0"; rids = @("win-x86","win-x64","win-arm64","linux-x64","linux-arm","linux-arm64","osx-x64","osx-arm64"); - pgo = $true; - netMonoPkgVer = "7.0.20" + pgo = $true; + netMonoPkgVer = "7.0.20" netMonoNugetSrc = $nugetOrgPkgSrc; }, [pscustomobject]@{ @@ -114,25 +114,25 @@ $dotnetVersions = @( sdk = "8.0"; tfm = "net8.0"; rids = @("win-x86","win-x64","win-arm64","linux-x64","linux-arm","linux-arm64","osx-x64","osx-arm64"); - pgo = $true; - netMonoPkgVer = "8.0.6" + pgo = $true; + netMonoPkgVer = "8.0.6" netMonoNugetSrc = $nugetOrgPkgSrc; } ); - -$netMonoPackageName = "Microsoft.NETCore.App.Runtime.Mono.{RID}"; -$netMonoLibPath = "runtimes/{RID}/lib/{TFM}/"; -$netMonoDllPath = "runtimes/{RID}/native/{DllPre}coreclr{DllSuf}"; - -function Fill-Template($template, $obj) -{ - $result = $template; - foreach ($kvp in $obj.GetEnumerator()) - { + +$netMonoPackageName = "Microsoft.NETCore.App.Runtime.Mono.{RID}"; +$netMonoLibPath = "runtimes/{RID}/lib/{TFM}/"; +$netMonoDllPath = "runtimes/{RID}/native/{DllPre}coreclr{DllSuf}"; + +function Fill-Template($template, $obj) +{ + $result = $template; + foreach ($kvp in $obj.GetEnumerator()) + { $result = $result -replace "{$($kvp.Key)}",$kvp.Value; - } + } return $result; -} +} $monoTfm = "net462"; @@ -172,7 +172,7 @@ function Remove-NullProperties { $obj } -} +} foreach ($os in $operatingSystems) { @@ -253,38 +253,38 @@ foreach ($os in $operatingSystems) arch = $arch; } ); - } - - if ($dotnet.netMonoNugetSrc) - { - # this runtime version has an associated Mono build - $fill = @{ - RID = $rid; - TFM = $dotnet.tfm; - DllPre = $os.dllPrefix; + } + + if ($dotnet.netMonoNugetSrc) + { + # this runtime version has an associated Mono build + $fill = @{ + RID = $rid; + TFM = $dotnet.tfm; + DllPre = $os.dllPrefix; DllSuf = $os.dllSuffix; - }; - - # fill the templates, so that we can add the job - $pkgName = Fill-Template $netMonoPackageName $fill - $libPath = Fill-Template $netMonoLibPath $fill - $dllPath = Fill-Template $netMonoDllPath $fill - - # We always need to do a restore on Mono - $jobdotnet = $outdotnet | Select-Object -ExcludeProperty sdk,pgo -Property *,` - @{n='isMono';e={$true}},` - @{n='netMonoPkgName';e={$pkgName}},` - @{n='monoLibPath';e={$libPath}},` - @{n='monoDllPath';e={$dllPath}} - $jobdotnet.needsRestore = $true; - - $jobs += @( - [pscustomobject]@{ - title = ".NET Mono $($dotnet.netMonoPkgVer) $arch on $($os.name)"; - os = $outos; - dotnet = $jobdotnet | Remove-NullProperties; + }; + + # fill the templates, so that we can add the job + $pkgName = Fill-Template $netMonoPackageName $fill + $libPath = Fill-Template $netMonoLibPath $fill + $dllPath = Fill-Template $netMonoDllPath $fill + + # We always need to do a restore on Mono + $jobdotnet = $outdotnet | Select-Object -ExcludeProperty sdk,pgo -Property *,` + @{n='isMono';e={$true}},` + @{n='netMonoPkgName';e={$pkgName}},` + @{n='monoLibPath';e={$libPath}},` + @{n='monoDllPath';e={$dllPath}} + $jobdotnet.needsRestore = $true; + + $jobs += @( + [pscustomobject]@{ + title = ".NET Mono $($dotnet.netMonoPkgVer) $arch on $($os.name)"; + os = $outos; + dotnet = $jobdotnet | Remove-NullProperties; arch = $arch; - } + } ); } } diff --git a/.github/setup-mono.csx b/.github/setup-mono.csx deleted file mode 100644 index 0fa400cd..00000000 --- a/.github/setup-mono.csx +++ /dev/null @@ -1,234 +0,0 @@ -#!/usr/bin/env dotnet script -#nullable enable -#r "nuget:Chell,1.0.0" -#r "nuget:NuGet.Frameworks,6.10.0" -#r "nuget:NuGet.Configuration,6.10.0" -#r "nuget:NuGet.Protocol,6.10.0" - -using Chell; -using NuGet.Frameworks; -using System.IO.Compression; -using static Chell.Exports; - -static string GetScriptFolder([System.Runtime.CompilerServices.CallerFilePath] string path = "") => Path.GetDirectoryName(path) ?? "."; -var ScriptDir = GetScriptFolder(); - -if (Args is not [{ } matrixJson, { } githubOutputFile, { } githubEnvFile, { } runnerOs]) -{ - Console.WriteLine("Must have 4 arguments: the job json, the github outputs file, the github env file, and the runner OS"); - return 1; -} - -githubOutputFile = Path.GetFullPath(githubOutputFile); -githubEnvFile = Path.GetFullPath(githubEnvFile); - -var jobInfo = FromJson(matrixJson, new -{ - arch = "", - dotnet = new - { - isMono = false, - systemMono = false, - tfm = "", - netMonoNugetSrc = (string?)null, - netMonoPkgName = (string?)null, - netMonoPkgVer = (string?)null, - monoLibPath = (string?)null, - monoDllPath = (string?)null, - } -}); - -if (jobInfo is null) -{ - Console.WriteLine("Job info was null"); - return 1; -} - -if (!jobInfo.dotnet.isMono) -{ - Console.WriteLine("Nothing to do, job is not a Mono job"); - return 0; -} - -// TODO: use NuGet libs to automatically determine matching xunit console tfm -var tfm = jobInfo.dotnet.tfm; -var ntf = NuGetFramework.Parse(tfm); - -var runnerTfm = NuGetFrameworkUtility.GetNearest( - [ // xUnit.runner.console package /tools/ TFMs - "net452", - "net46", - "net461", - "net462", - "net47", - "net471", - "net472", - "netcoreapp1.0", - "netcoreapp2.0", - ], - ntf, - NuGetFramework.Parse); - -// set the output -File.AppendAllLines(githubOutputFile, [$"runner_tfm={runnerTfm}"]); - -if (jobInfo.dotnet.systemMono) -{ - if (!TryWhich("mono", out var monoPath)) - { - Console.WriteLine("System mono job, but could not find system Mono on PATH"); - return 1; - } - - Console.WriteLine($"Job is for system mono; using mono={monoPath}"); - File.AppendAllLines(githubOutputFile, [ - "use_mdh=false", - $"mono_dll={monoPath}", - ]); - return 0; -} - -var pkgSrc = jobInfo.dotnet.netMonoNugetSrc; -var pkgName = jobInfo.dotnet.netMonoPkgName; -var pkgVer = jobInfo.dotnet.netMonoPkgVer; -var libPath = jobInfo.dotnet.monoLibPath; -var dllPath = jobInfo.dotnet.monoDllPath; - -if (pkgSrc is null || pkgName is null || pkgVer is null || libPath is null || dllPath is null) -{ - Console.WriteLine("Job info is missing some required properties"); - return 1; -} - -var repoRoot = Path.GetFullPath(Path.Combine(ScriptDir, "..")); -var monoDir = Path.Combine(repoRoot, ".mono"); -Directory.CreateDirectory(monoDir); - -// Lets download MDH -var mdhDir = Path.Combine(monoDir, "mdh"); -var mdhExe = Path.Combine(mdhDir, "mdh"); - -{ - var mdhZip = Path.Combine(monoDir, "mdh.zip"); - - // compute the arch name - var mdhArch = jobInfo.arch; - var osName = runnerOs.ToLowerInvariant(); - mdhArch = mdhArch switch - { - "x64" => "x86_64", - "arm64" => "aarch64", - var x => x - }; - if (osName is "linux") - { - osName = "linux-gnu.2.10"; - } - - // download the file - var url = $"https://github.com/nike4613/mono-dynamic-host/releases/latest/download/{mdhArch}-{osName}.zip"; - - using (var file = File.Create(mdhZip)) - { - using var stream = await FetchStreamAsync(url); - await stream.CopyToAsync(file); - } - - // extract the archive - if (Directory.Exists(mdhDir)) - { - Directory.Delete(mdhDir, true); - } - ZipFile.ExtractToDirectory(mdhZip, mdhDir); - - // update mdhExe - if (File.Exists(mdhExe + ".exe")) - { - mdhExe = mdhExe + ".exe"; - } - - if (!Env.IsWindows) - { - // on non-Windows, mark the exe executable - await Run($"chmod +x {mdhExe}"); - } -} - -// now we want to restore the Mono package - -// TODO: do NuGet restore with NuGet APIs - -var origNugetPackages = Env.Vars["NUGET_PACKAGES"]; -try -{ - var pkgsPath = Path.Combine(monoDir, "pkg"); - Env.Vars["NUGET_PACKAGES"] = pkgsPath; - - var dummyProjPath = Path.Combine(monoDir, "dummy.csproj"); - // set up project files - File.WriteAllText(Path.Combine(monoDir, "Directory.Build.props"), ""); - File.WriteAllText(Path.Combine(monoDir, "Directory.Build.targets"), ""); - File.WriteAllText(dummyProjPath, $""" - - - - {tfm} - false - - - - - - - - """); - - var nugetConfigFile = Path.Combine(monoDir, "nuget.config"); - var embeddedMapping = pkgSrc == "nuget.org" - ? "" - : $""; - File.WriteAllText(nugetConfigFile, $""" - - - - - - - - {embeddedMapping} - - - - """); - - using (Cd(monoDir)) - { - await Run($"dotnet restore {dummyProjPath} --packages {pkgsPath} -tl:off -bl:{Path.Combine(monoDir, "msbuild.binlog")}"); - } - - var pkgBase = Path.Combine(pkgsPath, pkgName.ToLowerInvariant(), pkgVer); - var fullLibPath = Path.GetFullPath(Path.Combine(pkgBase, libPath)); - var fullDllPath = Path.GetFullPath(Path.Combine(pkgBase, dllPath)); - - Console.WriteLine($""" - Job is for .NET Mono - mdh={mdhExe} - mono_dll={fullDllPath} - MONO_PATH={fullLibPath} - """); - - File.AppendAllLines(githubOutputFile, [ - "use_mdh=true", - $"mdh={mdhExe}", - $"mono_dll={fullDllPath}", - ]); - File.AppendAllLines(githubEnvFile, [ - $"MONO_PATH={fullLibPath}" - ]); -} -finally -{ - Env.Vars["NUGET_PACKAGES"] = origNugetPackages; -} - -return 0; \ No newline at end of file diff --git a/.github/workflows/run-mono-tests.ps1 b/.github/workflows/run-mono-tests.ps1 index 1bd16336..331b68fc 100644 --- a/.github/workflows/run-mono-tests.ps1 +++ b/.github/workflows/run-mono-tests.ps1 @@ -3,5 +3,5 @@ $useMdh = $env:USE_MDH -eq "true"; [string[]]$exeargs = if ($useMdh) { @($env:MONO_DLL) } else { @() }; # TODO: this xUnit TFM is incorrect for some targets. We'd really like to use vstest on .NET Mono, as that will keep things somewhat simpler. -&$exe @exeargs "$($env:NUGET_PACKAGES)/xunit.runner.console/$($env:XunitVersion)/tools/$($env:XUNIT_TFM)/xunit.console.exe" ` +&$exe @exeargs "$($env:NUGET_PACKAGES)/xunit.runner.console/$($env:XunitVersion)/tools/$($env:TFM)/xunit.console.exe" ` "release_$($env:TFM)/MonoMod.UnitTest.dll" -junit "$($env:LOG_FILE_NAME).xml" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a06cef22..25d74377 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,6 @@ env: DOTNET_TELEMETRY_OPTOUT: true DOTNET_NOLOGO: true NUGET_PACKAGES: ${{github.workspace}}/artifacts/pkg - DOTNET_SCRIPT_CACHE_LOCATION: ${{github.workspace}}/artifacts/script-cache XunitVersion: "2.4.2" jobs: @@ -49,14 +48,6 @@ jobs: key: ${{ runner.os }}-nuget-v1-${{ hashFiles('**/*.csproj', '**/*.props', '**/*.targets', 'nuget.config', 'global.json') }} restore-keys: ${{ runner.os }}-nuget-v1- - - name: Cache scripts - uses: actions/cache@v4 - if: ${{ fromJSON(inputs.matrix).dotnet.isMono }} - with: - path: ${{ env.NUGET_PACKAGES }} - key: ${{ runner.os }}-script-v1-${{ hashFiles('**/*.csx') }} - restore-keys: ${{ runner.os }}-script-v1- - - name: Install restore SDK if: ${{ fromJSON(inputs.matrix).dotnet.needsRestore }} uses: nike4613/install-dotnet@54b402247e474b39b84891b9093d8025892c8b47 @@ -64,10 +55,6 @@ jobs: architecture: ${{ fromJSON(inputs.matrix).arch }} global-json: global.json - - name: Restore tools - if: ${{ fromJSON(inputs.matrix).dotnet.isMono }} - run: dotnet tool restore - - name: Restore packages if: ${{ fromJSON(inputs.matrix).dotnet.needsRestore }} run: dotnet restore -noAutoRsp @@ -91,7 +78,7 @@ jobs: env: INPUT_JOB: ${{ inputs.matrix }} run: | - dotnet script ./.github/setup-mono.csx $env:INPUT_JOB $env:GITHUB_OUTPUT $env:GITHUB_ENV ${{ runner.os }} + ./.github/setup-mono.ps1 $env:INPUT_JOB $env:GITHUB_OUTPUT $env:GITHUB_ENV ${{ runner.os }} - name: Print SDK info run: dotnet --info @@ -121,12 +108,13 @@ jobs: if: ${{ fromJSON(inputs.matrix).dotnet.isMono }} env: TFM: ${{ fromJSON(inputs.matrix).dotnet.tfm }} - XUNIT_TFM: ${{ steps.setup_mono.outputs.runner_tfm }} USE_MDH: ${{ steps.setup_mono.outputs.use_mdh }} MDH: ${{ steps.setup_mono.outputs.mdh }} MONO_DLL: ${{ steps.setup_mono.outputs.mono_dll }} run: ./.github/workflows/run-mono-tests.ps1 - + + # TODO: Non-system Mono + - name: Upload test results uses: actions/upload-artifact@v4 if: ${{ always() }}