Changes needed to make dotnet work with nsjail (#3307)

This commit is contained in:
Patrick Quist
2022-02-01 08:39:55 +01:00
committed by GitHub
parent 5f0a3a7f23
commit c28d535c1e
10 changed files with 98 additions and 53 deletions

View File

@@ -5,6 +5,7 @@ include:
exclude:
- lib/asm-docs/generated/asm-docs-*.js
- lib/compilers/fake-for-test.js
- lib/**/*.d.ts
report-dir: ./out/coverage
reporter:
- lcov

View File

@@ -0,0 +1,17 @@
compilers=&csharp
supportsBinary=false
needsMulti=false
compilerType=csharp
defaultCompiler=dotnet601csharp
group.csharp.compilers=dotnet601csharp
compiler.dotnet601csharp.exe=/opt/compiler-explorer/dotnet-v6.0.1/bin/coreclr/Linux.x64.Checked/.dotnet/dotnet
compiler.dotnet601csharp.name=.NET 6.0.101
compiler.dotnet601csharp.clrDir=/opt/compiler-explorer/dotnet-v6.0.1/bin/coreclr/Linux.x64.Checked
compiler.dotnet601csharp.runtimeId=linux-x64
compiler.dotnet601csharp.targetFramework=net6.0
compiler.dotnet601csharp.buildConfig=Release
compiler.dotnet601csharp.additionalSources=
compiler.dotnet601csharp.langVersion=latest
compiler.dotnet601csharp.nugetPackages=/opt/compiler-explorer/dotnet_nuget-v6.0.0/packages

View File

@@ -1,10 +1,8 @@
compilers=&csharp
compilers=dotnet6csharp
supportsBinary=false
needsMulti=false
compilerType=csharp
defaultCompiler=dotnet6csharp:dotnettrunkcsharp
group.csharp.compilers=dotnet6csharp:dotnettrunkcsharp
defaultCompiler=dotnet6csharp
compiler.dotnet6csharp.exe=/opt/compiler-explorer/dotnet-v6.0.1/bin/coreclr/Linux.x64.Checked/.dotnet/dotnet
compiler.dotnet6csharp.name=.NET 6.0.101
@@ -14,12 +12,3 @@ compiler.dotnet6csharp.targetFramework=net6.0
compiler.dotnet6csharp.buildConfig=Release
compiler.dotnet6csharp.additionalSources=
compiler.dotnet6csharp.langVersion=latest
compiler.dotnettrunkcsharp.exe=/opt/compiler-explorer/dotnet-trunk/bin/coreclr/Linux.x64.Checked/.dotnet/dotnet
compiler.dotnettrunkcsharp.name=.NET Trunk
compiler.dotnettrunkcsharp.clrDir=/opt/compiler-explorer/dotnet-trunk/bin/coreclr/Linux.x64.Checked
compiler.dotnettrunkcsharp.runtimeId=linux-x64
compiler.dotnettrunkcsharp.targetFramework=net6.0
compiler.dotnettrunkcsharp.buildConfig=Release
compiler.dotnettrunkcsharp.additionalSources=
compiler.dotnettrunkcsharp.langVersion=preview

View File

@@ -0,0 +1,17 @@
compilers=&fsharp
supportsBinary=false
needsMulti=false
compilerType=fsharp
defaultCompiler=dotnet601fsharp
group.fsharp.compilers=dotnet601fsharp
compiler.dotnet601fsharp.exe=/opt/compiler-explorer/dotnet-v6.0.1/bin/coreclr/Linux.x64.Checked/.dotnet/dotnet
compiler.dotnet601fsharp.name=.NET 6.0.101
compiler.dotnet601fsharp.clrDir=/opt/compiler-explorer/dotnet-v6.0.1/bin/coreclr/Linux.x64.Checked
compiler.dotnet601fsharp.runtimeId=linux-x64
compiler.dotnet601fsharp.targetFramework=net6.0
compiler.dotnet601fsharp.buildConfig=Release
compiler.dotnet601fsharp.additionalSources=
compiler.dotnet601fsharp.langVersion=latest
compiler.dotnet601fsharp.nugetPackages=/opt/compiler-explorer/dotnet_nuget-v6.0.0/packages

View File

@@ -1,11 +1,9 @@
compilers=&fsharp
compilers=dotnet6fsharp
supportsBinary=false
needsMulti=false
compilerType=fsharp
defaultCompiler=dotnet6fsharp
group.fsharp.compilers=dotnet6fsharp:dotnettrunkfsharp
compiler.dotnet6fsharp.exe=/opt/compiler-explorer/dotnet-v6.0.1/bin/coreclr/Linux.x64.Checked/.dotnet/dotnet
compiler.dotnet6fsharp.name=.NET 6.0.101
compiler.dotnet6fsharp.clrDir=/opt/compiler-explorer/dotnet-v6.0.1/bin/coreclr/Linux.x64.Checked
@@ -14,12 +12,3 @@ compiler.dotnet6fsharp.targetFramework=net6.0
compiler.dotnet6fsharp.buildConfig=Release
compiler.dotnet6fsharp.additionalSources=
compiler.dotnet6fsharp.langVersion=latest
compiler.dotnettrunkfsharp.exe=/opt/compiler-explorer/dotnet-trunk/bin/coreclr/Linux.x64.Checked/.dotnet/dotnet
compiler.dotnettrunkfsharp.name=.NET Trunk
compiler.dotnettrunkfsharp.clrDir=/opt/compiler-explorer/dotnet-trunk/bin/coreclr/Linux.x64.Checked
compiler.dotnettrunkfsharp.runtimeId=linux-x64
compiler.dotnettrunkfsharp.targetFramework=net6.0
compiler.dotnettrunkfsharp.buildConfig=Release
compiler.dotnettrunkfsharp.additionalSources=
compiler.dotnettrunkfsharp.langVersion=latest

View File

@@ -0,0 +1,17 @@
compilers=&vb
supportsBinary=false
needsMulti=false
compilerType=vb
defaultCompiler=dotnet601vb
group.vb.compilers=dotnet601vb
compiler.dotnet601vb.exe=/opt/compiler-explorer/dotnet-v6.0.1/bin/coreclr/Linux.x64.Checked/.dotnet/dotnet
compiler.dotnet601vb.name=.NET 6.0.101
compiler.dotnet601vb.clrDir=/opt/compiler-explorer/dotnet-v6.0.1/bin/coreclr/Linux.x64.Checked
compiler.dotnet601vb.runtimeId=linux-x64
compiler.dotnet601vb.targetFramework=net6.0
compiler.dotnet601vb.buildConfig=Release
compiler.dotnet601vb.additionalSources=
compiler.dotnet601vb.langVersion=latest
compiler.dotnet601vb.nugetPackages=/opt/compiler-explorer/dotnet_nuget-v6.0.0/packages

View File

@@ -1,11 +1,9 @@
compilers=&vb
compilers=dotnet6vb
supportsBinary=false
needsMulti=false
compilerType=vb
defaultCompiler=dotnet6vb
group.vb.compilers=dotnet6vb:dotnettrunkvb
compiler.dotnet6vb.exe=/opt/compiler-explorer/dotnet-v6.0.1/bin/coreclr/Linux.x64.Checked/.dotnet/dotnet
compiler.dotnet6vb.name=.NET 6.0.101
compiler.dotnet6vb.clrDir=/opt/compiler-explorer/dotnet-v6.0.1/bin/coreclr/Linux.x64.Checked
@@ -14,12 +12,3 @@ compiler.dotnet6vb.targetFramework=net6.0
compiler.dotnet6vb.buildConfig=Release
compiler.dotnet6vb.additionalSources=
compiler.dotnet6vb.langVersion=latest
compiler.dotnettrunkvb.exe=/opt/compiler-explorer/dotnet-trunk/bin/coreclr/Linux.x64.Checked/.dotnet/dotnet
compiler.dotnettrunkvb.name=.NET Trunk
compiler.dotnettrunkvb.clrDir=/opt/compiler-explorer/dotnet-trunk/bin/coreclr/Linux.x64.Checked
compiler.dotnettrunkvb.runtimeId=linux-x64
compiler.dotnettrunkvb.targetFramework=net6.0
compiler.dotnettrunkvb.buildConfig=Release
compiler.dotnettrunkvb.additionalSources=
compiler.dotnettrunkvb.langVersion=latest

View File

@@ -10,7 +10,7 @@ log_level: FATAL
rlimit_as_type: INF
rlimit_cpu_type: SOFT
rlimit_fsize: 1024 # 1GB
rlimit_nofile: 100
rlimit_nofile: 150
uidmap {
inside_id: "10240"

12
lib/base-compiler.d.ts vendored Normal file
View File

@@ -0,0 +1,12 @@
export declare class BaseCompiler {
constructor(compilerInfo, env);
public compiler;
public lang;
public outputFilebase: string;
public compilerProps: (key: string) => string;
public getOutputFilename(path: string, filename: string): string;
public exec(filepath: string, args: string[], execOptions);
public parseCompilationOutput(result, filename: string);
public getDefaultExecOptions();
public runCompiler(compiler: string, args: string[], filename: string, execOptions);
}

View File

@@ -26,13 +26,29 @@ import path from 'path';
import fs from 'fs-extra';
/// <reference types="../base-compiler" />
import { BaseCompiler } from '../base-compiler';
class DotNetCompiler extends BaseCompiler {
private rID: string;
private targetFramework: string;
private buildConfig: string;
private nugetPackagesPath: string;
private clrBuildDir: string;
private additionalSources: string;
private langVersion: string;
get rID() { return this.compilerProps(`compiler.${this.compiler.id}.runtimeId`); }
get targetFramework() { return this.compilerProps(`compiler.${this.compiler.id}.targetFramework`); }
get buildConfig() { return this.compilerProps(`compiler.${this.compiler.id}.buildConfig`); }
constructor(compilerInfo, env) {
super(compilerInfo, env);
this.rID = this.compilerProps(`compiler.${this.compiler.id}.runtimeId`);
this.targetFramework = this.compilerProps(`compiler.${this.compiler.id}.targetFramework`);
this.buildConfig = this.compilerProps(`compiler.${this.compiler.id}.buildConfig`);
this.nugetPackagesPath = this.compilerProps(`compiler.${this.compiler.id}.nugetPackages`);
this.clrBuildDir = this.compilerProps(`compiler.${this.compiler.id}.clrDir`);
this.additionalSources = this.compilerProps(`compiler.${this.compiler.id}.additionalSources`);
this.langVersion = this.compilerProps(`compiler.${this.compiler.id}.langVersion`);
}
get compilerOptions() {
return ['publish', '-c', this.buildConfig, '--self-contained', '--runtime', this.rID, '-v', 'q', '--nologo'];
@@ -55,10 +71,9 @@ class DotNetCompiler extends BaseCompiler {
const programDir = path.dirname(inputFileName);
const sourceFile = path.basename(inputFileName);
const clrBuildDir = this.compilerProps(`compiler.${this.compiler.id}.clrDir`);
const projectFilePath = path.join(programDir, `CompilerExplorer${this.lang.extensions[0]}proj`);
const crossgen2Path = path.join(clrBuildDir, 'crossgen2', 'crossgen2.dll');
const crossgen2Path = path.join(this.clrBuildDir, 'crossgen2', 'crossgen2.dll');
const programPublishPath = path.join(
programDir,
@@ -70,8 +85,6 @@ class DotNetCompiler extends BaseCompiler {
);
const programDllPath = path.join(programPublishPath, 'CompilerExplorer.dll');
const additionalSources = this.compilerProps(`compiler.${this.compiler.id}.additionalSources`);
const langVersion = this.compilerProps(`compiler.${this.compiler.id}.langVersion`);
const projectFileContent =
`<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
@@ -79,11 +92,11 @@ class DotNetCompiler extends BaseCompiler {
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<AssemblyName>CompilerExplorer</AssemblyName>
<LangVersion>${langVersion}</LangVersion>
<LangVersion>${this.langVersion}</LangVersion>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<EnablePreviewFeatures>${langVersion === 'preview' ? 'true' : 'false'}</EnablePreviewFeatures>
<EnablePreviewFeatures>${this.langVersion === 'preview' ? 'true' : 'false'}</EnablePreviewFeatures>
<RestoreAdditionalProjectSources>
https://api.nuget.org/v3/index.json;${additionalSources ? additionalSources : ''}
https://api.nuget.org/v3/index.json;${this.additionalSources ? this.additionalSources : ''}
</RestoreAdditionalProjectSources>
</PropertyGroup>
<ItemGroup>
@@ -92,6 +105,11 @@ class DotNetCompiler extends BaseCompiler {
</Project>
`;
execOptions.env.DOTNET_CLI_TELEMETRY_OPTOUT = 'true';
execOptions.env.DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 'true';
execOptions.env.NUGET_PACKAGES = this.nugetPackagesPath;
execOptions.env.DOTNET_NOLOGO='true';
execOptions.customCwd = programDir;
await fs.writeFile(projectFilePath, projectFileContent);
@@ -128,7 +146,7 @@ class DotNetCompiler extends BaseCompiler {
programPublishPath,
programDllPath,
crossgen2Options,
this.getOutputFilename(programDir, ''),
this.getOutputFilename(programDir, this.outputFilebase),
);
if (crossgen2Result.code !== 0) {
@@ -142,10 +160,6 @@ class DotNetCompiler extends BaseCompiler {
return this.compilerOptions;
}
getOutputFilename(dirPath) {
return path.join(dirPath, `output.s`);
}
cleanAsm(stdout) {
let cleanedAsm = '';