Skip to content

Commit

Permalink
updating standalone dependency resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
agracio committed Oct 7, 2024
1 parent f6fbd44 commit 1653533
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 13 deletions.
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
27 changes: 18 additions & 9 deletions src/double/Edge.js/dotnetcore/coreclrembedding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public struct EdgeBootstrapperContext
public delegate void CallV8FunctionDelegate(IntPtr payload, int payloadType, IntPtr v8FunctionContext, IntPtr callbackContext, IntPtr callbackDelegate);
public delegate void TaskCompleteDelegate(IntPtr result, int resultType, int taskState, IntPtr context);



[SecurityCritical]
public class CoreCLREmbedding
{
Expand All @@ -93,6 +95,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 +115,7 @@ public string DependencyManifestFile

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

Expand Down Expand Up @@ -232,7 +232,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 +241,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 @@ -466,10 +466,19 @@ private void AddCompileDependencies(DependencyContext dependencyContext, bool st

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

string assemblyPath;
var assemblyPath = string.Empty;

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(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

0 comments on commit 1653533

Please sign in to comment.