Skip to content

Commit 18d0e5f

Browse files
Merge pull request #1309 from Unity-Technologies/mac-arm64
Add Apple silicon slice to Mono runtime built for macOS
2 parents b4d9b3c + db492f6 commit 18d0e5f

File tree

16 files changed

+274
-126
lines changed

16 files changed

+274
-126
lines changed

configure.ac

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ case "$host" in
355355
platform_ios=yes
356356
has_dtrace=no
357357
;;
358+
aarch64*-darwinmacos*)
359+
support_boehm=no
360+
;;
358361
aarch64*-darwin*)
359362
platform_ios=yes
360363
;;
@@ -1617,22 +1620,27 @@ if test x$host_win32 = xno; then
16171620
LIBS="$LIBS $DL_LIB"
16181621
AC_DEFINE(HAVE_DL_LOADER,1,[dlopen-based dynamic loader available])
16191622
dnl from glib's configure.ac
1620-
AC_CACHE_CHECK([for preceeding underscore in symbols],
1621-
mono_cv_uscore,[
1622-
AC_TRY_RUN([#include <dlfcn.h>
1623-
int mono_underscore_test (void) { return 42; }
1624-
int main() {
1625-
void *f1 = (void*)0, *f2 = (void*)0, *handle;
1626-
handle = dlopen ((void*)0, 0);
1627-
if (handle) {
1628-
f1 = dlsym (handle, "mono_underscore_test");
1629-
f2 = dlsym (handle, "_mono_underscore_test");
1630-
} return (!f2 || f1);
1631-
}],
1623+
if test "x$cross_compiling" = "xyes"; then
1624+
AC_MSG_RESULT(cross compiling, assuming no)
1625+
mono_cv_uscore=no
1626+
else
1627+
AC_CACHE_CHECK([for preceeding underscore in symbols],
1628+
mono_cv_uscore,[
1629+
AC_TRY_RUN([#include <dlfcn.h>
1630+
int mono_underscore_test (void) { return 42; }
1631+
int main() {
1632+
void *f1 = (void*)0, *f2 = (void*)0, *handle;
1633+
handle = dlopen ((void*)0, 0);
1634+
if (handle) {
1635+
f1 = dlsym (handle, "mono_underscore_test");
1636+
f2 = dlsym (handle, "_mono_underscore_test");
1637+
} return (!f2 || f1);
1638+
}],
16321639
[mono_cv_uscore=yes],
16331640
[mono_cv_uscore=no],
1634-
[])
1635-
])
1641+
[])
1642+
])
1643+
fi
16361644
if test "x$mono_cv_uscore" = "xyes"; then
16371645
MONO_DL_NEED_USCORE=1
16381646
else
@@ -3434,6 +3442,16 @@ case "$host" in
34343442
ACCESS_UNALIGNED="no"
34353443
CPPFLAGS="$CPPFLAGS -D__ARM_EABI__"
34363444
;;
3445+
aarch64-*-darwinmacos*)
3446+
TARGET_SYS=MACOS
3447+
TARGET=ARM64
3448+
arch_target=arm64
3449+
boehm_supported=false
3450+
AOT_SUPPORTED="yes"
3451+
BTLS_SUPPORTED=yes
3452+
BTLS_PLATFORM=aarch64
3453+
AC_CHECK_HEADER(stdalign.h,[],[BTLS_SUPPORTED=no])
3454+
;;
34373455
aarch64-*)
34383456
# https://lkml.org/lkml/2012/7/15/133
34393457
TARGET=ARM64
@@ -3727,8 +3745,8 @@ if test "x$target_mach" = "xyes"; then
37273745
CPPFLAGS_FOR_LIBGC="$CPPFLAGS_FOR_LIBGC -DTARGET_WATCHOS"
37283746
CFLAGS_FOR_LIBGC="$CFLAGS_FOR_LIBGC -DTARGET_WATCHOS"
37293747
BTLS_SUPPORTED=no
3730-
elif test "x$TARGET" = "xARM" -o "x$TARGET" = "xARM64"; then
3731-
AC_DEFINE(TARGET_IOS,1,[The JIT/AOT targets iOS])
3748+
elif test "x$TARGET" = "xARM" -o "x$TARGET" = "xARM64" -a "x$TARGET_SYS" != "xMACOS"; then
3749+
AC_DEFINE(TARGET_IOS,1,[The JIT/AOT targets iOS])
37323750
CPPFLAGS_FOR_LIBGC="$CPPFLAGS_FOR_LIBGC -DTARGET_IOS"
37333751
CFLAGS_FOR_LIBGC="$CFLAGS_FOR_LIBGC -DTARGET_IOS"
37343752
BTLS_SUPPORTED=no

external/buildscripts/Build.bee.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private static void RegisterOSXArtifacts()
7575

7676
Artifacts.Add("MacBuildEnvironment",
7777
new Tuple<string, string>(
78-
"MacBuildEnvironment/9df1e3b3b120_2fc8e616a2e5dfb7907fc42d9576b427e692223c266dc3bc305de4bf03714e30.7z",
78+
"mac-toolchain-11_0/12.0-12A8158a_2b346a6c93e9c82250a1d88c02f24a5dea9f0bd1aa2ef44109896a44800e8c68.zip",
7979
"unity-internal"));
8080

8181
Artifacts.Add("mono-build-tools-extra",

external/buildscripts/build.pl

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
use File::Basename;
55
use File::Path;
66
use lib ('external/buildscripts', "../../Tools/perl_lib","perl_lib", 'external/buildscripts/perl_lib');
7+
use strict;
8+
use warnings;
79
use Tools qw(InstallNameTool);
810

911
print ">>> PATH in Build All = $ENV{PATH}\n\n";
1012

1113
my $currentdir = getcwd();
1214

1315
my $monoroot = File::Spec->rel2abs(dirname(__FILE__) . "/../..");
14-
my $monoroot = abs_path($monoroot);
16+
$monoroot = abs_path($monoroot);
1517

1618
my $buildscriptsdir = "$monoroot/external/buildscripts";
1719
my $addtoresultsdistdir = "$buildscriptsdir/add_to_build_results/monodistribution";
@@ -50,6 +52,7 @@
5052
my $existingMonoRootPath = '';
5153
my $sdk = '';
5254
my $arch32 = 0;
55+
my $targetArch = "";
5356
my $winPerl = "";
5457
my $winMonoRoot = "";
5558
my $msBuildVersion = "14.0";
@@ -95,6 +98,7 @@
9598
'runtimetests=i'=>\$runRuntimeTests,
9699
'classlibtests=i'=>\$runClasslibTests,
97100
'arch32=i'=>\$arch32,
101+
'targetarch=s'=>\$targetArch,
98102
'jobs=i'=>\$jobs,
99103
'sdk=s'=>\$sdk,
100104
'existingmono=s'=>\$existingMonoRootPath,
@@ -204,10 +208,16 @@
204208
}
205209
elsif($^O eq 'darwin')
206210
{
207-
$monoHostArch = $arch32 ? "i386" : "x86_64";
211+
$monoHostArch = "x86_64";
208212
$existingExternalMono = "$existingExternalMonoRoot";
209213
$existingExternalMonoBinDir = "bin";
210214

215+
if ($targetArch eq "arm64")
216+
{
217+
$disableMcs = 1;
218+
$test = 0;
219+
}
220+
211221
# From Massi: I was getting failures in install_name_tool about space
212222
# for the commands being too small, and adding here things like
213223
# $ENV{LDFLAGS} = '-headerpad_max_install_names' and
@@ -294,7 +304,7 @@
294304
}
295305
else
296306
{
297-
if (not $checkoutonthefly)
307+
if (not $checkoutOnTheFly)
298308
{
299309
print(">>> No external build deps found. Might as well try to check them out. If it fails, we'll continue and trust mono is in your PATH\n");
300310
}
@@ -445,22 +455,12 @@
445455
}
446456

447457
my $macSdkPath = "";
448-
my $macversion = '10.8';
458+
my $macversion = '10.12';
449459
my $darwinVersion = "10";
450460
if ($^O eq 'darwin')
451461
{
452-
if ($sdk eq '')
453-
{
454-
$sdk='10.11';
455-
}
456-
457-
my $macBuildEnvDir = "$externalBuildDeps/MacBuildEnvironment";
458-
$macSdkPath = "$macBuildEnvDir/builds/MacOSX$sdk.sdk";
459-
if (! -d $macSdkPath)
460-
{
461-
print(">>> Unzipping mac build toolchain\n");
462-
system("unzip", '-qd', "$macBuildEnvDir", "$macBuildEnvDir/builds.zip") eq 0 or die ("failed unzipping mac build toolchain\n");
463-
}
462+
$sdk='11.0';
463+
$macSdkPath = "$externalBuildDeps/mac-toolchain-11_0/MacOSX$sdk.sdk";
464464
}
465465

466466
if ($iphone || $iphoneSimulator)
@@ -681,7 +681,6 @@
681681
my $platformRootPostfix = "";
682682
my $useKraitPatch = 1;
683683
my $kraitPatchPath = "$monoroot/../../android_krait_signal_handler/build";
684-
my $toolChainExtension = "";
685684

686685
$ENV{ANDROID_PLATFORM} = "android-$apiLevel";
687686

@@ -759,8 +758,6 @@
759758

760759
if ($runningOnWindows)
761760
{
762-
$toolChainExtension = ".exe";
763-
764761
$androidPlatformRoot = `cygpath -w $androidPlatformRoot`;
765762
# clean up trailing new lines that end up in the output from cygpath.
766763
$androidPlatformRoot =~ s/\n+$//;
@@ -968,8 +965,6 @@
968965

969966
if ($runningOnWindows)
970967
{
971-
$toolChainExtension = ".exe";
972-
973968
$tizenPlatformRoot = `cygpath -w $tizenPlatformRoot`;
974969
# clean up trailing new lines that end up in the output from cygpath.
975970
$tizenPlatformRoot =~ s/\n+$//;
@@ -1159,20 +1154,37 @@
11591154
$existingMonoRootPath = "$monoInstalls/$monoVersionToUse";
11601155
}
11611156

1157+
if ($targetArch eq "arm64")
1158+
{
1159+
$macversion = "11.0"; # To build on ARM64, we need to specify min OS version as 11.0 as we need to use new APIs from 11.0
1160+
}
1161+
11621162
$mcs = "EXTERNAL_MCS=$existingMonoRootPath/bin/mcs";
11631163

11641164
$ENV{'CC'} = "$macSdkPath/../usr/bin/clang";
11651165
$ENV{'CXX'} = "$macSdkPath/../usr/bin/clang++";
1166-
$ENV{'CFLAGS'} = $ENV{MACSDKOPTIONS} = "-D_XOPEN_SOURCE -I$macBuildEnvDir/builds/usr/include -mmacosx-version-min=$macversion -isysroot $macSdkPath";
1166+
$ENV{'CFLAGS'} = $ENV{MACSDKOPTIONS} = "-mmacosx-version-min=$macversion -isysroot $macSdkPath -g";
11671167

1168-
$ENV{CFLAGS} = "$ENV{CFLAGS} -g -O0" if $debug;
1168+
$ENV{CFLAGS} = "$ENV{CFLAGS} -O0" if $debug;
11691169
$ENV{CFLAGS} = "$ENV{CFLAGS} -Os" if not $debug; #optimize for size
11701170

1171-
$ENV{CC} = "$ENV{CC} -arch $monoHostArch";
1172-
$ENV{CXX} = "$ENV{CXX} -arch $monoHostArch";
1171+
$ENV{CC} = "$ENV{CC} -arch $targetArch";
1172+
$ENV{CXX} = "$ENV{CXX} -arch $targetArch";
11731173

11741174
# Add OSX specific autogen args
1175-
push @configureparams, "--host=$monoHostArch-apple-darwin12.2.0";
1175+
1176+
if ($targetArch eq "x86_64")
1177+
{
1178+
push @configureparams, "--host=x86_64-apple-darwin12.2.0";
1179+
}
1180+
elsif ($targetArch eq "arm64")
1181+
{
1182+
push @configureparams, "--host=aarch64-apple-darwinmacos12.2.0";
1183+
}
1184+
else
1185+
{
1186+
die("Unsupported macOS architecture: $targetArch");
1187+
}
11761188

11771189
# Need to define because Apple's SIP gets in the way of us telling mono where to find this
11781190
push @configureparams, "--with-libgdiplus=$addtoresultsdistdir/lib/libgdiplus.dylib";
@@ -1510,10 +1522,9 @@
15101522
}
15111523
elsif($^O eq 'darwin')
15121524
{
1513-
# Note these tmp directories will get merged into a single 'osx' directory later by a parent script
1514-
$embedDirArchDestination = "$embedDirRoot/osx-tmp-$monoHostArch";
1515-
$distDirArchBin = "$distdir/bin-osx-tmp-$monoHostArch";
1516-
$versionsOutputFile = $arch32 ? "$buildsroot/versions-osx32.txt" : "$buildsroot/versions-osx64.txt";
1525+
$embedDirArchDestination = "$embedDirRoot/osx-tmp-$targetArch";
1526+
$distDirArchBin = "$distdir/bin-osx-tmp-$targetArch";
1527+
$versionsOutputFile = "$buildsroot/versions-macos-$targetArch.txt";
15171528
}
15181529
else
15191530
{
@@ -1598,7 +1609,7 @@
15981609
system("ln","-f", "$monoroot/mono/mini/.libs/libmonosgen-2.0.dylib","$embedDirArchDestination/libmonosgen-2.0.dylib") eq 0 or die ("failed symlinking libmonosgen-2.0.dylib\n");
15991610

16001611
print "Hardlinking libMonoPosixHelper.dylib\n";
1601-
system("ln","-f", "$monoroot/support/.libs/libMonoPosixHelper.dylib","$embedDirArchDestination/libMonoPosixHelper.dylib") eq 0 or die ("failed symlinking $libtarget/libMonoPosixHelper.dylib\n");
1612+
system("ln","-f", "$monoroot/support/.libs/libMonoPosixHelper.dylib","$embedDirArchDestination/libMonoPosixHelper.dylib") eq 0 or die ("failed symlinking $embedDirArchDestination/libMonoPosixHelper.dylib\n");
16021613

16031614
InstallNameTool("$embedDirArchDestination/libmonobdwgc-2.0.dylib", "\@executable_path/../Frameworks/MonoEmbedRuntime/osx/libmonobdwgc-2.0.dylib");
16041615
InstallNameTool("$embedDirArchDestination/libmonosgen-2.0.dylib", "\@executable_path/../Frameworks/MonoEmbedRuntime/osx/libmonosgen-2.0.dylib");
@@ -1691,9 +1702,9 @@
16911702

16921703
if ($test)
16931704
{
1705+
my $runtimeTestsDir = "$monoroot/mono/mini";
16941706
if ($runRuntimeTests)
16951707
{
1696-
my $runtimeTestsDir = "$monoroot/mono/mini";
16971708
chdir("$runtimeTestsDir") eq 1 or die ("failed to chdir");
16981709
print("\n>>> Calling make check in $runtimeTestsDir\n\n");
16991710
system("make","check") eq 0 or die ("runtime tests failed\n");
@@ -1727,4 +1738,4 @@
17271738
print(">>> Skipping unit tests\n");
17281739
}
17291740

1730-
chdir ($currentdir);
1741+
chdir ($currentdir);

0 commit comments

Comments
 (0)