private static bool CompileCode( Project project, string cacheDir, string codePath, object consoleLock) { var compiler = new CLangCompiler(); var runtimeLibrarySourcePath = System.IO.Path.Combine(cacheDir, CodeEmitter.RuntimeLibraryCodeFileName); File.WriteAllText(runtimeLibrarySourcePath, CodeEmitter.RuntimeLibraryCode, Encoding.UTF8); var runtimeLibraryHeaderPath = System.IO.Path.Combine(cacheDir, CodeEmitter.RuntimeLibraryHeaderFileName); File.WriteAllText(runtimeLibraryHeaderPath, CodeEmitter.RuntimeLibraryHeader, Encoding.UTF8); var sourceFiles = new[] { codePath, runtimeLibrarySourcePath }; var headerSearchPaths = new[] { cacheDir }; string outputPath = project.Template switch { ProjectTemplate.App => Path.ChangeExtension(codePath, "exe"), ProjectTemplate.Lib => Path.ChangeExtension(codePath, "dll"), _ => throw ExhaustiveMatch.Failed(project.Template) }; lock (consoleLock) { Console.WriteLine($"CLang Compiling {project.Name} ({project.Path})..."); var exitCode = compiler.Compile(ConsoleCompilerOutput.Instance, sourceFiles, headerSearchPaths, outputPath); return(exitCode == 0); } }
private string CompileToExecutable(string codePath) { var compiler = new CLangCompiler(); var sourceFiles = new[] { codePath, RuntimeLibraryFixture.GetRuntimeLibraryPath() }; var headerSearchPaths = new[] { RuntimeLibraryFixture.GetRuntimeDirectory() }; var outputPath = Path.ChangeExtension(codePath, "exe"); var exitCode = compiler.Compile(new CompilerOutputAdapter(testOutput), sourceFiles, headerSearchPaths, outputPath); Assert.True(exitCode == 0, $"clang exited with {exitCode}"); return(outputPath); }