Skip to content

Commit

Permalink
Create runner layout for osx-arm64 (Apple M1) platform. (#1618)
Browse files Browse the repository at this point in the history
* Create runner layout for osx-arm64 (Apple M1) platform.

* bypass m1 macos

* l0
  • Loading branch information
TingluoHuang committed May 20, 2022
1 parent fade0f4 commit 0398f57
Show file tree
Hide file tree
Showing 21 changed files with 61 additions and 22 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/Directory.Build.props
Expand Up @@ -25,9 +25,12 @@
<DefineConstants>$(DefineConstants);X86</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(BUILD_OS)' == 'OSX'">
<PropertyGroup Condition="'$(BUILD_OS)' == 'OSX' AND '$(PackageRuntime)' == 'osx-x64'">
<DefineConstants>$(DefineConstants);X64</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(BUILD_OS)' == 'OSX' AND '$(PackageRuntime)' == 'osx-arm64'">
<DefineConstants>$(DefineConstants);ARM64</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(BUILD_OS)' == 'Linux' AND ('$(PackageRuntime)' == 'linux-x64' OR '$(PackageRuntime)' == '')">
<DefineConstants>$(DefineConstants);X64</DefineConstants>
Expand Down
1 change: 1 addition & 0 deletions src/Misc/contentHash/dotnetRuntime/osx-arm64
@@ -0,0 +1 @@
02c7126ff4d63ee2a0ae390c81434c125630522aadf35903bbeebb1a99d8af99
1 change: 1 addition & 0 deletions src/Misc/contentHash/externals/osx-arm64
@@ -0,0 +1 @@
cc4708962a80325de0baa5ae8484e0cb9ae976ac6a4178c1c0d448b8c52bd7f7
5 changes: 5 additions & 0 deletions src/Misc/externals.sh
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Runner.Common/Runner.Common.csproj
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Library</OutputType>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64</RuntimeIdentifiers>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<NoWarn>NU1701;NU1603</NoWarn>
<Version>$(Version)</Version>
Expand Down
8 changes: 7 additions & 1 deletion src/Runner.Common/Util/NodeUtil.cs
Expand Up @@ -6,7 +6,13 @@ namespace GitHub.Runner.Common.Util
public static class NodeUtil
{
private const string _defaultNodeVersion = "node16";
public static readonly ReadOnlyCollection<string> BuiltInNodeVersions = new(new[] {"node12", "node16"});

#if OS_OSX && ARM64
public static readonly ReadOnlyCollection<string> BuiltInNodeVersions = new(new[] { "node16" });
#else
public static readonly ReadOnlyCollection<string> BuiltInNodeVersions = new(new[] { "node12", "node16" });
#endif

public static string GetInternalNodeVersion()
{
var forcedNodeVersion = Environment.GetEnvironmentVariable(Constants.Variables.Agent.ForcedInternalNodeVersion);
Expand Down
2 changes: 1 addition & 1 deletion src/Runner.Listener/Runner.Listener.csproj
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64</RuntimeIdentifiers>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<NoWarn>NU1701;NU1603</NoWarn>
<Version>$(Version)</Version>
Expand Down
2 changes: 1 addition & 1 deletion src/Runner.PluginHost/Runner.PluginHost.csproj
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64</RuntimeIdentifiers>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<NoWarn>NU1701;NU1603</NoWarn>
<Version>$(Version)</Version>
Expand Down
2 changes: 1 addition & 1 deletion src/Runner.Plugins/Runner.Plugins.csproj
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Library</OutputType>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64</RuntimeIdentifiers>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<NoWarn>NU1701;NU1603</NoWarn>
<Version>$(Version)</Version>
Expand Down
2 changes: 1 addition & 1 deletion src/Runner.Sdk/Runner.Sdk.csproj
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Library</OutputType>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64</RuntimeIdentifiers>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<NoWarn>NU1701;NU1603</NoWarn>
<Version>$(Version)</Version>
Expand Down
8 changes: 8 additions & 0 deletions src/Runner.Worker/Handlers/NodeScriptActionHandler.cs
Expand Up @@ -94,6 +94,14 @@ public async Task RunAsync(ActionRunStage stage)
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}");

Expand Down
2 changes: 1 addition & 1 deletion src/Runner.Worker/Runner.Worker.csproj
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64</RuntimeIdentifiers>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<NoWarn>NU1701;NU1603</NoWarn>
<Version>$(Version)</Version>
Expand Down
2 changes: 1 addition & 1 deletion src/Sdk/Sdk.csproj
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Library</OutputType>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64</RuntimeIdentifiers>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<NoWarn>NU1701;NU1603</NoWarn>
<Version>$(Version)</Version>
Expand Down
3 changes: 2 additions & 1 deletion src/Test/L0/ConstantGenerationL0.cs
Expand Up @@ -19,7 +19,8 @@ public void BuildConstantGenerateSucceed()
"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}");
Expand Down
4 changes: 3 additions & 1 deletion 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;
Expand Down Expand Up @@ -795,3 +796,4 @@ public async void TestSelfUpdateAsync_FallbackToFullPackage()
}
}
}
#endif
8 changes: 4 additions & 4 deletions src/Test/L0/PackagesTrimL0.cs
Expand Up @@ -166,9 +166,9 @@ public async Task RunnerLayoutParts_CheckDotnetRuntimeHash()
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;
Expand Down Expand Up @@ -228,9 +228,9 @@ public async Task RunnerLayoutParts_CheckExternalsHash()
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;
Expand Down
4 changes: 2 additions & 2 deletions src/Test/L0/ProcessExtensionL0.cs
Expand Up @@ -27,9 +27,9 @@ public async Task SuccessReadProcessEnv()
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<IProcessInvoker>(new ProcessInvokerWrapper());
#endif
var startInfo = new ProcessStartInfo(node, "-e \"setTimeout(function(){{}}, 15 * 1000);\"");
Expand Down
2 changes: 2 additions & 0 deletions src/Test/L0/Worker/StepHostL0.cs
Expand Up @@ -32,6 +32,7 @@ private TestHostContext CreateTestContext([CallerMemberName] String testName = "
return hc;
}

#if OS_LINUX
[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Worker")]
Expand Down Expand Up @@ -108,5 +109,6 @@ public async Task DetermineNodeRuntimeVersionInUnknowContainerAsync()
Assert.Equal("node16", nodeVersion);
}
}
#endif
}
}
2 changes: 1 addition & 1 deletion src/Test/Test.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64</RuntimeIdentifiers>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<NoWarn>NU1701;NU1603;NU1603;xUnit2013;</NoWarn>
</PropertyGroup>
Expand Down
10 changes: 8 additions & 2 deletions src/dev.sh
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0398f57

Please sign in to comment.