From 0398f57125560fd440fb3a1481b9250cd4d03d5e Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Fri, 20 May 2022 11:00:54 -0400 Subject: [PATCH] Create runner layout for osx-arm64 (Apple M1) platform. (#1618) * Create runner layout for osx-arm64 (Apple M1) platform. * bypass m1 macos * l0 --- .github/workflows/build.yml | 8 ++++++-- src/Directory.Build.props | 5 ++++- src/Misc/contentHash/dotnetRuntime/osx-arm64 | 1 + src/Misc/contentHash/externals/osx-arm64 | 1 + src/Misc/externals.sh | 5 +++++ src/Runner.Common/Runner.Common.csproj | 2 +- src/Runner.Common/Util/NodeUtil.cs | 8 +++++++- src/Runner.Listener/Runner.Listener.csproj | 2 +- src/Runner.PluginHost/Runner.PluginHost.csproj | 2 +- src/Runner.Plugins/Runner.Plugins.csproj | 2 +- src/Runner.Sdk/Runner.Sdk.csproj | 2 +- src/Runner.Worker/Handlers/NodeScriptActionHandler.cs | 8 ++++++++ src/Runner.Worker/Runner.Worker.csproj | 2 +- src/Sdk/Sdk.csproj | 2 +- src/Test/L0/ConstantGenerationL0.cs | 3 ++- src/Test/L0/Listener/SelfUpdaterL0.cs | 4 +++- src/Test/L0/PackagesTrimL0.cs | 8 ++++---- src/Test/L0/ProcessExtensionL0.cs | 4 ++-- src/Test/L0/Worker/StepHostL0.cs | 2 ++ src/Test/Test.csproj | 2 +- src/dev.sh | 10 ++++++++-- 21 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 src/Misc/contentHash/dotnetRuntime/osx-arm64 create mode 100644 src/Misc/contentHash/externals/osx-arm64 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2373119ca..db05427c3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ jobs: build: strategy: matrix: - runtime: [ linux-x64, linux-arm64, linux-arm, win-x64, osx-x64 ] + runtime: [ linux-x64, linux-arm64, linux-arm, win-x64, osx-x64, osx-arm64 ] include: - runtime: linux-x64 os: ubuntu-latest @@ -36,6 +36,10 @@ jobs: os: macOS-latest devScript: ./dev.sh + - runtime: osx-arm64 + os: macOS-latest + devScript: ./dev.sh + - runtime: win-x64 os: windows-2019 devScript: ./dev @@ -78,7 +82,7 @@ jobs: run: | ${{ matrix.devScript }} test working-directory: src - if: matrix.runtime != 'linux-arm64' && matrix.runtime != 'linux-arm' + if: matrix.runtime != 'linux-arm64' && matrix.runtime != 'linux-arm' && matrix.runtime != 'osx-arm64' # Create runner package tar.gz/zip - name: Package Release diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 71e570e08..1931b7f8f 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -25,9 +25,12 @@ $(DefineConstants);X86 - + $(DefineConstants);X64 + + $(DefineConstants);ARM64 + $(DefineConstants);X64 diff --git a/src/Misc/contentHash/dotnetRuntime/osx-arm64 b/src/Misc/contentHash/dotnetRuntime/osx-arm64 new file mode 100644 index 000000000..04681bcfc --- /dev/null +++ b/src/Misc/contentHash/dotnetRuntime/osx-arm64 @@ -0,0 +1 @@ +02c7126ff4d63ee2a0ae390c81434c125630522aadf35903bbeebb1a99d8af99 \ No newline at end of file diff --git a/src/Misc/contentHash/externals/osx-arm64 b/src/Misc/contentHash/externals/osx-arm64 new file mode 100644 index 000000000..5f2d6f38c --- /dev/null +++ b/src/Misc/contentHash/externals/osx-arm64 @@ -0,0 +1 @@ +cc4708962a80325de0baa5ae8484e0cb9ae976ac6a4178c1c0d448b8c52bd7f7 \ No newline at end of file diff --git a/src/Misc/externals.sh b/src/Misc/externals.sh index fe7a74b9a..b11b225f7 100755 --- a/src/Misc/externals.sh +++ b/src/Misc/externals.sh @@ -140,6 +140,11 @@ if [[ "$PACKAGERUNTIME" == "osx-x64" ]]; then acquireExternalTool "$NODE_URL/v${NODE16_VERSION}/node-v${NODE16_VERSION}-darwin-x64.tar.gz" node16 fix_nested_dir fi +if [[ "$PACKAGERUNTIME" == "osx-arm64" ]]; then + # node.js v12 doesn't support macOS on arm64. + acquireExternalTool "$NODE_URL/v${NODE16_VERSION}/node-v${NODE16_VERSION}-darwin-arm64.tar.gz" node16 fix_nested_dir +fi + # Download the external tools for Linux PACKAGERUNTIMEs. if [[ "$PACKAGERUNTIME" == "linux-x64" ]]; then acquireExternalTool "$NODE_URL/v${NODE12_VERSION}/node-v${NODE12_VERSION}-linux-x64.tar.gz" node12 fix_nested_dir diff --git a/src/Runner.Common/Runner.Common.csproj b/src/Runner.Common/Runner.Common.csproj index bf55ea845..84bb6e4c0 100644 --- a/src/Runner.Common/Runner.Common.csproj +++ b/src/Runner.Common/Runner.Common.csproj @@ -3,7 +3,7 @@ net6.0 Library - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64 true NU1701;NU1603 $(Version) diff --git a/src/Runner.Common/Util/NodeUtil.cs b/src/Runner.Common/Util/NodeUtil.cs index d537de1cc..bae94f4b0 100644 --- a/src/Runner.Common/Util/NodeUtil.cs +++ b/src/Runner.Common/Util/NodeUtil.cs @@ -6,7 +6,13 @@ namespace GitHub.Runner.Common.Util public static class NodeUtil { private const string _defaultNodeVersion = "node16"; - public static readonly ReadOnlyCollection BuiltInNodeVersions = new(new[] {"node12", "node16"}); + +#if OS_OSX && ARM64 + public static readonly ReadOnlyCollection BuiltInNodeVersions = new(new[] { "node16" }); +#else + public static readonly ReadOnlyCollection BuiltInNodeVersions = new(new[] { "node12", "node16" }); +#endif + public static string GetInternalNodeVersion() { var forcedNodeVersion = Environment.GetEnvironmentVariable(Constants.Variables.Agent.ForcedInternalNodeVersion); diff --git a/src/Runner.Listener/Runner.Listener.csproj b/src/Runner.Listener/Runner.Listener.csproj index a327bd298..1aa14e386 100644 --- a/src/Runner.Listener/Runner.Listener.csproj +++ b/src/Runner.Listener/Runner.Listener.csproj @@ -3,7 +3,7 @@ net6.0 Exe - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64 true NU1701;NU1603 $(Version) diff --git a/src/Runner.PluginHost/Runner.PluginHost.csproj b/src/Runner.PluginHost/Runner.PluginHost.csproj index a7418bb8d..7937a2516 100644 --- a/src/Runner.PluginHost/Runner.PluginHost.csproj +++ b/src/Runner.PluginHost/Runner.PluginHost.csproj @@ -3,7 +3,7 @@ net6.0 Exe - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64 true NU1701;NU1603 $(Version) diff --git a/src/Runner.Plugins/Runner.Plugins.csproj b/src/Runner.Plugins/Runner.Plugins.csproj index daa86f026..8314aea51 100644 --- a/src/Runner.Plugins/Runner.Plugins.csproj +++ b/src/Runner.Plugins/Runner.Plugins.csproj @@ -3,7 +3,7 @@ net6.0 Library - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64 true NU1701;NU1603 $(Version) diff --git a/src/Runner.Sdk/Runner.Sdk.csproj b/src/Runner.Sdk/Runner.Sdk.csproj index e0294afc6..63d6c0e18 100644 --- a/src/Runner.Sdk/Runner.Sdk.csproj +++ b/src/Runner.Sdk/Runner.Sdk.csproj @@ -3,7 +3,7 @@ net6.0 Library - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64 true NU1701;NU1603 $(Version) diff --git a/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs b/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs index cc8cedfd0..197e10e76 100644 --- a/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs +++ b/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs @@ -94,6 +94,14 @@ namespace GitHub.Runner.Worker.Handlers workingDirectory = HostContext.GetDirectory(WellKnownDirectory.Work); } +#if OS_OSX + if (string.Equals(Data.NodeVersion, "node12", StringComparison.OrdinalIgnoreCase) && + Constants.Runner.PlatformArchitecture.Equals(Constants.Architecture.Arm64)) + { + ExecutionContext.Output($"The node12 is not supported on macOS ARM64 platform. Use node16 instead."); + Data.NodeVersion = "node16"; + } +#endif var nodeRuntimeVersion = await StepHost.DetermineNodeRuntimeVersion(ExecutionContext, Data.NodeVersion); string file = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), nodeRuntimeVersion, "bin", $"node{IOUtil.ExeExtension}"); diff --git a/src/Runner.Worker/Runner.Worker.csproj b/src/Runner.Worker/Runner.Worker.csproj index 40779c33b..f949b6037 100644 --- a/src/Runner.Worker/Runner.Worker.csproj +++ b/src/Runner.Worker/Runner.Worker.csproj @@ -3,7 +3,7 @@ net6.0 Exe - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64 true NU1701;NU1603 $(Version) diff --git a/src/Sdk/Sdk.csproj b/src/Sdk/Sdk.csproj index 133f99a41..44f6c7941 100644 --- a/src/Sdk/Sdk.csproj +++ b/src/Sdk/Sdk.csproj @@ -3,7 +3,7 @@ net6.0 Library - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64 true NU1701;NU1603 $(Version) diff --git a/src/Test/L0/ConstantGenerationL0.cs b/src/Test/L0/ConstantGenerationL0.cs index d964ba474..69c3a0bd4 100644 --- a/src/Test/L0/ConstantGenerationL0.cs +++ b/src/Test/L0/ConstantGenerationL0.cs @@ -19,7 +19,8 @@ namespace GitHub.Runner.Common.Tests "linux-x64", "linux-arm", "linux-arm64", - "osx-x64" + "osx-x64", + "osx-arm64" }; Assert.True(BuildConstants.Source.CommitHash.Length == 40, $"CommitHash should be SHA-1 hash {BuildConstants.Source.CommitHash}"); diff --git a/src/Test/L0/Listener/SelfUpdaterL0.cs b/src/Test/L0/Listener/SelfUpdaterL0.cs index 84b5c67b5..d67cf11f3 100644 --- a/src/Test/L0/Listener/SelfUpdaterL0.cs +++ b/src/Test/L0/Listener/SelfUpdaterL0.cs @@ -1,4 +1,5 @@ -using System; +#if !(OS_OSX && ARM64) +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -795,3 +796,4 @@ namespace GitHub.Runner.Common.Tests.Listener } } } +#endif diff --git a/src/Test/L0/PackagesTrimL0.cs b/src/Test/L0/PackagesTrimL0.cs index 51a91b0ff..391e85745 100644 --- a/src/Test/L0/PackagesTrimL0.cs +++ b/src/Test/L0/PackagesTrimL0.cs @@ -166,9 +166,9 @@ namespace GitHub.Runner.Common.Tests string binDir = Path.Combine(TestUtil.GetSrcPath(), @"../_layout/bin"); #if OS_WINDOWS - string node = Path.Combine(TestUtil.GetSrcPath(), @"..\_layout\externals\node12\bin\node"); + string node = Path.Combine(TestUtil.GetSrcPath(), @"..\_layout\externals\node16\bin\node"); #else - string node = Path.Combine(TestUtil.GetSrcPath(), @"../_layout/externals/node12/bin/node"); + string node = Path.Combine(TestUtil.GetSrcPath(), @"../_layout/externals/node16/bin/node"); #endif string hashFilesScript = Path.Combine(binDir, "hashFiles"); var hashResult = string.Empty; @@ -228,9 +228,9 @@ namespace GitHub.Runner.Common.Tests string binDir = Path.Combine(TestUtil.GetSrcPath(), @"../_layout/bin"); #if OS_WINDOWS - string node = Path.Combine(TestUtil.GetSrcPath(), @"..\_layout\externals\node12\bin\node"); + string node = Path.Combine(TestUtil.GetSrcPath(), @"..\_layout\externals\node16\bin\node"); #else - string node = Path.Combine(TestUtil.GetSrcPath(), @"../_layout/externals/node12/bin/node"); + string node = Path.Combine(TestUtil.GetSrcPath(), @"../_layout/externals/node16/bin/node"); #endif string hashFilesScript = Path.Combine(binDir, "hashFiles"); var hashResult = string.Empty; diff --git a/src/Test/L0/ProcessExtensionL0.cs b/src/Test/L0/ProcessExtensionL0.cs index 02be3991b..1fd01e304 100644 --- a/src/Test/L0/ProcessExtensionL0.cs +++ b/src/Test/L0/ProcessExtensionL0.cs @@ -27,9 +27,9 @@ namespace GitHub.Runner.Common.Tests try { #if OS_WINDOWS - string node = Path.Combine(TestUtil.GetSrcPath(), @"..\_layout\externals\node12\bin\node"); + string node = Path.Combine(TestUtil.GetSrcPath(), @"..\_layout\externals\node16\bin\node"); #else - string node = Path.Combine(TestUtil.GetSrcPath(), @"../_layout/externals/node12/bin/node"); + string node = Path.Combine(TestUtil.GetSrcPath(), @"../_layout/externals/node16/bin/node"); hc.EnqueueInstance(new ProcessInvokerWrapper()); #endif var startInfo = new ProcessStartInfo(node, "-e \"setTimeout(function(){{}}, 15 * 1000);\""); diff --git a/src/Test/L0/Worker/StepHostL0.cs b/src/Test/L0/Worker/StepHostL0.cs index 8666e2e0a..9e18c1128 100644 --- a/src/Test/L0/Worker/StepHostL0.cs +++ b/src/Test/L0/Worker/StepHostL0.cs @@ -32,6 +32,7 @@ namespace GitHub.Runner.Common.Tests.Worker return hc; } +#if OS_LINUX [Fact] [Trait("Level", "L0")] [Trait("Category", "Worker")] @@ -108,5 +109,6 @@ namespace GitHub.Runner.Common.Tests.Worker Assert.Equal("node16", nodeVersion); } } +#endif } } diff --git a/src/Test/Test.csproj b/src/Test/Test.csproj index 432d48223..1e48b2baf 100644 --- a/src/Test/Test.csproj +++ b/src/Test/Test.csproj @@ -1,7 +1,7 @@  net6.0 - win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64 true NU1701;NU1603;NU1603;xUnit2013; diff --git a/src/dev.sh b/src/dev.sh index 198b1eac3..c4d0aa062 100755 --- a/src/dev.sh +++ b/src/dev.sh @@ -54,6 +54,12 @@ elif [[ "$CURRENT_PLATFORM" == 'linux' ]]; then fi elif [[ "$CURRENT_PLATFORM" == 'darwin' ]]; then RUNTIME_ID='osx-x64' + if command -v uname > /dev/null; then + CPU_NAME=$(uname -m) + case $CPU_NAME in + arm64) RUNTIME_ID="osx-arm64";; + esac + fi fi if [[ -n "$DEV_TARGET_RUNTIME" ]]; then @@ -63,7 +69,7 @@ fi # Make sure current platform support publish the dotnet runtime # Windows can publish win-x86/x64 # Linux can publish linux-x64/arm/arm64 -# OSX can publish osx-x64 +# OSX can publish osx-x64/arm64 if [[ "$CURRENT_PLATFORM" == 'windows' ]]; then if [[ ("$RUNTIME_ID" != 'win-x86') && ("$RUNTIME_ID" != 'win-x64') ]]; then echo "Failed: Can't build $RUNTIME_ID package $CURRENT_PLATFORM" >&2 @@ -75,7 +81,7 @@ elif [[ "$CURRENT_PLATFORM" == 'linux' ]]; then exit 1 fi elif [[ "$CURRENT_PLATFORM" == 'darwin' ]]; then - if [[ ("$RUNTIME_ID" != 'osx-x64') ]]; then + if [[ ("$RUNTIME_ID" != 'osx-x64') && ("$RUNTIME_ID" != 'osx-arm64') ]]; then echo "Failed: Can't build $RUNTIME_ID package $CURRENT_PLATFORM" >&2 exit 1 fi