diff --git a/etc/config/csharp.defaults.properties b/etc/config/csharp.defaults.properties index 20c93164192..cd318bfbc0f 100644 --- a/etc/config/csharp.defaults.properties +++ b/etc/config/csharp.defaults.properties @@ -1,19 +1,25 @@ -compilers=&csharpdef +compilers=&csharp supportsBinary=true needsMulti=false compilerType=csharp -defaultCompiler=dotnet7csharpdef +defaultCompiler=dotnet700csharp -group.csharpdef.compilers=dotnet6csharpdef:dotnet7csharpdef +group.csharp.compilers=dotnettrunkcsharp:dotnet700csharp:dotnet6011csharp -compiler.dotnet6csharpdef.exe=/opt/compiler-explorer/dotnet-v6.0.11/.dotnet/dotnet -compiler.dotnet6csharpdef.name=.NET 6.0.403 -compiler.dotnet6csharpdef.clrDir=/opt/compiler-explorer/dotnet-v6.0.11 -compiler.dotnet6csharpdef.buildConfig=Release -compiler.dotnet6csharpdef.langVersion=latest +compiler.dotnet6011csharp.exe=/opt/compiler-explorer/dotnet-v6.0.11/.dotnet/dotnet +compiler.dotnet6011csharp.name=.NET 6.0.403 +compiler.dotnet6011csharp.clrDir=/opt/compiler-explorer/dotnet-v6.0.11 +compiler.dotnet6011csharp.buildConfig=Release +compiler.dotnet6011csharp.langVersion=latest -compiler.dotnet7csharpdef.exe=/opt/compiler-explorer/dotnet-v7.0.0/.dotnet/dotnet -compiler.dotnet7csharpdef.name=.NET 7.0.100 -compiler.dotnet7csharpdef.clrDir=/opt/compiler-explorer/dotnet-v7.0.0 -compiler.dotnet7csharpdef.buildConfig=Release -compiler.dotnet7csharpdef.langVersion=latest +compiler.dotnet700csharp.exe=/opt/compiler-explorer/dotnet-v7.0.0/.dotnet/dotnet +compiler.dotnet700csharp.name=.NET 7.0.100 +compiler.dotnet700csharp.clrDir=/opt/compiler-explorer/dotnet-v7.0.0 +compiler.dotnet700csharp.buildConfig=Release +compiler.dotnet700csharp.langVersion=latest + +compiler.dotnettrunkcsharp.exe=/opt/compiler-explorer/dotnet-trunk/.dotnet/dotnet +compiler.dotnettrunkcsharp.name=.NET (main) +compiler.dotnettrunkcsharp.clrDir=/opt/compiler-explorer/dotnet-trunk +compiler.dotnettrunkcsharp.buildConfig=Release +compiler.dotnettrunkcsharp.langVersion=preview diff --git a/lib/compilers/dotnet.ts b/lib/compilers/dotnet.ts index cd77007251f..d59e61a5511 100644 --- a/lib/compilers/dotnet.ts +++ b/lib/compilers/dotnet.ts @@ -40,12 +40,15 @@ import {DotNetAsmParser} from '../parsers/asm-parser-dotnet'; import * as utils from '../utils'; class DotNetCompiler extends BaseCompiler { - private sdkBaseDir: string; - private sdkVersion: string; - private targetFramework: string; - private buildConfig: string; - private clrBuildDir: string; - private langVersion: string; + private readonly sdkBaseDir: string; + private readonly sdkVersion: string; + private readonly targetFramework: string; + private readonly buildConfig: string; + private readonly clrBuildDir: string; + private readonly langVersion: string; + private readonly crossgen2Path: string; + + private crossgen2VersionString: string; constructor(compilerInfo, env) { super(compilerInfo, env); @@ -59,7 +62,10 @@ class DotNetCompiler extends BaseCompiler { this.buildConfig = this.compilerProps(`compiler.${this.compiler.id}.buildConfig`); this.clrBuildDir = this.compilerProps(`compiler.${this.compiler.id}.clrDir`); this.langVersion = this.compilerProps(`compiler.${this.compiler.id}.langVersion`); + + this.crossgen2Path = path.join(this.clrBuildDir, 'crossgen2', 'crossgen2'); this.asm = new DotNetAsmParser(); + this.crossgen2VersionString = ''; } get compilerOptions() { @@ -128,6 +134,7 @@ class DotNetCompiler extends BaseCompiler { // Some versions of .NET complain if they can't work out what the user's directory is. We force it to the output // directory here. execOptions.env.DOTNET_CLI_HOME = programDir; + execOptions.env.DOTNET_ROOT = path.join(this.clrBuildDir, '.dotnet'); // Place nuget packages in the output directory. execOptions.env.NUGET_PACKAGES = path.join(programDir, '.nuget'); // Try to be less chatty @@ -190,7 +197,6 @@ class DotNetCompiler extends BaseCompiler { inputFilename: string, execOptions: ExecutionOptions, ): Promise { - const crossgen2Path = path.join(this.clrBuildDir, 'crossgen2', 'crossgen2.dll'); const crossgen2Options: string[] = []; const configurableOptions = this.configurableOptions; const programDir = path.dirname(inputFilename); @@ -221,9 +227,7 @@ class DotNetCompiler extends BaseCompiler { } const crossgen2Result = await this.runCrossgen2( - compiler, execOptions, - crossgen2Path, this.clrBuildDir, programDllPath, crossgen2Options, @@ -280,9 +284,27 @@ class DotNetCompiler extends BaseCompiler { } } - async runCrossgen2(compiler, execOptions, crossgen2Path, bclPath, dllPath, options, outputPath) { + async ensureCrossgen2Version(execOptions) { + if (!this.crossgen2VersionString) { + this.crossgen2VersionString = '// crossgen2 '; + + const versionFilePath = `${this.clrBuildDir}/version.txt`; + const versionResult = await this.exec(this.crossgen2Path, ['--version'], execOptions); + if (versionResult.code === 0) { + this.crossgen2VersionString += versionResult.stdout; + } else if (fs.existsSync(versionFilePath)) { + const versionString = await fs.readFile(versionFilePath); + this.crossgen2VersionString += versionString; + } else { + this.crossgen2VersionString += ''; + } + } + } + + async runCrossgen2(execOptions, bclPath, dllPath, options, outputPath) { + await this.ensureCrossgen2Version(execOptions); + const crossgen2Options = [ - crossgen2Path, '-r', path.join(bclPath, '/'), dllPath, @@ -300,12 +322,12 @@ class DotNetCompiler extends BaseCompiler { '--compilebubblegenerics', ].concat(options); - const compilerExecResult = await this.exec(compiler, crossgen2Options, execOptions); + const compilerExecResult = await this.exec(this.crossgen2Path, crossgen2Options, execOptions); const result = this.transformToCompilationResult(compilerExecResult, dllPath); await fs.writeFile( outputPath, - result.stdout.map(o => o.text).reduce((a, n) => `${a}\n${n}`, ''), + `${this.crossgen2VersionString}\n\n${result.stdout.map(o => o.text).reduce((a, n) => `${a}\n${n}`, '')}`, ); return result;