From 185af6c868d8a282514a560d286ca128abfe686e Mon Sep 17 00:00:00 2001 From: agracio Date: Fri, 27 Dec 2024 20:28:01 +0000 Subject: [PATCH 1/4] updating Nuget package --- src/double/Edge.js/dotnet/EdgeJs.cs | 70 +++++++++++++++++----- test/double/double_test/DoubleEdge.cs | 2 +- test/double/double_test/double_test.csproj | 2 +- test/double/double_test/nuget.config | 6 ++ tools/build_double.bat | 42 ++++++++----- tools/nuget/README.md | 6 +- tools/nuget/edge.nuspec | 2 +- 7 files changed, 95 insertions(+), 35 deletions(-) create mode 100644 test/double/double_test/nuget.config diff --git a/src/double/Edge.js/dotnet/EdgeJs.cs b/src/double/Edge.js/dotnet/EdgeJs.cs index 8fccd998..88a4f005 100644 --- a/src/double/Edge.js/dotnet/EdgeJs.cs +++ b/src/double/Edge.js/dotnet/EdgeJs.cs @@ -2,7 +2,6 @@ using System.ComponentModel; using System.Collections.Generic; using System.IO; -using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Threading; @@ -18,6 +17,7 @@ public class Edge static ManualResetEvent waitHandle = new ManualResetEvent(false); private static string edgeDirectory; private static List>> compiledFuncs = new List>>(); + private static readonly bool DebugMode = Environment.GetEnvironmentVariable("EDGE_DEBUG") == "1"; static Edge() { @@ -34,6 +34,14 @@ static Edge() ? Path.GetDirectoryName(asm.Location) : Path.GetDirectoryName(codeBase.LocalPath); } + + internal static void DebugMessage(string message, params object[] parameters) + { + if (DebugMode) + { + Console.WriteLine(message, parameters); + } + } static string assemblyDirectory; static string AssemblyDirectory @@ -56,7 +64,7 @@ static string AssemblyDirectory } } - // in case we want to set this path and not use an enviroment var + // in case we want to set this path and not use an environment var public static void SetAssemblyDirectory(string folder) { assemblyDirectory = folder; @@ -96,6 +104,28 @@ public static void Uninitialize() [DllImport("kernel32.dll", EntryPoint = "LoadLibrary")] static extern int LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpLibFileName); + private static string GetLibNodeDll(string arch) + { + string path = ResolveUnicodeCharactersInPath(string.Format(@"{0}\edge\{1}\libnode.dll", AssemblyDirectory, arch)); + + if (!File.Exists(path)) + { + path = string.Format(@"edge\{0}\libnode.dll", arch); + } + + DebugMessage("libnode path: {0}", path); + return path; + } + + private static string ResolveUnicodeCharactersInPath(string path) + { + // Workaround for Unicode characters in path + StringBuilder shortPath = new StringBuilder(255); + GetShortPathName(path, shortPath, shortPath.Capacity); + return shortPath.ToString(); + // End workaround for Unicode characters in path + } + public static Func> Func(string code) { if (!initialized) @@ -107,14 +137,15 @@ public static Func> Func(string code) Func nodeStart; if (IntPtr.Size == 4) { - LoadLibrary(AssemblyDirectory + @"\edge\x86\libnode.dll"); + LoadLibrary(GetLibNodeDll("x86")); nodeStart = NodeStartx86; } else if (IntPtr.Size == 8) { - LoadLibrary(AssemblyDirectory + @"\edge\x64\libnode.dll"); + LoadLibrary(GetLibNodeDll("x64")); nodeStart = NodeStartx64; } + else { throw new InvalidOperationException( @@ -125,23 +156,34 @@ public static Func> Func(string code) { List argv = new List(); argv.Add("node"); - string node_params = Environment.GetEnvironmentVariable("EDGE_NODE_PARAMS"); - if (!string.IsNullOrEmpty(node_params)) + var nodeParams = Environment.GetEnvironmentVariable("EDGE_NODE_PARAMS"); + if (!string.IsNullOrEmpty(nodeParams)) { - foreach (string p in node_params.Split(' ')) + foreach (string p in nodeParams.Split(' ')) { argv.Add(p); } } - // Workaround for unicode characters in path - string path = AssemblyDirectory + "\\edge\\double_edge.js"; - StringBuilder shortPath = new StringBuilder(255); - int result = GetShortPathName(path, shortPath, shortPath.Capacity); - argv.Add(shortPath.ToString()); - // End workaround for unicode characters in path + var path = ResolveUnicodeCharactersInPath(AssemblyDirectory + @"\edge\double_edge.js"); + var edgeDll = ResolveUnicodeCharactersInPath(Path.Combine(edgeDirectory, "EdgeJs.dll")); + + if (File.Exists(path) && File.Exists(edgeDll)) + { + DebugMessage("double_edge.js path: {0}", path); + DebugMessage("-EdgeJs:{0}", edgeDll); + argv.Add(path); + argv.Add(string.Format("-EdgeJs:{0}", edgeDll)); + } + else + { + DebugMessage("double_edge.js path: {0}", @"edge\double_edge.js"); + DebugMessage("-EdgeJs:EdgeJs.dll"); + + argv.Add(@"edge\double_edge.js"); + argv.Add("-EdgeJs:EdgeJs.dll"); + } - argv.Add(string.Format("-EdgeJs:{0}", Path.Combine(edgeDirectory, "EdgeJs.dll"))); nodeStart(argv.Count, argv.ToArray()); }, 1048576); // Force typical Windows stack size because less is liable to break diff --git a/test/double/double_test/DoubleEdge.cs b/test/double/double_test/DoubleEdge.cs index dcd7d238..e39f7b1a 100644 --- a/test/double/double_test/DoubleEdge.cs +++ b/test/double/double_test/DoubleEdge.cs @@ -63,7 +63,7 @@ public void SucceedsCheckingNodeVersion() ")(".NET").Result; System.Console.WriteLine(result); - Assert.AreEqual(result, "v20.12.2"); + Assert.AreEqual(result, "v22.12.0"); } [Test] diff --git a/test/double/double_test/double_test.csproj b/test/double/double_test/double_test.csproj index c903c810..d87655ee 100644 --- a/test/double/double_test/double_test.csproj +++ b/test/double/double_test/double_test.csproj @@ -8,7 +8,7 @@ - + diff --git a/test/double/double_test/nuget.config b/test/double/double_test/nuget.config new file mode 100644 index 00000000..c7f8ff1b --- /dev/null +++ b/test/double/double_test/nuget.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/tools/build_double.bat b/tools/build_double.bat index 4c6762ec..880f4dce 100644 --- a/tools/build_double.bat +++ b/tools/build_double.bat @@ -7,26 +7,37 @@ if "%1" equ "" ( exit /b -1 ) +FOR /F "tokens=* USEBACKQ" %%F IN (`node -p process.arch`) DO (SET ARCH=%%F) +for /F "delims=." %%a in ("%1") do set MAJORVERSION=%%a +set MAJORVERSION=%MAJORVERSION: =% + + call :build_lib if %ERRORLEVEL% neq 0 exit /b -1 call :download_node %1 if %ERRORLEVEL% neq 0 exit /b -1 -call :build_node %1 x86 -if %ERRORLEVEL% neq 0 exit /b -1 +if %MAJORVERSION% LSS 23 ( + call :build_node %1 x86 + if %ERRORLEVEL% neq 0 exit /b -1 +) call :build_node %1 x64 if %ERRORLEVEL% neq 0 exit /b -1 -call :download_node_exe %1 -if %ERRORLEVEL% neq 0 exit /b -1 -call :build_edge %1 x86 ia32 -if %ERRORLEVEL% neq 0 exit /b -1 +@REM call :download_node_exe %1 +@REM if %ERRORLEVEL% neq 0 exit /b -1 + call :build_edge %1 x64 x64 if %ERRORLEVEL% neq 0 exit /b -1 +if %MAJORVERSION% LSS 23 ( + call :build_edge %1 x86 ia32 + if %ERRORLEVEL% neq 0 exit /b -1 +) + call :clean_nuget_package if %ERRORLEVEL% neq 0 exit /b -1 @@ -39,14 +50,14 @@ REM =========================================================== :build_lib echo :build_lib -if exist "%SELF%\build\nuget\lib\net45" ( - echo "%SELF%\build\nuget\lib\net45" already exists. - exit /b 0 - ) +@REM if exist "%SELF%\build\nuget\lib\net462" ( +@REM echo "%SELF%\build\nuget\lib\net462" already exists. +@REM exit /b 0 +@REM ) -mkdir "%SELF%\..\src\double\Edge.js\bin\Release\net45" > nul 2>&1 +mkdir "%SELF%\..\src\double\Edge.js\bin\Release\net462" > nul 2>&1 -csc /out:"%SELF%\..\src\double\Edge.js\bin\Release\net45\EdgeJs.dll" /target:library "%SELF%\..\src\double\Edge.js\dotnet\EdgeJs.cs" +csc /out:"%SELF%\..\src\double\Edge.js\bin\Release\net462\EdgeJs.dll" /target:library "%SELF%\..\src\double\Edge.js\dotnet\EdgeJs.cs" if %ERRORLEVEL% neq 0 exit /b -1 cd "%SELF%\..\src\double\Edge.js" @@ -67,8 +78,8 @@ REM =========================================================== echo :build_node %1 %2 if exist "%SELF%\build\node-%1-%2\node.lib" ( - echo "%SELF%\build\node-%1-%2\node.lib" already built - exit /b 0 + echo "%SELF%\build\node-%1-%2\node.lib" already built + exit /b 0 ) pushd "%SELF%\build\node-%1" @@ -154,7 +165,7 @@ set GYP=%NODEBASE%\node_modules\node-gyp\bin\node-gyp.js pushd "%SELF%\.." -"%NODEEXE%" "%GYP%" configure --msvs_version=2019 +node "%GYP%" configure --msvs_version=2022 --target=%1 --runtime=node --release --arch=%2 if %ERRORLEVEL% neq 0 ( echo Error configuring edge.node %FLAVOR% for node.js %2 v%3 exit /b -1 @@ -164,6 +175,7 @@ FOR %%F IN (build\*.vcxproj) DO ( echo Patch node.lib in %%F powershell -Command "(Get-Content -Raw %%F) -replace '\\\\node.lib', '\\\\libnode.lib' | Out-File -Encoding Utf8 %%F" ) + "%NODEEXE%" "%GYP%" build mkdir "%SELF%\build\nuget\content\edge\%2" > nul 2>&1 copy /y build\release\edge_nativeclr.node "%SELF%\build\nuget\content\edge\%2" diff --git a/tools/nuget/README.md b/tools/nuget/README.md index 61f206ac..9b825a23 100644 --- a/tools/nuget/README.md +++ b/tools/nuget/README.md @@ -5,13 +5,13 @@ Edge.js allows you to run Node.js and .NET code in one process. You can call Node.js functions from .NET and .NET functions from Node.js. Edge.js takes care of marshaling data between CLR and V8. Edge.js also reconciles threading models of single-threaded V8 and multi-threaded CLR. Edge.js ensures correct lifetime of objects on V8 and CLR heaps. -Script CLR from Node.Js on Windows/Linux/macOS with .NET Framework, .Net Core and .NET Standard. +Script CLR from Node.Js on Windows with .NET Framework. -**NOTE** Scripting Node.Js from CLR is only supported on Windows .NET Framework 4.5 +**NOTE** Scripting Node.Js from CLR is only supported on Windows .NET Framework 4.5 - 4.8 More documentation is available at [Edge.Js GitHub page](https://github.com/agracio/edge-js). -#### NuGet package compiled using Node.js v20.12.2. +#### NuGet package compiled using Node.js v22.12.0. ### How to use diff --git a/tools/nuget/edge.nuspec b/tools/nuget/edge.nuspec index 54f60366..f2eff942 100644 --- a/tools/nuget/edge.nuspec +++ b/tools/nuget/edge.nuspec @@ -2,7 +2,7 @@ EdgeJs - 20.12.3 + 22.12.0 Tomasz Janczuk MIT https://licenses.nuget.org/MIT From bd07611381a4c6fe705327843751eb02e1b2dfd8 Mon Sep 17 00:00:00 2001 From: agracio Date: Fri, 27 Dec 2024 20:33:29 +0000 Subject: [PATCH 2/4] updating Nuget package --- appveyor_double.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/appveyor_double.yml b/appveyor_double.yml index 5ac757d5..549c51c3 100644 --- a/appveyor_double.yml +++ b/appveyor_double.yml @@ -17,5 +17,6 @@ after_test: only_commits: files: - - 'test/double' + - 'test/double/*' - 'appveyor_double.yml' + - 'src/double/Edge.js/dotnet/EdgeJs.cs' From 2a09182e94a8f5428de47b6765ce5141f57995e9 Mon Sep 17 00:00:00 2001 From: agracio Date: Fri, 27 Dec 2024 20:35:27 +0000 Subject: [PATCH 3/4] updating Nuget package --- test/double/double_test/nuget.config | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 test/double/double_test/nuget.config diff --git a/test/double/double_test/nuget.config b/test/double/double_test/nuget.config deleted file mode 100644 index c7f8ff1b..00000000 --- a/test/double/double_test/nuget.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From bb1b615487175e33689340716e173451796c78f4 Mon Sep 17 00:00:00 2001 From: agracio Date: Fri, 27 Dec 2024 20:37:15 +0000 Subject: [PATCH 4/4] updating Nuget package --- appveyor_double.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/appveyor_double.yml b/appveyor_double.yml index 549c51c3..61f6b5bb 100644 --- a/appveyor_double.yml +++ b/appveyor_double.yml @@ -17,6 +17,8 @@ after_test: only_commits: files: - - 'test/double/*' + - 'test/double/**' + - 'test/double/double_test/*' + - 'test/double/double_test/**/*' - 'appveyor_double.yml' - 'src/double/Edge.js/dotnet/EdgeJs.cs'