Skip to content

Commit 259a634

Browse files
committed
Shift to clang
1 parent 0636c41 commit 259a634

4 files changed

Lines changed: 21 additions & 117 deletions

File tree

Src/FastData.Generator.CPlusPlus.TestHarness/CPlusPlusBenchmark.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Globalization;
22
using System.Text;
3+
using Genbox.FastData.Generator.CPlusPlus.TestHarness.Code;
34
using Genbox.FastData.InternalShared;
45
using Genbox.FastData.InternalShared.Harness;
56
using Genbox.FastData.InternalShared.Helpers;
@@ -52,7 +53,7 @@ public override BenchmarkSuite CreateFiles(IEnumerable<ITestData> data)
5253

5354
public override void Run(BenchmarkSuite suite, bool useBencher, bool useShell)
5455
{
55-
ProcessResult configureResult = ProcessHelper.RunProcess("cmake", "-S . -B build", Bootstrap.RootDir, 100_000);
56+
ProcessResult configureResult = ProcessHelper.RunProcess("cmake", "-S . -B build -DCMAKE_CXX_COMPILER=\"" + ClangCompiler.CompilerPath + "\"", Bootstrap.RootDir, 100_000);
5657

5758
if (configureResult.ExitCode != 0)
5859
throw new InvalidOperationException($"Failed to configure CMake. Exit code: {configureResult.ExitCode}\nSTDOUT:\n{configureResult.StandardOutput}\nSTDERR:\n{configureResult.StandardError}");
@@ -81,6 +82,18 @@ private string RenderBenchmarkQueries(ITestData data, string identifier)
8182
private static string BuildCMakeLists(IEnumerable<string> sources) =>
8283
$$"""
8384
cmake_minimum_required(VERSION 3.20)
85+
86+
if(DEFINED ENV{FASTDATA_CLANGXX})
87+
set(_clangxx "$ENV{FASTDATA_CLANGXX}")
88+
if(IS_DIRECTORY "${_clangxx}")
89+
set(_clangxx "${_clangxx}/clang++")
90+
endif()
91+
if(WIN32 AND NOT EXISTS "${_clangxx}" AND EXISTS "${_clangxx}.exe")
92+
set(_clangxx "${_clangxx}.exe")
93+
endif()
94+
set(CMAKE_CXX_COMPILER "${_clangxx}" CACHE FILEPATH "" FORCE)
95+
endif()
96+
8497
project(fast_data_benchmarks LANGUAGES CXX)
8598
set(CMAKE_CXX_STANDARD 17)
8699
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Src/FastData.Generator.CPlusPlus.TestHarness/CPlusPlusBootstrap.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public CPlusPlusBootstrap(HarnessType type) : base("CPlusPlus", type)
1313
{
1414
CPlusPlusLanguageDef langDef = new CPlusPlusLanguageDef();
1515
Map = new TypeMap(langDef.TypeDefinitions, GeneratorEncoding.UTF8);
16-
Compiler = new GccCompiler(RootDir);
16+
Compiler = new ClangCompiler(RootDir);
1717
}
1818

1919
internal TypeMap Map { get; }
20-
internal GccCompiler Compiler { get; }
20+
internal ClangCompiler Compiler { get; }
2121

2222
public override ICodeGenerator GeneratorFactory(string id) => CPlusPlusCodeGenerator.Create(new CPlusPlusCodeGeneratorConfig(id));
2323
}

Src/FastData.Generator.CPlusPlus.TestHarness/Code/GccCompiler.cs renamed to Src/FastData.Generator.CPlusPlus.TestHarness/Code/ClangCompiler.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33

44
namespace Genbox.FastData.Generator.CPlusPlus.TestHarness.Code;
55

6-
public sealed class GccCompiler
6+
public sealed class ClangCompiler
77
{
88
private readonly string _rootPath;
9+
internal const string CompilerPath = @"C:\clang+llvm-22.1.0-x86_64-pc-windows-msvc\bin\clang++.exe";
910

10-
public GccCompiler(string rootDir)
11+
public ClangCompiler(string rootDir)
1112
{
1213
_rootPath = rootDir;
1314

14-
if (!ProcessHelper.TryRunProcess("g++.exe", "--version"))
15+
if (!ProcessHelper.TryRunProcess(CompilerPath, "--version"))
1516
throw new InvalidOperationException("No compiler found");
1617
}
1718

@@ -24,7 +25,7 @@ public string Compile(string fileId, string source)
2425
if (!FileHelper.TryWriteFile(srcFile, source) && File.Exists(dstFile))
2526
return dstFile;
2627

27-
ProcessResult res = ProcessHelper.RunProcess("g++", $"{srcFile} -std=c++17 -O3 -DNDEBUG -o {dstFile}");
28+
ProcessResult res = ProcessHelper.RunProcess(CompilerPath, $"\"{srcFile}\" -std=c++17 -O3 -DNDEBUG -o \"{dstFile}\"");
2829

2930
if (res.ExitCode != 0)
3031
{

Src/FastData.Generator.CPlusPlus.TestHarness/Code/MsvcCompiler.cs

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)