From ab3ca44a63b9b776f47b3c4e5fd4acc10d9d2eeb Mon Sep 17 00:00:00 2001 From: ChanTsune <41658782+ChanTsune@users.noreply.github.com> Date: Thu, 17 Oct 2024 23:19:42 +0900 Subject: [PATCH 1/3] Initial support building the runner on FreeBSD --- src/Directory.Build.props | 10 ++++++++++ src/Runner.Common/Constants.cs | 5 ++++- src/Runner.Common/Runner.Common.csproj | 3 ++- src/Runner.Common/Util/VarUtil.cs | 3 +++ .../Configuration/ConfigurationManager.cs | 2 +- src/Runner.Listener/Configuration/RSAFileKeyManager.cs | 2 +- .../Configuration/ServiceControlManager.cs | 2 +- src/Runner.Listener/Program.cs | 7 +++++++ src/Runner.Listener/Runner.Listener.csproj | 3 ++- src/Runner.Listener/SelfUpdater.cs | 2 +- src/Runner.Listener/SelfUpdaterV2.cs | 2 +- src/Runner.PluginHost/Runner.PluginHost.csproj | 3 ++- src/Runner.Plugins/Runner.Plugins.csproj | 3 ++- src/Runner.Sdk/Runner.Sdk.csproj | 3 ++- src/Runner.Worker/Runner.Worker.csproj | 3 ++- src/Sdk/Sdk.csproj | 3 ++- src/Test/Test.csproj | 3 ++- src/dev.sh | 6 ++++-- 18 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 9db5faca37a..01a43a499dd 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -6,6 +6,10 @@ Linux + + FreeBSD + + $(DefineConstants);OS_WINDOWS @@ -16,6 +20,9 @@ $(DefineConstants);OS_LINUX + + $(DefineConstants);OS_FREEBSD + @@ -44,6 +51,9 @@ $(DefineConstants);ARM64 + + $(DefineConstants);X64 + diff --git a/src/Runner.Common/Constants.cs b/src/Runner.Common/Constants.cs index 2c20d1b16fe..7fe21e4ffc2 100644 --- a/src/Runner.Common/Constants.cs +++ b/src/Runner.Common/Constants.cs @@ -50,7 +50,8 @@ public enum OSPlatform { OSX, Linux, - Windows + Windows, + FreeBSD } public enum Architecture @@ -69,6 +70,8 @@ public static class Runner public static readonly OSPlatform Platform = OSPlatform.OSX; #elif OS_WINDOWS public static readonly OSPlatform Platform = OSPlatform.Windows; +#elif OS_FREEBSD + public static readonly OSPlatform Platform = OSPlatform.FreeBSD; #else public static readonly OSPlatform Platform = OSPlatform.Linux; #endif diff --git a/src/Runner.Common/Runner.Common.csproj b/src/Runner.Common/Runner.Common.csproj index 6c4635626a2..db06e126da1 100644 --- a/src/Runner.Common/Runner.Common.csproj +++ b/src/Runner.Common/Runner.Common.csproj @@ -3,7 +3,8 @@ net8.0 Library - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64;freebsd-x64 true NU1701;NU1603;SYSLIB0050;SYSLIB0051 $(Version) diff --git a/src/Runner.Common/Util/VarUtil.cs b/src/Runner.Common/Util/VarUtil.cs index 97273a1adb3..88c30cd3e05 100644 --- a/src/Runner.Common/Util/VarUtil.cs +++ b/src/Runner.Common/Util/VarUtil.cs @@ -12,6 +12,7 @@ public static StringComparer EnvironmentVariableKeyComparer { case Constants.OSPlatform.Linux: case Constants.OSPlatform.OSX: + case Constants.OSPlatform.FreeBSD: return StringComparer.Ordinal; case Constants.OSPlatform.Windows: return StringComparer.OrdinalIgnoreCase; @@ -33,6 +34,8 @@ public static string OS return "macOS"; case Constants.OSPlatform.Windows: return "Windows"; + case Constants.OSPlatform.FreeBSD: + return "FreeBSD"; default: throw new NotSupportedException(); // Should never reach here. } diff --git a/src/Runner.Listener/Configuration/ConfigurationManager.cs b/src/Runner.Listener/Configuration/ConfigurationManager.cs index 05b93cb58bb..7dea9868d60 100644 --- a/src/Runner.Listener/Configuration/ConfigurationManager.cs +++ b/src/Runner.Listener/Configuration/ConfigurationManager.cs @@ -427,7 +427,7 @@ public async Task ConfigureAsync(CommandSettings command) serviceControlManager.ConfigureService(runnerSettings, command); } -#elif OS_LINUX || OS_OSX +#elif OS_LINUX || OS_OSX || OS_FREEBSD // generate service config script for OSX and Linux, GenerateScripts() will no-opt on windows. var serviceControlManager = HostContext.GetService(); serviceControlManager.GenerateScripts(runnerSettings); diff --git a/src/Runner.Listener/Configuration/RSAFileKeyManager.cs b/src/Runner.Listener/Configuration/RSAFileKeyManager.cs index 532128a5700..3562cfb67b8 100644 --- a/src/Runner.Listener/Configuration/RSAFileKeyManager.cs +++ b/src/Runner.Listener/Configuration/RSAFileKeyManager.cs @@ -1,4 +1,4 @@ -#if OS_LINUX || OS_OSX +#if OS_LINUX || OS_OSX || OS_FREEBSD using System; using System.IO; using System.Security.Cryptography; diff --git a/src/Runner.Listener/Configuration/ServiceControlManager.cs b/src/Runner.Listener/Configuration/ServiceControlManager.cs index 6129034eb31..1b8e500838f 100644 --- a/src/Runner.Listener/Configuration/ServiceControlManager.cs +++ b/src/Runner.Listener/Configuration/ServiceControlManager.cs @@ -76,7 +76,7 @@ public void CalculateServiceName(RunnerSettings settings, string serviceNamePatt Trace.Info($"Service name '{serviceName}' display name '{serviceDisplayName}' will be used for service configuration."); } -#if (OS_LINUX || OS_OSX) +#if (OS_LINUX || OS_OSX || OS_FREEBSD) const int MaxServiceNameLength = 150; const int MaxRepoOrgCharacters = 70; #elif OS_WINDOWS diff --git a/src/Runner.Listener/Program.cs b/src/Runner.Listener/Program.cs index a6bdce62ce8..a3b6361dcc2 100644 --- a/src/Runner.Listener/Program.cs +++ b/src/Runner.Listener/Program.cs @@ -53,6 +53,13 @@ private async static Task MainAsync(IHostContext context, string[] args) return Constants.Runner.ReturnCode.TerminatedError; } break; + case Constants.OSPlatform.FreeBSD: + if (!RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) + { + terminal.WriteLine("This runner version is built for FreeBSD. Please install a correct build for your OS."); + return Constants.Runner.ReturnCode.TerminatedError; + } + break; case Constants.OSPlatform.Windows: if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { diff --git a/src/Runner.Listener/Runner.Listener.csproj b/src/Runner.Listener/Runner.Listener.csproj index afd528128a5..77a740915ca 100644 --- a/src/Runner.Listener/Runner.Listener.csproj +++ b/src/Runner.Listener/Runner.Listener.csproj @@ -3,7 +3,8 @@ net8.0 Exe - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64;freebsd-x64 true true NU1701;NU1603;SYSLIB0050;SYSLIB0051 diff --git a/src/Runner.Listener/SelfUpdater.cs b/src/Runner.Listener/SelfUpdater.cs index 6ebeebd8270..6cdd9b757db 100644 --- a/src/Runner.Listener/SelfUpdater.cs +++ b/src/Runner.Listener/SelfUpdater.cs @@ -103,7 +103,7 @@ public async Task SelfUpdate(AgentRefreshMessage updateMessage, IJobDispat #if OS_WINDOWS invokeScript.StartInfo.FileName = WhichUtil.Which("cmd.exe", trace: Trace); invokeScript.StartInfo.Arguments = $"/c \"{updateScript}\""; -#elif (OS_OSX || OS_LINUX) +#elif (OS_OSX || OS_LINUX || OS_FREEBSD) invokeScript.StartInfo.FileName = WhichUtil.Which("bash", trace: Trace); invokeScript.StartInfo.Arguments = $"\"{updateScript}\""; #endif diff --git a/src/Runner.Listener/SelfUpdaterV2.cs b/src/Runner.Listener/SelfUpdaterV2.cs index b64619b69e5..25c6d27481f 100644 --- a/src/Runner.Listener/SelfUpdaterV2.cs +++ b/src/Runner.Listener/SelfUpdaterV2.cs @@ -103,7 +103,7 @@ public async Task SelfUpdate(RunnerRefreshMessage updateMessage, IJobDispa #if OS_WINDOWS invokeScript.StartInfo.FileName = WhichUtil.Which("cmd.exe", trace: Trace); invokeScript.StartInfo.Arguments = $"/c \"{updateScript}\""; -#elif (OS_OSX || OS_LINUX) +#elif (OS_OSX || OS_LINUX || OS_FREEBSD) invokeScript.StartInfo.FileName = WhichUtil.Which("bash", trace: Trace); invokeScript.StartInfo.Arguments = $"\"{updateScript}\""; #endif diff --git a/src/Runner.PluginHost/Runner.PluginHost.csproj b/src/Runner.PluginHost/Runner.PluginHost.csproj index 81a8d2e4304..aad81ea013b 100644 --- a/src/Runner.PluginHost/Runner.PluginHost.csproj +++ b/src/Runner.PluginHost/Runner.PluginHost.csproj @@ -3,7 +3,8 @@ net8.0 Exe - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64;freebsd-x64 true true NU1701;NU1603;SYSLIB0050;SYSLIB0051 diff --git a/src/Runner.Plugins/Runner.Plugins.csproj b/src/Runner.Plugins/Runner.Plugins.csproj index a786cf1cd1b..640c6012c3f 100644 --- a/src/Runner.Plugins/Runner.Plugins.csproj +++ b/src/Runner.Plugins/Runner.Plugins.csproj @@ -3,7 +3,8 @@ net8.0 Library - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64;freebsd-x64 true true NU1701;NU1603;SYSLIB0050;SYSLIB0051 diff --git a/src/Runner.Sdk/Runner.Sdk.csproj b/src/Runner.Sdk/Runner.Sdk.csproj index 55dbf12627c..4f1122e2b4a 100644 --- a/src/Runner.Sdk/Runner.Sdk.csproj +++ b/src/Runner.Sdk/Runner.Sdk.csproj @@ -3,7 +3,8 @@ net8.0 Library - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64;freebsd-x64 true true NU1701;NU1603;SYSLIB0050;SYSLIB0051 diff --git a/src/Runner.Worker/Runner.Worker.csproj b/src/Runner.Worker/Runner.Worker.csproj index 53c1610df3e..ddfe2e36df8 100644 --- a/src/Runner.Worker/Runner.Worker.csproj +++ b/src/Runner.Worker/Runner.Worker.csproj @@ -3,7 +3,8 @@ net8.0 Exe - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64;freebsd-x64 true true NU1701;NU1603;SYSLIB0050;SYSLIB0051 diff --git a/src/Sdk/Sdk.csproj b/src/Sdk/Sdk.csproj index 7ba739498a4..a3836d41783 100644 --- a/src/Sdk/Sdk.csproj +++ b/src/Sdk/Sdk.csproj @@ -3,7 +3,8 @@ net8.0 Library - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64;freebsd-x64 true NU1701;NU1603;SYSLIB0050;SYSLIB0051 diff --git a/src/Test/Test.csproj b/src/Test/Test.csproj index aebe242096f..b72ff244d0c 100644 --- a/src/Test/Test.csproj +++ b/src/Test/Test.csproj @@ -1,7 +1,8 @@ net8.0 - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64;freebsd-x64 true NU1701;NU1603;NU1603;xUnit2013;SYSLIB0050;SYSLIB0051 diff --git a/src/dev.sh b/src/dev.sh index 795c135a232..378fc31e238 100755 --- a/src/dev.sh +++ b/src/dev.sh @@ -35,7 +35,7 @@ if [[ "$DEV_CONFIG" == "Release" ]]; then fi CURRENT_PLATFORM="windows" -if [[ ($(uname) == "Linux") || ($(uname) == "Darwin") ]]; then +if [[ ($(uname) == "Linux") || ($(uname) == "Darwin") || ($(uname) == "FreeBSD")]]; then CURRENT_PLATFORM=$(uname | awk '{print tolower($0)}') fi @@ -64,6 +64,8 @@ elif [[ "$CURRENT_PLATFORM" == 'darwin' ]]; then arm64) RUNTIME_ID="osx-arm64";; esac fi +elif [[ "$CURRENT_PLATFORM" == 'freebsd' ]]; then + RUNTIME_ID='freebsd-x64' fi if [[ -n "$DEV_TARGET_RUNTIME" ]]; then @@ -183,7 +185,7 @@ function package () pushd "$PACKAGE_DIR" > /dev/null - if [[ ("$CURRENT_PLATFORM" == "linux") || ("$CURRENT_PLATFORM" == "darwin") ]]; then + if [[ ("$CURRENT_PLATFORM" == "linux") || ("$CURRENT_PLATFORM" == "darwin") || ("$CURRENT_PLATFORM" == "freebsd")]]; then tar_name="${runner_pkg_name}.tar.gz" echo "Creating $tar_name in ${LAYOUT_DIR}" tar -czf "${tar_name}" -C "${LAYOUT_DIR}" . From b0622759fed71c17d5f74304f3196e7839618555 Mon Sep 17 00:00:00 2001 From: ChanTsune <41658782+ChanTsune@users.noreply.github.com> Date: Fri, 18 Oct 2024 21:07:21 +0900 Subject: [PATCH 2/3] fix test case for freebsd --- src/Test/L0/ConstantGenerationL0.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Test/L0/ConstantGenerationL0.cs b/src/Test/L0/ConstantGenerationL0.cs index f3c1b8f9eaf..879104cb231 100644 --- a/src/Test/L0/ConstantGenerationL0.cs +++ b/src/Test/L0/ConstantGenerationL0.cs @@ -21,7 +21,8 @@ public void BuildConstantGenerateSucceed() "linux-arm", "linux-arm64", "osx-x64", - "osx-arm64" + "osx-arm64", + "freebsd-x64" }; Assert.Equal(40, BuildConstants.Source.CommitHash.Length); From 8beacf8a842ba33eef33a7eb843fef69458d87b8 Mon Sep 17 00:00:00 2001 From: ChanTsune <41658782+ChanTsune@users.noreply.github.com> Date: Thu, 17 Oct 2024 23:23:06 +0900 Subject: [PATCH 3/3] use system dotnet on freebsd --- src/dev.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/dev.sh b/src/dev.sh index 378fc31e238..6f04e008784 100755 --- a/src/dev.sh +++ b/src/dev.sh @@ -220,6 +220,10 @@ if [[ (! -d "${DOTNETSDK_INSTALLDIR}") || (! -e "${DOTNETSDK_INSTALLDIR}/.${DOTN sdkinstallwindow_path=${DOTNETSDK_INSTALLDIR:1} sdkinstallwindow_path=${sdkinstallwindow_path:0:1}:${sdkinstallwindow_path:1} $POWERSHELL -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "& \"./Misc/dotnet-install.ps1\" -Version ${DOTNETSDK_VERSION} -InstallDir \"${sdkinstallwindow_path}\" -NoPath; exit \$LastExitCode;" || checkRC dotnet-install.ps1 + # FIXME: binary for freebsd is not on https://dotnetcli.azureedge.net + elif [[ ("$CURRENT_PLATFORM" == "freebsd") ]]; then + echo "Skip installing dotnet, use system dotnet" + command -v dotnet else bash ./Misc/dotnet-install.sh --version ${DOTNETSDK_VERSION} --install-dir "${DOTNETSDK_INSTALLDIR}" --no-path || checkRC dotnet-install.sh fi