diff options
author | Steve <hez2010@outlook.com> | 2022-11-28 01:14:35 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-27 10:14:35 -0600 |
commit | 75b9d30485795eb176b490ecab550ffca891f737 (patch) | |
tree | e1d54c97a88d1e246417f9dc10ad37684c15f1e6 /lib/compilers/dotnet.ts | |
parent | 01e67e60b942e0dedb55f740bd27250cbe8da671 (diff) | |
download | compiler-explorer-75b9d30485795eb176b490ecab550ffca891f737.tar.gz compiler-explorer-75b9d30485795eb176b490ecab550ffca891f737.zip |
Support trunk and execution for .NET (#4351)gh-5100
* Support trunk and execution for .NET
* Adjust compilers order
* Support stdin
* Update samples
Diffstat (limited to 'lib/compilers/dotnet.ts')
-rw-r--r-- | lib/compilers/dotnet.ts | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/lib/compilers/dotnet.ts b/lib/compilers/dotnet.ts index e7001427d..054beec96 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 { <LangVersion>${this.langVersion}</LangVersion> <EnableDefaultCompileItems>false</EnableDefaultCompileItems> <Nullable>enable</Nullable> + <OutputType>${this.compileToBinary ? 'Exe' : 'Library'}</OutputType> </PropertyGroup> <ItemGroup> <Compile Include="${sourceFile}" /> @@ -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<BasicExecutionResult> { + 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, |