Skip to content

Commit

Permalink
adding apploader
Browse files Browse the repository at this point in the history
  • Loading branch information
aishwaryabh committed Sep 17, 2024
1 parent 3800bab commit 9caa9ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
3 changes: 2 additions & 1 deletion host/src/FunctionsCustomHost/Prelaunch/Prelauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ internal static class PreLauncher
/// </summary>
internal static void Run()
{
// Adding this here for testing; remove later
Environment.SetEnvironmentVariable(EnvironmentVariables.FunctionsWorkerRuntimeVersion, "8.0");
Environment.SetEnvironmentVariable(EnvironmentVariables.FunctionsWorkerRuntime, "dotnet");
Environment.SetEnvironmentVariable(EnvironmentVariables.FunctionsWorkerRuntime, "dotnet-isolated");
Environment.SetEnvironmentVariable(EnvironmentVariables.FunctionsInProcNet8Enabled, "1");


Expand Down
36 changes: 17 additions & 19 deletions host/src/FunctionsCustomHost/Program.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Transactions;
using FunctionsNetHost.Prelaunch;
using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic;
using Newtonsoft.Json.Linq;

namespace FunctionsNetHost
{
internal class Program
{
private const string WindowsExecutableName = "func.exe";
private const string LinuxExecutableName = "func";
private const string ExecutableName = "func.dll";
private const string InProc8DirectoryName = "in-proc8";
private const string InProc6DirectoryName = "in-proc6";

static async Task Main(string[] args)
{
try
Expand All @@ -37,22 +30,22 @@ static async Task Main(string[] args)
}
if (workerRuntime == "dotnet")
{
// Start child process for .NET 8 in proc host
// Load host assembly for .NET 8 in proc host
if (string.Equals("1", EnvironmentUtils.GetValue(EnvironmentVariables.FunctionsInProcNet8Enabled)))
{
await LoadHostAssembly(isOutOfProc: false, isNet8InProc: true);
await LoadHostAssembly(appLoader, isOutOfProc: false, isNet8InProc: true);
}
else
{
// Start child process for .NET 6 in proc host
await LoadHostAssembly(isOutOfProc: false, isNet8InProc: false);
// Load host assembly for .NET 6 in proc host
await LoadHostAssembly(appLoader, isOutOfProc: false, isNet8InProc: false);
}

}
else if (workerRuntime == "dotnet-isolated")
{
// Start process for oop host
await LoadHostAssembly(isOutOfProc: true, isNet8InProc: false);
await LoadHostAssembly(appLoader, isOutOfProc: true, isNet8InProc: false);
}
}
catch (Exception exception)
Expand All @@ -61,24 +54,29 @@ static async Task Main(string[] args)
}
}

private static Task LoadHostAssembly(bool isOutOfProc, bool isNet8InProc)
private static Task LoadHostAssembly(AppLoader appLoader, bool isOutOfProc, bool isNet8InProc)
{
var commandLineArguments = string.Join(" ", Environment.GetCommandLineArgs().Skip(1));
var tcs = new TaskCompletionSource();

var rootDirectory = GetFunctionAppRootDirectory(Environment.CurrentDirectory, new[] { "Azure.Functions.Cli" });
var coreToolsDirectory = Path.Combine(rootDirectory, "Azure.Functions.Cli");

var executableName = LinuxExecutableName;
var executableName = ExecutableName;

var fileName = isNet8InProc ? Path.Combine(coreToolsDirectory, InProc8DirectoryName, executableName): Path.Combine(coreToolsDirectory, InProc8DirectoryName, executableName);
string fileName = "";

if (isOutOfProc)
{
fileName = Path.Combine(coreToolsDirectory, executableName);
}
Assembly assembly = Assembly.LoadFrom(fileName);
Logger.Log("Loaded Assembly: " + assembly.FullName);
else
{
fileName = isNet8InProc ? Path.Combine(coreToolsDirectory, InProc8DirectoryName, executableName) : Path.Combine(coreToolsDirectory, InProc8DirectoryName, executableName);

}

appLoader.RunApplication(fileName);

return tcs.Task;
}
Expand Down

0 comments on commit 9caa9ca

Please sign in to comment.