Skip to content

Commit

Permalink
merging standalone dependency resolution from edge-js, updating workf…
Browse files Browse the repository at this point in the history
…lows
  • Loading branch information
agracio committed Oct 15, 2024
1 parent a02c010 commit 4271106
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 54 deletions.
50 changes: 26 additions & 24 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ on:
default: '30.0.0'
type: choice
options:
- 29.0.0
- 30.0.0
- 31.0.0
- 32.0.0
- 33.0.0
- 29
- 30
- 31
- 32
- 33
# test-version:
# description: 'Electron version to test build'
# required: true
Expand Down Expand Up @@ -51,20 +51,22 @@ jobs:
id: electron-test-version
shell: bash
run: |
if [[ ${{ inputs.build-version }} == '29.0.0' ]]; then
if [[ ${{ inputs.build-version }} == '29' ]]; then
echo "test-version=29.4.6" >> $GITHUB_OUTPUT
elif [[ ${{ inputs.build-version }} == '30.0.0' ]]; then
elif [[ ${{ inputs.build-version }} == '30' ]]; then
echo "test-version=30.5.1" >> $GITHUB_OUTPUT
elif [[ ${{ inputs.build-version }} == '31.0.0' ]]; then
elif [[ ${{ inputs.build-version }} == '31' ]]; then
echo "test-version=31.6.0" >> $GITHUB_OUTPUT
elif [[ ${{ inputs.build-version }} == '32.0.0' ]]; then
echo "test-version=32.1.2" >> $GITHUB_OUTPUT
elif [[ ${{ inputs.build-version }} == '32' ]]; then
echo "test-version=32.2.0" >> $GITHUB_OUTPUT
elif [[ ${{ inputs.build-version }} == '33' ]]; then
echo "test-version=33.0.0" >> $GITHUB_OUTPUT
fi
- name: Setup env
uses: ./.github/actions/setup-env
with:
electron: ${{ inputs.build-version }}
electron: '${{ inputs.build-version }}.0.0'
os: ${{ matrix.os }}

- name: install node-gyp
Expand All @@ -73,68 +75,68 @@ jobs:

- name: Create release folder
run: |
mkdir "release\ia32\${{ inputs.build-version }}"
mkdir "release\x64\${{ inputs.build-version }}"
mkdir "release\arm64\${{ inputs.build-version }}"
mkdir "release\ia32\${{ inputs.build-version }}.0.0"
mkdir "release\x64\${{ inputs.build-version }}.0.0"
mkdir "release\arm64\${{ inputs.build-version }}.0.0"
- name: Build ia32
timeout-minutes: 30
shell: pwsh
run: |
node-gyp configure --target=${{ inputs.build-version }} --disturl=https://electronjs.org/headers --runtime=electron --release --arch=ia32
node-gyp configure --target=${{ inputs.build-version }}.0.0 --disturl=https://electronjs.org/headers --runtime=electron --release --arch=ia32
if ( '${{ inputs.build-version }}' -eq '32.0.0'){
if ( '${{ inputs.build-version }}' -GEQ 32){
(Get-Content -Raw build/build_managed.vcxproj) -replace 'std:c\+\+17', 'std:c++20' | Out-File -Encoding Utf8 build/build_managed.vcxproj
(Get-Content -Raw build/edge_coreclr.vcxproj) -replace 'std:c\+\+17', 'std:c++20' | Out-File -Encoding Utf8 build/edge_coreclr.vcxproj
(Get-Content -Raw build/edge_nativeclr.vcxproj) -replace 'std:c\+\+17', 'std:c++20' | Out-File -Encoding Utf8 build/edge_nativeclr.vcxproj
}
node-gyp build
cmd /c copy /y build\Release\edge_*.node release\ia32\${{ inputs.build-version }}
cmd /c copy /y build\Release\edge_*.node release\ia32\${{ inputs.build-version }}.0.0
cmd /c rmdir /S /Q build
- name: Build x64
timeout-minutes: 30
shell: pwsh
run: |
node-gyp configure --target=${{ inputs.build-version }} --disturl=https://electronjs.org/headers --runtime=electron --release --arch=x64
node-gyp configure --target=${{ inputs.build-version }}.0.0 --disturl=https://electronjs.org/headers --runtime=electron --release --arch=x64
if ( '${{ inputs.build-version }}' -eq '32.0.0'){
if ( '${{ inputs.build-version }}' -GEQ 32){
(Get-Content -Raw build/build_managed.vcxproj) -replace 'std:c\+\+17', 'std:c++20' | Out-File -Encoding Utf8 build/build_managed.vcxproj
(Get-Content -Raw build/edge_coreclr.vcxproj) -replace 'std:c\+\+17', 'std:c++20' | Out-File -Encoding Utf8 build/edge_coreclr.vcxproj
(Get-Content -Raw build/edge_nativeclr.vcxproj) -replace 'std:c\+\+17', 'std:c++20' | Out-File -Encoding Utf8 build/edge_nativeclr.vcxproj
}
node-gyp build
cmd /c copy /y build\Release\edge_*.node release\x64\${{ inputs.build-version }}
cmd /c copy /y build\Release\edge_*.node release\x64\${{ inputs.build-version }}.0.0
cmd /c rmdir /S /Q build
- name: Build arm64
timeout-minutes: 30
shell: pwsh
run: |
node-gyp configure --target=${{ inputs.build-version }} --disturl=https://electronjs.org/headers --runtime=electron --release --arch=arm64
node-gyp configure --target=${{ inputs.build-version }}.0.0 --disturl=https://electronjs.org/headers --runtime=electron --release --arch=arm64
(Get-Content -Raw build/build_managed.vcxproj) -replace '<FloatingPointModel>Strict</FloatingPointModel>', '<!-- <FloatingPointModel>Strict</FloatingPointModel> -->' | Out-File -Encoding Utf8 build/build_managed.vcxproj
(Get-Content -Raw build/edge_coreclr.vcxproj) -replace '<FloatingPointModel>Strict</FloatingPointModel>', '<!-- <FloatingPointModel>Strict</FloatingPointModel> -->' | Out-File -Encoding Utf8 build/edge_coreclr.vcxproj
(Get-Content -Raw build/edge_nativeclr.vcxproj) -replace '<FloatingPointModel>Strict</FloatingPointModel>', '<!-- <FloatingPointModel>Strict</FloatingPointModel> -->' | Out-File -Encoding Utf8 build/edge_nativeclr.vcxproj
if ( '${{ inputs.build-version }}' -eq '32.0.0'){
if ( '${{ inputs.build-version }}' -GEQ 32){
(Get-Content -Raw build/build_managed.vcxproj) -replace 'std:c\+\+17', 'std:c++20' | Out-File -Encoding Utf8 build/build_managed.vcxproj
(Get-Content -Raw build/edge_coreclr.vcxproj) -replace 'std:c\+\+17', 'std:c++20' | Out-File -Encoding Utf8 build/edge_coreclr.vcxproj
(Get-Content -Raw build/edge_nativeclr.vcxproj) -replace 'std:c\+\+17', 'std:c++20' | Out-File -Encoding Utf8 build/edge_nativeclr.vcxproj
}
node-gyp build
cmd /c copy /y build\Release\edge_*.node release\arm64\${{ inputs.build-version }}
cmd /c copy /y build\Release\edge_*.node release\arm64\${{ inputs.build-version }}.0.0
cmd /c rmdir /S /Q build
- name: Upload artifacts
uses: actions/upload-artifact@v4
if: success()
with:
name: electron-edge-js-${{ inputs.build-version }}
name: electron-edge-js-${{ inputs.build-version }}.0.0
path: |
release
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
os: [macos-13, macos-14, ubuntu-22.04, windows-2022]
# os: [ macos-14, ubuntu-22.04]
# electron: [32.1.2]
electron: [29.4.6, 30.5.1, 31.6.0, 32.1.2]
electron: [29.4.6, 30.5.1, 31.6.0, 32.2.0]
# electron: [31.6.0, 32.1.0]

name: test-${{ matrix.os }}-v${{ matrix.electron }}
Expand Down
48 changes: 44 additions & 4 deletions src/CoreCLREmbedding/coreclrembedding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
#include <libproc.h>
#endif

// Special entry for coreclr path
pal::string_t m_coreclr_standalone_path;

// Special entry for JIT path
pal::string_t m_clrjit_standalone_path;

GetFuncFunction getFunc;
CallFuncFunction callFunc;
ContinueTaskFunction continueTask;
Expand Down Expand Up @@ -177,6 +183,25 @@ pal::string_t GetOSVersion()
#endif
}

void init_known_entry_path(const pal::string_t& edgeAppDir)
{
trace::info(_X("CoreClrEmbedding::Initialize - Resolving CoreCLR and CLRJit for standalone"));
pal::string_t coreclr(edgeAppDir);
append_path(&coreclr, LIBCORECLR_NAME);
if(pal::file_exists(coreclr))
{
trace::info(_X("CoreClrEmbedding::Initialize - Resolved CoreCLR to %s"), coreclr.c_str());
m_coreclr_standalone_path = coreclr;
}
pal::string_t clrjit(edgeAppDir);
append_path(&clrjit, LIBCLRJIT_NAME);
if(pal::file_exists(clrjit))
{
trace::info(_X("CoreClrEmbedding::Initialize - Resolved CLRJit to %s"), clrjit.c_str());
m_clrjit_standalone_path = clrjit;
}
}

HRESULT CoreClrEmbedding::Initialize(BOOL debugMode)
{
trace::setup();
Expand Down Expand Up @@ -338,13 +363,14 @@ HRESULT CoreClrEmbedding::Initialize(BOOL debugMode)

if (mode != host_mode_t::standalone && dotnetExecutablePath.empty())
{
throwV8Exception("This is not a published, standalone application and we are unable to locate the .NET Core SDK. Please make sure that it is installed; see http://microsoft.com/net/core for more details.");
throwV8Exception("This is not a published, standalone application and we are unable to locate the .NET Core SDK. Please make sure that it is installed; see https://microsoft.com/net/core for more details.");
}

pal::string_t configFile, devConfigFile, sdkPath;

if (mode != host_mode_t::standalone)
{
trace::verbose(_X("CoreClrEmbedding::Initialize - host mode: muxer"));
pal::string_t sdkDirectory;

fx_muxer_t::resolve_sdk_dotnet_path(dotnetDirectory, &sdkDirectory);
Expand All @@ -357,6 +383,8 @@ HRESULT CoreClrEmbedding::Initialize(BOOL debugMode)

else
{
trace::verbose(_X("CoreClrEmbedding::Initialize - host mode: standalone"));
init_known_entry_path(edgeAppDir);
get_runtime_config_paths_from_app(entryPointAssembly, &configFile, &devConfigFile);
}

Expand Down Expand Up @@ -446,14 +474,26 @@ HRESULT CoreClrEmbedding::Initialize(BOOL debugMode)
return StatusCode::ResolverResolveFailure;
}

pal::string_t clr_path = probe_paths.coreclr;
pal::string_t clr_path;
pal::string_t clrjit_path;

if (mode != host_mode_t::standalone)
{
clr_path = probe_paths.coreclr;
clrjit_path = probe_paths.clrjit;
}
else
{
clr_path = m_coreclr_standalone_path;
clrjit_path = m_clrjit_standalone_path;
}

if (clr_path.empty() || !pal::realpath(&clr_path))
{
trace::error(_X("CoreClrEmbedding::Initialize - Could not resolve CoreCLR path. For more details, enable tracing by setting COREHOST_TRACE environment variable to 1"));;
trace::error(_X("CoreClrEmbedding::Initialize - Could not resolve CoreCLR path. For more details, enable tracing by setting COREHOST_TRACE environment variable to 1"));
return StatusCode::CoreClrResolveFailure;
}

pal::string_t clrjit_path = probe_paths.clrjit;
if (clrjit_path.empty())
{
trace::warning(_X("CoreClrEmbedding::Initialize - Could not resolve CLRJit path"));
Expand Down
50 changes: 25 additions & 25 deletions src/double/Edge.js/dotnetcore/coreclrembedding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Threading.Tasks;
using System.IO;
using Microsoft.Extensions.DependencyModel;
// ReSharper disable InconsistentNaming

[StructLayout(LayoutKind.Sequential)]
// ReSharper disable once CheckNamespace
Expand Down Expand Up @@ -93,6 +94,7 @@ public EdgeRuntimeEnvironment(EdgeBootstrapperContext bootstrapperContext)
ApplicationDirectory = bootstrapperContext.ApplicationDirectory;
RuntimePath = bootstrapperContext.RuntimeDirectory;
DependencyManifestFile = bootstrapperContext.DependencyManifestFile;
StandaloneApplication = Path.GetDirectoryName(RuntimePath) == ApplicationDirectory;
}

public string RuntimePath
Expand All @@ -112,10 +114,7 @@ public string DependencyManifestFile

public bool StandaloneApplication
{
get
{
return ApplicationDirectory == RuntimePath;
}
get;
}
}

Expand Down Expand Up @@ -232,7 +231,7 @@ public void LoadDependencyManifest(string dependencyManifestFile)
dependencyContext = dependencyContext.Merge(dependencyContextReader.Read(runtimeDependencyManifestStream));
}
}

DebugMessage("EdgeAssemblyResolver::Runtime - ApplicationDirectory: {0}, RuntimePath: {1}, Standalone: {2}", RuntimeEnvironment.ApplicationDirectory, RuntimeEnvironment.RuntimePath, RuntimeEnvironment.StandaloneApplication);
AddDependencies(dependencyContext, RuntimeEnvironment.StandaloneApplication);
}

Expand All @@ -241,7 +240,7 @@ public void LoadDependencyManifest(string dependencyManifestFile)

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

AddCompileDependencies(dependencyContext, standalone);

Expand Down Expand Up @@ -459,17 +458,26 @@ private void AddCompileDependencies(DependencyContext dependencyContext, bool st
var runtimePath = Path.GetDirectoryName(RuntimeEnvironment.RuntimePath);
foreach (CompilationLibrary compileLibrary in dependencyContext.CompileLibraries)
{
if (compileLibrary.Assemblies == null || compileLibrary.Assemblies.Count == 0 || CompileAssemblies.ContainsKey(compileLibrary.Name))
if (compileLibrary.Assemblies.Count == 0 || CompileAssemblies.ContainsKey(compileLibrary.Name))
{
continue;
}

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

string assemblyPath;
var assemblyPath = compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar);

if (standalone && File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, "refs", Path.GetFileName(compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar)))))
assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, "refs", Path.GetFileName(compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar)));
if (standalone)
{
if (File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, "refs", Path.GetFileName(compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar)))))
{
assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, "refs", Path.GetFileName(compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar)));
}
else if(!string.IsNullOrEmpty(runtimePath) && File.Exists(Path.Combine(runtimePath, Path.GetFileName(compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar)))))
{
assemblyPath = Path.Combine(runtimePath, Path.GetFileName(compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar)));
}
}
else
{
assemblyPath = Path.Combine(_packagesPath, compileLibrary.Name.ToLower(), compileLibrary.Version, compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar).ToLower());
Expand Down Expand Up @@ -627,8 +635,7 @@ public static void Initialize(IntPtr context, IntPtr exception)
{
DebugMessage("CoreCLREmbedding::Initialize (CLR) - Exception was thrown: {0}{1}{2}", e.Message, Environment.NewLine, e.StackTrace);

V8Type v8Type;
Marshal.WriteIntPtr(exception, MarshalCLRToV8(e, out v8Type));
Marshal.WriteIntPtr(exception, MarshalCLRToV8(e, out _));
}
}

Expand Down Expand Up @@ -695,8 +702,7 @@ public static IntPtr GetFunc(string assemblyFile, string typeName, string method
{
DebugMessage("CoreCLREmbedding::GetFunc (CLR) - Exception was thrown: {0}{1}{2}", e.Message, Environment.NewLine, e.StackTrace);

V8Type v8Type;
Marshal.WriteIntPtr(exception, MarshalCLRToV8(e, out v8Type));
Marshal.WriteIntPtr(exception, MarshalCLRToV8(e, out _));

return IntPtr.Zero;
}
Expand Down Expand Up @@ -806,8 +812,7 @@ public static IntPtr CompileFunc(IntPtr v8Options, int payloadType, IntPtr excep
{
DebugMessage("CoreCLREmbedding::CompileFunc (CLR) - Exception was thrown: {0}\n{1}", e.InnerException.Message, e.InnerException.StackTrace);

V8Type v8Type;
Marshal.WriteIntPtr(exception, MarshalCLRToV8(e, out v8Type));
Marshal.WriteIntPtr(exception, MarshalCLRToV8(e, out _));

return IntPtr.Zero;
}
Expand All @@ -816,8 +821,7 @@ public static IntPtr CompileFunc(IntPtr v8Options, int payloadType, IntPtr excep
{
DebugMessage("CoreCLREmbedding::CompileFunc (CLR) - Exception was thrown: {0}{1}{2}", e.Message, Environment.NewLine, e.StackTrace);

V8Type v8Type;
Marshal.WriteIntPtr(exception, MarshalCLRToV8(e, out v8Type));
Marshal.WriteIntPtr(exception, MarshalCLRToV8(e, out _));

return IntPtr.Zero;
}
Expand Down Expand Up @@ -854,9 +858,7 @@ public static void CallFunc(IntPtr function, IntPtr payload, int payloadType, In
{
DebugMessage("CoreCLREmbedding::CallFunc (CLR) - .NET method ran synchronously and faulted, marshalling exception data for V8");

V8Type taskExceptionType;

Marshal.WriteIntPtr(result, MarshalCLRToV8(functionTask.Exception, out taskExceptionType));
Marshal.WriteIntPtr(result, MarshalCLRToV8(functionTask.Exception, out _));
Marshal.WriteInt32(resultType, (int)V8Type.Exception);
break;
}
Expand Down Expand Up @@ -969,8 +971,7 @@ public static void ContinueTask(IntPtr task, IntPtr context, IntPtr callback, In
{
DebugMessage("CoreCLREmbedding::ContinueTask (CLR) - Exception was thrown: {0}{1}{2}", e.Message, Environment.NewLine, e.StackTrace);

V8Type v8Type;
Marshal.WriteIntPtr(exception, MarshalCLRToV8(e, out v8Type));
Marshal.WriteIntPtr(exception, MarshalCLRToV8(e, out _));
}
}

Expand All @@ -987,8 +988,7 @@ public static void SetCallV8FunctionDelegate(IntPtr callV8Function, IntPtr excep
{
DebugMessage("CoreCLREmbedding::SetCallV8FunctionDelegate (CLR) - Exception was thrown: {0}{1}{2}", e.Message, Environment.NewLine, e.StackTrace);

V8Type v8Type;
Marshal.WriteIntPtr(exception, MarshalCLRToV8(e, out v8Type));
Marshal.WriteIntPtr(exception, MarshalCLRToV8(e, out _));
}
}

Expand Down

0 comments on commit 4271106

Please sign in to comment.