Skip to content

Commit 2ad0b58

Browse files
authored
Enable building universal (x64,arm64) binaries for MacOS (#64)
1 parent 93b999f commit 2ad0b58

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dotnet-install.sh
2+
dotnet-uninstall-pkgs.sh
3+
src/powershell-unix

.vsts-ci/mac.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ variables:
99
resources:
1010
- repo: self
1111
clean: true
12-
phases:
13-
- phase: Build
1412

15-
queue:
16-
name: Hosted macOS
13+
jobs:
14+
- job: Build
15+
16+
pool:
17+
vmImage: macOs-latest
18+
1719
steps:
1820
- powershell: |
1921
tools/releaseBuild/PowershellNative.ps1 -Arch osx -Configuration Release -RepoRoot $(Build.SourcesDirectory) -TargetLocation "$(System.ArtifactsDirectory)/Packages" -Verbose

build.psm1

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,11 @@ function Start-BuildNativeUnixBinaries {
462462
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./arm64.toolchain.cmake" . }
463463
Start-NativeExecution { make -j }
464464
}
465+
elseif ($IsMacOS) {
466+
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./macos.toolchain.cmake" . }
467+
Start-NativeExecution { make -j }
468+
Start-NativeExecution { ctest --verbose }
469+
}
465470
else {
466471
Start-NativeExecution { cmake -DCMAKE_BUILD_TYPE=Debug . }
467472
Start-NativeExecution { make -j }
@@ -774,6 +779,7 @@ function Start-PSBuild {
774779
# If this parameter is not provided it will get determined automatically.
775780
[ValidateSet("win7-x64",
776781
"win7-x86",
782+
"osx-arm64",
777783
"osx-x64",
778784
"linux-x64",
779785
"linux-arm",
@@ -1087,6 +1093,7 @@ function New-PSOptions {
10871093
[ValidateSet("",
10881094
"win7-x86",
10891095
"win7-x64",
1096+
"osx-arm64",
10901097
"osx-x64",
10911098
"linux-x64",
10921099
"linux-arm",
@@ -1139,7 +1146,12 @@ function New-PSOptions {
11391146
if ($Environment.IsLinux) {
11401147
$Runtime = "linux-x64"
11411148
} elseif ($Environment.IsMacOS) {
1142-
$Runtime = "osx-x64"
1149+
if ($PSVersionTable.OS.Contains('ARM64')) {
1150+
$Runtime = "osx-arm64"
1151+
}
1152+
else {
1153+
$Runtime = "osx-x64"
1154+
}
11431155
} else {
11441156
$RID = dotnet --info | ForEach-Object {
11451157
if ($_ -match "RID") {
@@ -2540,6 +2552,7 @@ function Start-CrossGen {
25402552
[Parameter(Mandatory=$true)]
25412553
[ValidateSet("win7-x86",
25422554
"win7-x64",
2555+
"osx-arm64",
25432556
"osx-x64",
25442557
"linux-x64",
25452558
"linux-arm",
@@ -2610,6 +2623,8 @@ function Start-CrossGen {
26102623
throw "crossgen is not available for 'linux-arm64'"
26112624
} elseif ($Environment.IsLinux) {
26122625
"linux-x64"
2626+
} elseif ($Runtime -eq "osx-arm64") {
2627+
"osx-arm64"
26132628
} elseif ($Environment.IsMacOS) {
26142629
"osx-x64"
26152630
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required(VERSION 3.19)
2+
SET(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "" FORCE)
3+
4+
add_compile_options(-g -mmacosx-version-min=10.9)
5+
6+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CROSS_LINK_FLAGS}" CACHE STRING "" FORCE)
7+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CROSS_LINK_FLAGS}" CACHE STRING "" FORCE)
8+
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${CROSS_LINK_FLAGS}" CACHE STRING "" FORCE)
9+
10+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
11+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
12+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
13+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

tools/releaseBuild/yaml/releaseBuild.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ stages:
7373

7474
- job: BuildMac
7575
displayName: Build Native Binaries on macOS
76-
pool: Hosted Mac Internal
76+
pool:
77+
vmImage: macOS-Latest
7778
steps:
7879
- template: mac.yml
7980

0 commit comments

Comments
 (0)