tazel
A build system for C, C++, Objective-C, Objective-C++ and Zig, with C# project files.
Clonegit clone https://git.progmasoft.com/tazel
Find snapshots in CI and build the C++ tests with MSVC on Windows
- Commit
9bc494a9b2be62cc59b311f8a66e3b9b57a9cb31- Author
- Leitwolf11 ·
- Parents
b3f7192ee1f8
Changes
.github/workflows/ci.yml | 10 ++++++++++ tests/Progmasoft.Tazel.Tests/BuildCommandTests.cs | 17 +++++++++++++---- tests/Progmasoft.Tazel.Tests/PlannerTests.cs | 2 +- .../Progmasoft.Tazel.Tests.csproj | 2 ++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6987800..9ce1290 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,6 +54,16 @@ jobs: tar -xJf "$RUNNER_TEMP/zig.tar.xz" -C "$RUNNER_TEMP/zig" --strip-components=1 echo "$RUNNER_TEMP/zig" >> "$GITHUB_PATH" + # clang on Windows takes the headers and libraries of MSVC from the environment vcvars64 sets. + - name: Load the MSVC environment + if: runner.os == 'Windows' + shell: pwsh + run: | + $vs = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -property installationPath + cmd /c "`"$vs\VC\Auxiliary\Build\vcvars64.bat`" >NUL && set" | ForEach-Object { + if ($_ -match '^(INCLUDE|LIB|LIBPATH|PATH)=(.*)$') { "$($Matches[1])=$($Matches[2])" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8 } + } + # Warnings are errors in every project (Directory.Build.props). - name: Build run: dotnet build Tazel.slnx -c Release diff --git a/tests/Progmasoft.Tazel.Tests/BuildCommandTests.cs b/tests/Progmasoft.Tazel.Tests/BuildCommandTests.cs index 8122959..3c24229 100644 --- a/tests/Progmasoft.Tazel.Tests/BuildCommandTests.cs +++ b/tests/Progmasoft.Tazel.Tests/BuildCommandTests.cs @@ -54,10 +54,19 @@ public sealed class BuildCommandTests .Write("math_test.cpp", "#include \"math.hpp\"\nint main() { return add(2, 2) == 4 ? 0 : 1; }\n") .Write("failing.cpp", "int main() { return 3; }\n"); + /// <summary>Skips a test that needs a C++ compiler with its headers.</summary> + private static void SkipWithoutCompiler() + { + Assert.SkipWhen(Host.Which("clang++") is null && Host.Which("g++") is null, "no C++ compiler on PATH"); + // clang on Windows takes the C and C++ headers of MSVC from the environment that vcvars sets. + Assert.SkipWhen(OperatingSystem.IsWindows() && Environment.GetEnvironmentVariable("INCLUDE") is null, + "no MSVC environment (INCLUDE) for the headers of clang on Windows"); + } + [Fact] public async Task BuildsRunsAndTestsAModule() { - Assert.SkipWhen(Host.Which("clang++") is null && Host.Which("g++") is null, "no C++ compiler on PATH"); + SkipWithoutCompiler(); using var module = Sample(); var (status, output) = await module.TazelAsync(".", "build", "//..."); Assert.True(status == 0, output); @@ -85,13 +94,13 @@ public sealed class BuildCommandTests [Fact] public async Task ACompilerErrorStopsTheBuildWithItsCommand() { - Assert.SkipWhen(Host.Which("clang++") is null && Host.Which("g++") is null, "no C++ compiler on PATH"); + SkipWithoutCompiler(); using var module = Sample(); module.Write("math.cpp", "this is not C++\n"); var (status, output) = await module.TazelAsync(".", "build", "//:app"); Assert.Equal(1, status); - Assert.Contains("FAILED Compiling //:math math.cpp", output, StringComparison.Ordinal); - Assert.Contains("-c math.cpp", output, StringComparison.Ordinal); + Assert.True(output.Contains("FAILED Compiling //:math math.cpp", StringComparison.Ordinal), output); + Assert.True(output.Contains("-c math.cpp", StringComparison.Ordinal), output); } [Fact] diff --git a/tests/Progmasoft.Tazel.Tests/PlannerTests.cs b/tests/Progmasoft.Tazel.Tests/PlannerTests.cs index 1a94b8b..acdfb29 100644 --- a/tests/Progmasoft.Tazel.Tests/PlannerTests.cs +++ b/tests/Progmasoft.Tazel.Tests/PlannerTests.cs @@ -20,7 +20,7 @@ public sealed class PlannerTests { private static string ModuleWithToolchain(string root) => TemporaryModule.ModuleFile + """ - toolchains = Toolchains.Define("//toolchains:fake"); + toolchains = Toolchains.Define("//toolchains:fake", "//toolchains:zig"); """; private static string Toolchain(string root) => $$""" diff --git a/tests/Progmasoft.Tazel.Tests/Progmasoft.Tazel.Tests.csproj b/tests/Progmasoft.Tazel.Tests/Progmasoft.Tazel.Tests.csproj index c36fa03..709efb8 100644 --- a/tests/Progmasoft.Tazel.Tests/Progmasoft.Tazel.Tests.csproj +++ b/tests/Progmasoft.Tazel.Tests/Progmasoft.Tazel.Tests.csproj @@ -6,6 +6,8 @@ <IsTestProject>true</IsTestProject> <!-- Tests are not an API; their names say what they check. --> <GenerateDocumentationFile>false</GenerateDocumentationFile> + <!-- Snapshots are found beside the test's source file, so its path stays the real one in CI builds too. --> + <DeterministicSourcePaths>false</DeterministicSourcePaths> </PropertyGroup> <ItemGroup> <ProjectReference Include="../../src/Progmasoft.Tazel/Progmasoft.Tazel.csproj" />