Skip to content

Commit

Permalink
Disable multithreading for dotnet
Browse files Browse the repository at this point in the history
  • Loading branch information
x0k committed Dec 6, 2024
1 parent 0a715ac commit fa1860a
Show file tree
Hide file tree
Showing 97 changed files with 413 additions and 379 deletions.
2 changes: 1 addition & 1 deletion apps/ppp/src/adapters/runtime/dotnet/info.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<p>
Your code is compiled by the Roslyn compiler (compiled to WebAssembly with a
several .NET assemblies) and is executed in the context of the current page.
several .NET assemblies) and is executed in a web worker environment.
</p>

<p>Available libraries:</p>
Expand Down
4 changes: 2 additions & 2 deletions apps/ppp/src/pages/editor/_runtimes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import RustWorker from "@/adapters/runtime/rust/worker?worker";
import GleamWorker from "@/adapters/runtime/gleam/worker?worker";
import JavaWorker from "@/adapters/runtime/java/worker?worker";
import RubyWorker from "@/adapters/runtime/ruby/worker?worker";
import { makeDotnetCompiler } from '@/adapters/runtime/dotnet/compiler-factory'
import DotnetWorker from '@/adapters/runtime/dotnet/worker?worker';

import phpProgram from './_program.php?raw';
import tsProgram from './_program.ts?raw';
Expand Down Expand Up @@ -60,7 +60,7 @@ export const RUNTIMES: Record<Language, Runtime> = {
},
[Language.CSharp]: {
initialValue: csProgram,
compilerFactory: makeDotnetCompiler,
compilerFactory: makeRemoteCompilerFactory(DotnetWorker),
},
[Language.Java]: {
initialValue: javaProgram,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
import { makeRemoteTestCompilerFactory } from "testing/actor";

import Worker from "@/adapters/runtime/dotnet/test-worker?worker";

// Only type imports are allowed

import type { TestCompilerFactory } from "testing";
import { makeExecutionCode } from "dotnet-runtime";

import { DotnetTestCompilerFactory } from "@/adapters/runtime/dotnet/test-compiler-factory";
import type { DotnetTestWorkerConfig } from "@/adapters/runtime/dotnet/test-worker";

import type { Input, Output } from "../tests-data";

import definitions from "./definitions.cs?raw";
import executionCode from "./execution-code.cs?raw";
export const factory: TestCompilerFactory<Input, Output> =
makeRemoteTestCompilerFactory(
Worker,
(
ctx,
{ dotnetTestCompilerFactory, makeExecutionCode }: DotnetTestWorkerConfig
) => {
const definitions = `struct Args {
[JsonPropertyName("base")]
public int Base { get; set; }
[JsonPropertyName("amount")]
public int Amount { get; set; }
export const factory: TestCompilerFactory<Input, Output> = async (ctx, out) => {
return new DotnetTestCompilerFactory(out).create(ctx, {
executionCode: makeExecutionCode({
additionalDefinitions: definitions,
executionCode: executionCode,
}),
});
[JsonPropertyName("paymentSystem")]
public string SystemType { get; set; }
}`;
const executionCode = `var args = JsonSerializer.Deserialize<Args>(jsonArguments);
var type = args.SystemType switch {
"paypal" => SystemType.PayPal,
"webmoney" => SystemType.WebMoney,
"catbank" => SystemType.CatBank,
_ => throw new System.Exception("Unknown payment type")
};
var result = Solution.Payment(type, args.Base, args.Amount);
`;
return dotnetTestCompilerFactory.create(ctx, {
executionCode: makeExecutionCode({
additionalDefinitions: definitions,
executionCode,
}),
});
}
);
2 changes: 1 addition & 1 deletion packages/dotnet-runtime/compiler/compiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CompressionEnabled>false</CompressionEnabled>
<!-- <RunAOTCompilation>true</RunAOTCompilation> -->
<WasmEnableThreads>true</WasmEnableThreads>
<!-- <WasmEnableThreads>true</WasmEnableThreads> -->
<Nullable>enable</Nullable>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>full</TrimMode>
Expand Down
257 changes: 3 additions & 254 deletions packages/dotnet-runtime/probe/index.js
Original file line number Diff line number Diff line change
@@ -1,256 +1,5 @@
import { dotnet } from "./compiler/dotnet.js";

const { setModuleImports, getAssemblyExports, getConfig } =
await dotnet.create();

setModuleImports("main.js", {
logger: {
debug: (msg) => console.log(msg),
info: (msg) => console.info(msg),
warn: (msg) => console.warn(msg),
error: (msg) => console.error(msg),
},
const worker = new Worker(new URL("./worker.js", import.meta.url), {
type: "module"
});

const config = getConfig();
const exports = await getAssemblyExports(config.mainAssemblyName);

const libs = [
"Humanizer.dll",
"Microsoft.Bcl.AsyncInterfaces.dll",
"Microsoft.CSharp.dll",
// "Microsoft.CodeAnalysis.CSharp.Workspaces.dll",
// "Microsoft.CodeAnalysis.CSharp.dll",
// "Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll",
// "Microsoft.CodeAnalysis.VisualBasic.dll",
// "Microsoft.CodeAnalysis.Workspaces.dll",
// "Microsoft.CodeAnalysis.dll",
// "Microsoft.JSInterop.WebAssembly.dll",
// "Microsoft.JSInterop.dll",
// "Microsoft.VisualBasic.Core.dll",
// "Microsoft.VisualBasic.dll",
// "Microsoft.Win32.Primitives.dll",
// "Microsoft.Win32.Registry.dll",
"System.AppContext.dll",
"System.Buffers.dll",
"System.Collections.Concurrent.dll",
"System.Collections.Immutable.dll",
"System.Collections.NonGeneric.dll",
"System.Collections.Specialized.dll",
"System.Collections.dll",
// "System.ComponentModel.Annotations.dll",
// "System.ComponentModel.DataAnnotations.dll",
// "System.ComponentModel.EventBasedAsync.dll",
// "System.ComponentModel.Primitives.dll",
// "System.ComponentModel.TypeConverter.dll",
// "System.ComponentModel.dll",
// "System.Composition.AttributedModel.dll",
// "System.Composition.Convention.dll",
// "System.Composition.Hosting.dll",
// "System.Composition.Runtime.dll",
// "System.Composition.TypedParts.dll",
// "System.Configuration.dll",
"System.Console.dll",
"System.Core.dll",
// "System.Data.Common.dll",
// "System.Data.DataSetExtensions.dll",
// "System.Data.dll",
// "System.Diagnostics.Contracts.dll",
"System.Diagnostics.Debug.dll",
// "System.Diagnostics.DiagnosticSource.dll",
// "System.Diagnostics.FileVersionInfo.dll",
// "System.Diagnostics.Process.dll",
// "System.Diagnostics.StackTrace.dll",
// "System.Diagnostics.TextWriterTraceListener.dll",
// "System.Diagnostics.Tools.dll",
// "System.Diagnostics.TraceSource.dll",
// "System.Diagnostics.Tracing.dll",
// "System.Drawing.Primitives.dll",
// "System.Drawing.dll",
// "System.Dynamic.Runtime.dll",
// "System.Formats.Asn1.dll",
// "System.Formats.Tar.dll",
"System.Globalization.Calendars.dll",
"System.Globalization.Extensions.dll",
"System.Globalization.dll",
// "System.IO.Compression.Brotli.dll",
// "System.IO.Compression.FileSystem.dll",
// "System.IO.Compression.ZipFile.dll",
// "System.IO.Compression.dll",
// "System.IO.FileSystem.AccessControl.dll",
// "System.IO.FileSystem.DriveInfo.dll",
// "System.IO.FileSystem.Primitives.dll",
// "System.IO.FileSystem.Watcher.dll",
"System.IO.FileSystem.dll",
// "System.IO.IsolatedStorage.dll",
// "System.IO.MemoryMappedFiles.dll",
// "System.IO.Pipelines.dll",
// "System.IO.Pipes.AccessControl.dll",
// "System.IO.Pipes.dll",
"System.IO.UnmanagedMemoryStream.dll",
"System.IO.dll",
"System.Linq.Expressions.dll",
"System.Linq.Parallel.dll",
"System.Linq.Queryable.dll",
"System.Linq.dll",
"System.Memory.dll",
"System.Net.Http.Json.dll",
"System.Net.Http.dll",
"System.Net.HttpListener.dll",
// "System.Net.Mail.dll",
"System.Net.NameResolution.dll",
"System.Net.NetworkInformation.dll",
// "System.Net.Ping.dll",
"System.Net.Primitives.dll",
// "System.Net.Quic.dll",
"System.Net.Requests.dll",
// "System.Net.Security.dll",
// "System.Net.ServicePoint.dll",
"System.Net.Sockets.dll",
"System.Net.WebClient.dll",
"System.Net.WebHeaderCollection.dll",
// "System.Net.WebProxy.dll",
// "System.Net.WebSockets.Client.dll",
// "System.Net.WebSockets.dll",
"System.Net.dll",
"System.Numerics.Vectors.dll",
"System.Numerics.dll",
"System.ObjectModel.dll",
"System.Private.CoreLib.dll",
// "System.Private.DataContractSerialization.dll",
"System.Private.Uri.dll",
// "System.Private.Xml.Linq.dll",
// "System.Private.Xml.dll",
// "System.Reflection.DispatchProxy.dll",
// "System.Reflection.Emit.ILGeneration.dll",
// "System.Reflection.Emit.Lightweight.dll",
// "System.Reflection.Emit.dll",
// "System.Reflection.Extensions.dll",
// "System.Reflection.Metadata.dll",
// "System.Reflection.Primitives.dll",
// "System.Reflection.TypeExtensions.dll",
"System.Reflection.dll",
"System.Resources.Reader.dll",
"System.Resources.ResourceManager.dll",
"System.Resources.Writer.dll",
// "System.Runtime.CompilerServices.Unsafe.dll",
// "System.Runtime.CompilerServices.VisualC.dll",
"System.Runtime.Extensions.dll",
"System.Runtime.Handles.dll",
// "System.Runtime.InteropServices.JavaScript.dll",
"System.Runtime.InteropServices.RuntimeInformation.dll",
"System.Runtime.InteropServices.dll",
// "System.Runtime.Intrinsics.dll",
// "System.Runtime.Loader.dll",
// "System.Runtime.Numerics.dll",
// "System.Runtime.Serialization.Formatters.dll",
// "System.Runtime.Serialization.Json.dll",
// "System.Runtime.Serialization.Primitives.dll",
// "System.Runtime.Serialization.Xml.dll",
// "System.Runtime.Serialization.dll",
"System.Runtime.dll",
// "System.Security.AccessControl.dll",
// "System.Security.Claims.dll",
// "System.Security.Cryptography.Algorithms.dll",
// "System.Security.Cryptography.Cng.dll",
// "System.Security.Cryptography.Csp.dll",
// "System.Security.Cryptography.Encoding.dll",
// "System.Security.Cryptography.OpenSsl.dll",
// "System.Security.Cryptography.Primitives.dll",
// "System.Security.Cryptography.X509Certificates.dll",
// "System.Security.Cryptography.dll",
// "System.Security.Principal.Windows.dll",
"System.Security.Principal.dll",
"System.Security.SecureString.dll",
"System.Security.dll",
// "System.ServiceModel.Web.dll",
// "System.ServiceProcess.dll",
// "System.Text.Encoding.CodePages.dll",
"System.Text.Encoding.Extensions.dll",
"System.Text.Encoding.dll",
"System.Text.Encodings.Web.dll",
"System.Text.Json.dll",
"System.Text.RegularExpressions.dll",
// "System.Threading.Channels.dll",
// "System.Threading.Overlapped.dll",
// "System.Threading.Tasks.Dataflow.dll",
"System.Threading.Tasks.Extensions.dll",
"System.Threading.Tasks.Parallel.dll",
"System.Threading.Tasks.dll",
"System.Threading.Thread.dll",
"System.Threading.ThreadPool.dll",
"System.Threading.Timer.dll",
"System.Threading.dll",
// "System.Transactions.Local.dll",
"System.Transactions.dll",
"System.ValueTuple.dll",
"System.Web.HttpUtility.dll",
// "System.Web.dll",
// "System.Windows.dll",
// "System.Xml.Linq.dll",
// "System.Xml.ReaderWriter.dll",
// "System.Xml.Serialization.dll",
// "System.Xml.XDocument.dll",
// "System.Xml.XPath.XDocument.dll",
// "System.Xml.XPath.dll",
// "System.Xml.XmlDocument.dll",
// "System.Xml.XmlSerializer.dll",
// "System.Xml.dll",
"System.dll",
"WebAssembly.dll",
// "WindowsBase.dll",
"compiler.dll",
"mscorlib.dll",
"netstandard.dll",
];

let status = await exports.Compiler.Init(`${location.origin}/lib`, libs);
if (status !== 0) {
throw new Error("Init failed");
}

status = await exports.Compiler.Compile([
`using System;
namespace ppp
{
public class Program
{
public static int Payment(int baseValue, int amount)
{
Console.WriteLine("Called payment");
return baseValue + amount;
}
}
}
`,
`using System.Collections.Generic;
using System.Text.Json;
using System.Diagnostics.CodeAnalysis;
namespace test
{
public class Program {
[RequiresUnreferencedCode("Calls System.Text.Json.JsonSerializer.Serialize<TValue>(TValue, JsonSerializerOptions)")]
public static string Test(string jsonArguments) {
var args = JsonSerializer.Deserialize<List<int>>(jsonArguments);
var result = ppp.Program.Payment(args[0], args[1]);
return JsonSerializer.Serialize(result);
}
}
}
`,
]);
if (status !== 0) {
throw new Error(`Compilation failed: ${status}`);
}

status = await exports.Compiler.Run("test.Program", "Test", [JSON.stringify([1, 2])]);
if (status !== 0) {
throw new Error("Run failed");
}

const result = await exports.Compiler.GetResultAsString();

console.log(result);

await exports.Compiler.DisposeAssembly();
worker.postMessage("start")
Loading

0 comments on commit fa1860a

Please sign in to comment.