Skip to content

Commit

Permalink
main merge
Browse files Browse the repository at this point in the history
  • Loading branch information
agracio committed May 3, 2024
1 parent fa0eccf commit 54f1eaa
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 210 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@ test-results*.*

test/mochawesome-report
mochawesome-report
mochawesome.json

56 changes: 0 additions & 56 deletions .jshintrc

This file was deleted.

5 changes: 4 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ tools/*.cs
tools/*.vbs
tools/nuget
*.nupkg
appveyor.*
appveyor*.*
.github
tools/coverage.js
tools/test*.js
tools/download*.js
test/mochawesome-report
mochawesome-report
mochawesome.json
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,9 @@ In that case the default typeName of `My.Edge.Samples.Startup` and methodName of

### How to: specify additional CLR assembly references in C# code

When you provide C# source code and let edge compile it for you at runtime, edge will by default reference only mscorlib.dll and System.dll assemblies. If you're using .NET Core, we automatically reference the most recent versions of the System.Runtime, System.Threading.Tasks, System.Dynamic.Runtime, and the compiler language packages, like Microsoft.CSharp. In applications that require additional assemblies you can specify them in C# code using a special hash pattern, similar to Roslyn. For example, to use ADO.NET you must reference System.Data.dll:
When you provide C# source code and let edge compile it for you at runtime, edge will by default reference only mscorlib.dll and System.dll assemblies. If you're using .NET Core, we automatically reference the most recent versions of the System. Runtime, System.Threading.Tasks, and the compiler language packages, like Microsoft.CSharp. In applications that require additional assemblies you can specify them in C# code using a special hash pattern, similar to Roslyn. For example, to use ADO.NET you must reference System.Data.dll:

#### NOTE: `#r` and `references: [ 'MyDll.dll' ]` references only work when using .NET Framework 4.5

```javascript
var add7 = edge.func(function() {/*
Expand Down
10 changes: 4 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
image:
- Visual Studio 2022
- Ubuntu2204
- macos-monterey

environment:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
matrix:
# node.js
# - nodejs: "21"
# - nodejs: "20"
# - nodejs: "18"
- nodejs: "21"
- nodejs: "20"
- nodejs: "18"
- nodejs: "16"

install:
Expand All @@ -17,14 +18,11 @@ install:
- cmd: powershell Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs) x64
- sh: nvm ls
- sh: nvm use $nodejs || nvm install $nodejs
# - sh: nvm use $nodejs
- cmd: node -v && npm -v && dotnet --version
- sh: node -v && npm -v && dotnet --version
- npm install -q
- cmd: echo npm install finished

test_script:
- cmd: echo starting tests
- cmd: node tools/test.js CI
- cmd: SET EDGE_USE_CORECLR=1 & node tools/test.js CI
- sh: EDGE_USE_CORECLR=1 node tools/test.js CI
Expand Down
2 changes: 1 addition & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
],
'xcode_settings': {
'OTHER_CFLAGS': [
'-DHAVE_CORECLR -D_NO_ASYNCRTIMP -Wno-reorder -Wno-sign-compare -Wno-mismatched-tags -Wno-missing-braces -Wno-redundant-move -Wno-deprecated-declarations -Wno-unused-value -Wno-deprecated-copy -Wno-cast-function-type -Wno-class-memaccess -Wno-unused-but-set-variable -Wno-unused-result -Wno-unused-private-field -Wno-unused-variable'
'-DHAVE_CORECLR -D_NO_ASYNCRTIMP -Wno-reorder -Wno-sign-compare -Wno-mismatched-tags -Wno-missing-braces -Wno-redundant-move -Wno-deprecated-declarations -Wno-unused-value -Wno-deprecated-copy -Wno-cast-function-type -Wno-unused-but-set-variable -Wno-unused-result -Wno-unused-private-field -Wno-unused-variable'
],
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'GCC_ENABLE_CPP_RTTI': 'YES',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"url": "http://tomasz.janczuk.org",
"twitter": "tjanczuk"
},
"version": "21.7.4",
"version": "21.7.5",
"description": "Edge.js: run .NET and Node.js in-process on Windows, Mac OS, and Linux",
"tags": [
"owin",
Expand Down
119 changes: 79 additions & 40 deletions src/double/Edge.js/dotnetcore/coreclrembedding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,30 @@ public void LoadDependencyManifest(string dependencyManifestFile)

DebugMessage("EdgeAssemblyResolver::LoadDependencyManifest (CLR) - Finished");
}

private void AddDependencies(DependencyContext dependencyContext, bool standalone)
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Adding dependencies for {0}", dependencyContext.Target.Framework);

AddCompileDependencies(dependencyContext, standalone);

Dictionary<string, string> supplementaryRuntimeLibraries = new Dictionary<string, string>();
var runtimePath = Path.GetDirectoryName(RuntimeEnvironment.RuntimePath);

foreach (RuntimeLibrary runtimeLibrary in dependencyContext.RuntimeLibraries)
{

if (!_libraries.ContainsKey(runtimeLibrary.Name) && CompileAssemblies.ContainsKey(runtimeLibrary.Name))
{
_libraries[runtimeLibrary.Name] = CompileAssemblies[runtimeLibrary.Name];
}

if (_libraries.ContainsKey(runtimeLibrary.Name) && CompileAssemblies.ContainsKey(runtimeLibrary.Name))
{
AddNativeAssemblies(dependencyContext, runtimeLibrary);
AddSupplementaryRuntime(runtimeLibrary);
continue;
}

DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing runtime dependency {1} {0}", runtimeLibrary.Name, runtimeLibrary.Type);

List<string> assets = runtimeLibrary.RuntimeAssemblyGroups.GetRuntimeAssets(RuntimeInformation.RuntimeIdentifier).ToList();
Expand All @@ -264,7 +276,7 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon

string assemblyPath;
if(runtimeLibrary.Type == "project")
assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, assetPath);
assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, assetPath);
else if (standalone)
assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(assetPath));
else
Expand All @@ -277,15 +289,15 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon

if (!File.Exists(assemblyPath))
{
assemblyPath = Path.Combine(RuntimeEnvironment.RuntimePath, Path.GetFileName(assemblyPath));
assemblyPath = Path.Combine(runtimePath, Path.GetFileName(assemblyPath));
}

if (!_libraries.ContainsKey(runtimeLibrary.Name))
{
if (File.Exists(assemblyPath))
{
_libraries[runtimeLibrary.Name] = assemblyPath;
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added runtime assembly {0}", assemblyPath);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added runtime assembly {1} from {0}", assemblyPath, runtimeLibrary.Name);
}
else
{
Expand All @@ -304,28 +316,25 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon
if (File.Exists(assemblyPath))
{
supplementaryRuntimeLibraries[libraryNameFromPath] = assemblyPath;
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added supplementary runtime assembly {0}", assemblyPath);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added supplementary runtime assembly {1} from {0}", assemblyPath, libraryNameFromPath);
}
else
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not resolve supplementary runtime assembly {0}",
assemblyPath);
}

}

if (!CompileAssemblies.ContainsKey(runtimeLibrary.Name))
{
if (File.Exists(assemblyPath))
{
CompileAssemblies[runtimeLibrary.Name] = assemblyPath;
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added compile assembly {0}",
assemblyPath);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added compile assembly {1} from {0}", assemblyPath, runtimeLibrary.Name);
}
else
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not resolve compile assembly {0}",
assemblyPath);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not resolve compile assembly {0}", assemblyPath);
}
}

Expand All @@ -336,7 +345,8 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon
}
else
{
AddRuntimeDependency(runtimeLibrary);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - RuntimeAssemblyGroups does not have RuntimeAssets or DefaultAssets");
if (!CompileAssemblies.ContainsKey(runtimeLibrary.Name)) AddCompileDependencyFromRuntime(runtimeLibrary);
}

foreach (string libraryName in supplementaryRuntimeLibraries.Keys)
Expand All @@ -354,37 +364,57 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon
CompileAssemblies[libraryName] = supplementaryRuntimeLibraries[libraryName];
}
}

List<string> nativeAssemblies = runtimeLibrary.GetRuntimeNativeAssets(dependencyContext, RuntimeInformation.RuntimeIdentifier).ToList();

if (nativeAssemblies.Any())
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Adding native dependencies for {0}", RuntimeInformation.RuntimeIdentifier);
AddNativeAssemblies(dependencyContext, runtimeLibrary);
}
}

private void AddSupplementaryRuntime(RuntimeLibrary runtimeLibrary)
{
var libraryNameFromPath = Path.GetFileNameWithoutExtension(_libraries[runtimeLibrary.Name]);
if (runtimeLibrary.Name != libraryNameFromPath)
{
_libraries.TryAdd(libraryNameFromPath, _libraries[runtimeLibrary.Name]);
CompileAssemblies.TryAdd(libraryNameFromPath, _libraries[runtimeLibrary.Name]);
}
}

private void AddNativeAssemblies(DependencyContext dependencyContext, RuntimeLibrary runtimeLibrary)
{
var runtimePath = Path.GetDirectoryName(RuntimeEnvironment.RuntimePath);
List<string> nativeAssemblies = runtimeLibrary.GetRuntimeNativeAssets(dependencyContext, RuntimeInformation.RuntimeIdentifier).ToList();

if (nativeAssemblies.Any())
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Adding native dependencies for {0}", RuntimeInformation.RuntimeIdentifier);

foreach (string nativeAssembly in nativeAssemblies)
foreach (var nativeAssembly in nativeAssemblies)
{
var nativeAssemblyPath = Path.Combine(_packagesPath, runtimeLibrary.Name, runtimeLibrary.Version, nativeAssembly.Replace('/', Path.DirectorySeparatorChar));
if (!File.Exists(nativeAssemblyPath))
{
string nativeAssemblyPath = Path.Combine(_packagesPath, runtimeLibrary.Name, runtimeLibrary.Version, nativeAssembly.Replace('/', Path.DirectorySeparatorChar));
nativeAssemblyPath = Path.Combine(runtimePath, nativeAssembly.Replace('/', Path.DirectorySeparatorChar));
}

if (File.Exists(nativeAssemblyPath))
{
_nativeLibraries[Path.GetFileNameWithoutExtension(nativeAssembly)] = nativeAssemblyPath;
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Adding native assembly {0} at {1}",
if (File.Exists(nativeAssemblyPath))
{
_nativeLibraries[Path.GetFileNameWithoutExtension(nativeAssembly)] = nativeAssemblyPath;
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Adding native assembly {0} at {1}",
Path.GetFileNameWithoutExtension(nativeAssembly), nativeAssemblyPath);
}
else
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not resolve native assembly {0} at {1}",
}
else
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not resolve native assembly {0} at {1}",
Path.GetFileNameWithoutExtension(nativeAssembly), nativeAssemblyPath);
}

}
}
}
}

private void AddRuntimeDependency(RuntimeLibrary runtimeLibrary)
private void AddCompileDependencyFromRuntime(RuntimeLibrary runtimeLibrary)
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing runtime dependency {0} using runtime path", runtimeLibrary.Name);
var runtimePath = Path.GetDirectoryName(RuntimeEnvironment.RuntimePath);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing compile dependency {1} {0} using runtime path {2}", runtimeLibrary.Name, runtimeLibrary.Type, runtimePath);

if (!CompileAssemblies.ContainsKey(runtimeLibrary.Name))
{
Expand All @@ -393,36 +423,40 @@ private void AddRuntimeDependency(RuntimeLibrary runtimeLibrary)
{
asset += ".dll";
}

var runtimePath = Path.GetDirectoryName(RuntimeEnvironment.RuntimePath);

if (asset == "runtime.native.System.dll")
{
asset = "System.dll";
}

var assemblyPath = Path.Combine(runtimePath, Path.GetFileName(asset));
if (File.Exists(assemblyPath))
{
CompileAssemblies[runtimeLibrary.Name] = assemblyPath;
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added runtime assembly {0}", assemblyPath);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added compile dependency {1} from {0}", assemblyPath, runtimeLibrary.Name);
}
else
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not add runtime dependency {0}", assemblyPath);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not add compile dependency {0}", assemblyPath);
}
}
else
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Already present in runtime dependency list, skipping");
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Already present in compile dependency list, skipping");
}
}

private void AddCompileDependencies(DependencyContext dependencyContext, bool standalone)
{
var runtimePath = Path.GetDirectoryName(RuntimeEnvironment.RuntimePath);
foreach (CompilationLibrary compileLibrary in dependencyContext.CompileLibraries)
{
if (compileLibrary.Assemblies == null || compileLibrary.Assemblies.Count == 0)
if (compileLibrary.Assemblies == null || compileLibrary.Assemblies.Count == 0 || CompileAssemblies.ContainsKey(compileLibrary.Name))
{
continue;
}

DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing compile dependency {0}", compileLibrary.Name);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing compile assembly {1} {0} {2}", compileLibrary.Name, compileLibrary.Type, compileLibrary.Assemblies[0]);

string assemblyPath;

Expand All @@ -434,6 +468,11 @@ private void AddCompileDependencies(DependencyContext dependencyContext, bool st
if(!File.Exists(assemblyPath))
assemblyPath = Path.Combine(_packagesPath, compileLibrary.Name.ToLower(), compileLibrary.Version, compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar));
}

if (!File.Exists(assemblyPath))
{
assemblyPath = Path.Combine(runtimePath, Path.GetFileName(assemblyPath));
}

if (!CompileAssemblies.ContainsKey(compileLibrary.Name))
{
Expand Down Expand Up @@ -489,15 +528,15 @@ internal void AddAssemblyPath(string assemblyPath)

internal void AddCompiler(string bootstrapDependencyManifest)
{
DebugMessage("EdgeAssemblyResolver::AddCompiler (CLR) - Adding the compiler from dependency manifest file {0}", bootstrapDependencyManifest);
DebugMessage("EdgeAssemblyResolver::AddCompiler (CLR) - Adding compiler from dependency manifest file {0}", bootstrapDependencyManifest);

DependencyContextJsonReader dependencyContextReader = new DependencyContextJsonReader();

using (FileStream bootstrapDependencyManifestStream = new FileStream(bootstrapDependencyManifest, FileMode.Open, FileAccess.Read))
{
DependencyContext compilerDependencyContext = dependencyContextReader.Read(bootstrapDependencyManifestStream);

DebugMessage("EdgeAssemblyResolver::AddCompiler (CLR) - Adding dependencies for the compiler");
DebugMessage("EdgeAssemblyResolver::AddCompiler (CLR) - Adding dependencies for compiler");

AddDependencies(compilerDependencyContext, false);

Expand Down
Loading

0 comments on commit 54f1eaa

Please sign in to comment.