diff --git a/etc/config/csharp.amazon.properties b/etc/config/csharp.amazon.properties index 05bf6a6bf30..d052378655a 100644 --- a/etc/config/csharp.amazon.properties +++ b/etc/config/csharp.amazon.properties @@ -1,10 +1,10 @@ compilers=&csharp -supportsBinary=false +supportsBinary=true needsMulti=false compilerType=csharp defaultCompiler=dotnet700csharp -group.csharp.compilers=dotnet6011csharp:dotnet700csharp +group.csharp.compilers=dotnettrunkcsharp:dotnet700csharp:dotnet6011csharp compiler.dotnet6011csharp.exe=/opt/compiler-explorer/dotnet-v6.0.11/.dotnet/dotnet compiler.dotnet6011csharp.name=.NET 6.0.403 @@ -19,3 +19,10 @@ compiler.dotnet700csharp.clrDir=/opt/compiler-explorer/dotnet-v7.0.0 compiler.dotnet700csharp.targetFramework=net7.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.targetFramework=net8.0 +compiler.dotnettrunkcsharp.buildConfig=Release +compiler.dotnettrunkcsharp.langVersion=preview diff --git a/etc/config/csharp.defaults.properties b/etc/config/csharp.defaults.properties index c7709e52d69..8579fbfdbc1 100644 --- a/etc/config/csharp.defaults.properties +++ b/etc/config/csharp.defaults.properties @@ -1,5 +1,5 @@ compilers=dotnet6csharp:dotnet7csharp -supportsBinary=false +supportsBinary=true needsMulti=false compilerType=csharp defaultCompiler=dotnet7csharp diff --git a/etc/config/fsharp.amazon.properties b/etc/config/fsharp.amazon.properties index 46198dad167..919893fb1e5 100644 --- a/etc/config/fsharp.amazon.properties +++ b/etc/config/fsharp.amazon.properties @@ -1,10 +1,10 @@ compilers=&fsharp -supportsBinary=false +supportsBinary=true needsMulti=false compilerType=fsharp defaultCompiler=dotnet700fsharp -group.fsharp.compilers=dotnet6011fsharp:dotnet700fsharp +group.fsharp.compilers=dotnettrunkfsharp:dotnet700fsharp:dotnet6011fsharp compiler.dotnet6011fsharp.exe=/opt/compiler-explorer/dotnet-v6.0.11/.dotnet/dotnet compiler.dotnet6011fsharp.name=.NET 6.0.403 @@ -19,3 +19,10 @@ compiler.dotnet700fsharp.clrDir=/opt/compiler-explorer/dotnet-v7.0.0 compiler.dotnet700fsharp.targetFramework=net7.0 compiler.dotnet700fsharp.buildConfig=Release compiler.dotnet700fsharp.langVersion=latest + +compiler.dotnettrunkfsharp.exe=/opt/compiler-explorer/dotnet-trunk/.dotnet/dotnet +compiler.dotnettrunkfsharp.name=.NET (main) +compiler.dotnettrunkfsharp.clrDir=/opt/compiler-explorer/dotnet-trunk +compiler.dotnettrunkfsharp.targetFramework=net8.0 +compiler.dotnettrunkfsharp.buildConfig=Release +compiler.dotnettrunkfsharp.langVersion=preview diff --git a/etc/config/fsharp.defaults.properties b/etc/config/fsharp.defaults.properties index 8a40f3f6da7..10699499758 100644 --- a/etc/config/fsharp.defaults.properties +++ b/etc/config/fsharp.defaults.properties @@ -1,5 +1,5 @@ compilers=dotnet6fsharp:dotnet7fsharp -supportsBinary=false +supportsBinary=true needsMulti=false compilerType=fsharp defaultCompiler=dotnet7fsharp diff --git a/etc/config/vb.amazon.properties b/etc/config/vb.amazon.properties index 489b799ee88..3ef2ce8e278 100644 --- a/etc/config/vb.amazon.properties +++ b/etc/config/vb.amazon.properties @@ -1,10 +1,10 @@ compilers=&vb -supportsBinary=false +supportsBinary=true needsMulti=false compilerType=vb defaultCompiler=dotnet700vb -group.vb.compilers=dotnet6011vb:dotnet700vb +group.vb.compilers=dotnettrunkvb:dotnet700vb:dotnet6011vb compiler.dotnet6011vb.exe=/opt/compiler-explorer/dotnet-v6.0.11/.dotnet/dotnet compiler.dotnet6011vb.name=.NET 6.0.403 @@ -19,3 +19,10 @@ compiler.dotnet700vb.clrDir=/opt/compiler-explorer/dotnet-v7.0.0 compiler.dotnet700vb.targetFramework=net7.0 compiler.dotnet700vb.buildConfig=Release compiler.dotnet700vb.langVersion=latest + +compiler.dotnettrunkvb.exe=/opt/compiler-explorer/dotnet-trunk/.dotnet/dotnet +compiler.dotnettrunkvb.name=.NET (main) +compiler.dotnettrunkvb.clrDir=/opt/compiler-explorer/dotnet-trunk +compiler.dotnettrunkvb.targetFramework=net8.0 +compiler.dotnettrunkvb.buildConfig=Release +compiler.dotnettrunkvb.langVersion=latest diff --git a/etc/config/vb.defaults.properties b/etc/config/vb.defaults.properties index f52f2379630..e2b11dc175f 100644 --- a/etc/config/vb.defaults.properties +++ b/etc/config/vb.defaults.properties @@ -1,5 +1,5 @@ compilers=dotnet6vb:dotnet7vb -supportsBinary=false +supportsBinary=true needsMulti=false compilerType=vb defaultCompiler=dotnet7vb diff --git a/examples/csharp/default.cs b/examples/csharp/default.cs index a3f2cdbfbc3..8d189cb472f 100644 --- a/examples/csharp/default.cs +++ b/examples/csharp/default.cs @@ -1,4 +1,7 @@ +using System; + class Program { static int Square(int num) => num * num; + static void Main() => Console.WriteLine(Sqaure(42)); } diff --git a/examples/fsharp/default.fs b/examples/fsharp/default.fs index 779784edce7..95f06250e83 100644 --- a/examples/fsharp/default.fs +++ b/examples/fsharp/default.fs @@ -1,3 +1,8 @@ module Program let square num = num * num + +[] +let main _ = + printfn "%d" (square 42) + 0 diff --git a/examples/vb/default.vb b/examples/vb/default.vb index 443be839663..479aa066360 100644 --- a/examples/vb/default.vb +++ b/examples/vb/default.vb @@ -1,5 +1,11 @@ +Imports System + Module Program Function Square(num As Integer) As Integer Return num * num End Function + + Sub Main() + Console.WriteLine(Square(42)) + End Sub End Module diff --git a/lib/base-compiler.ts b/lib/base-compiler.ts index ec02b260810..3a97f45a1eb 100644 --- a/lib/base-compiler.ts +++ b/lib/base-compiler.ts @@ -381,7 +381,7 @@ export class BaseCompiler { } supportsObjdump() { - return this.objdumperClass !== ''; + return !!this.objdumperClass; } getObjdumpOutputFilename(defaultOutputFilename) { diff --git a/lib/compilers/dotnet.ts b/lib/compilers/dotnet.ts index e7001427d0e..054beec96c5 100644 --- a/lib/compilers/dotnet.ts +++ b/lib/compilers/dotnet.ts @@ -22,19 +22,29 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. +import fs from 'fs-extra'; import path from 'path'; +import _ from 'underscore'; -import fs from 'fs-extra'; +import * as exec from '../exec'; +import * as utils from '../utils'; +import { + BasicExecutionResult, + ExecutableExecutionOptions, + UnprocessedExecResult, +} from '../../types/execution/execution.interfaces'; import {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces'; import {BaseCompiler} from '../base-compiler'; import {DotNetAsmParser} from '../parsers/asm-parser-dotnet'; +import {ParseFilters} from '../../types/features/filters.interfaces'; class DotNetCompiler extends BaseCompiler { private targetFramework: string; private buildConfig: string; private clrBuildDir: string; private langVersion: string; + private compileToBinary = false; constructor(compilerInfo, env) { super(compilerInfo, env); @@ -104,6 +114,7 @@ class DotNetCompiler extends BaseCompiler { ${this.langVersion} false enable + ${this.compileToBinary ? 'Exe' : 'Library'} @@ -193,10 +204,53 @@ class DotNetCompiler extends BaseCompiler { return compilerResult; } - override optionsForFilter() { + override optionsForFilter(filters: ParseFilters) { + if (filters.binary) { + this.compileToBinary = true; + } + return this.compilerOptions; } + override async execBinary( + executable: string, + maxSize: number | undefined, + executeParameters: ExecutableExecutionOptions, + homeDir: string | undefined, + ): Promise { + const programDir = path.dirname(executable); + const programOutputPath = path.join(programDir, 'bin', this.buildConfig, this.targetFramework); + const programDllPath = path.join(programOutputPath, 'CompilerExplorer.dll'); + const execOptions = this.getDefaultExecOptions(); + execOptions.maxOutput = maxSize; + execOptions.timeoutMs = this.env.ceProps('binaryExecTimeoutMs', 2000); + execOptions.ldPath = _.union(this.compiler.ldPath, executeParameters.ldPath); + execOptions.customCwd = homeDir; + execOptions.appHome = homeDir; + execOptions.env = executeParameters.env; + execOptions.env.DOTNET_EnableWriteXorExecute = '0'; + execOptions.env.DOTNET_CLI_HOME = programDir; + execOptions.env.CORE_ROOT = this.clrBuildDir; + execOptions.input = executeParameters.stdin; + const execArgs = ['-p', 'System.Runtime.TieredCompilation=false', programDllPath, ...executeParameters.args]; + const corerun = path.join(this.clrBuildDir, 'corerun'); + try { + const execResult: UnprocessedExecResult = await exec.sandbox(corerun, execArgs, execOptions); + return this.processExecutionResult(execResult); + } catch (err: UnprocessedExecResult | any) { + if (err.code && err.stderr) { + return this.processExecutionResult(err); + } else { + return { + ...this.getEmptyExecutionResult(), + stdout: err.stdout ? utils.parseOutput(err.stdout) : [], + stderr: err.stderr ? utils.parseOutput(err.stderr) : [], + code: err.code !== undefined ? err.code : -1, + }; + } + } + } + async runCrossgen2(compiler, execOptions, crossgen2Path, bclPath, dllPath, options, outputPath) { const crossgen2Options = [ crossgen2Path,