提交 bd8d105e 编写于 作者: T Tautvydas Žilys

Support cross compiling to ARM64 in our build scripts.

上级 399c21f1
......@@ -75,7 +75,7 @@ namespace BuildProgram
Artifacts.Add("MacBuildEnvironment",
new Tuple<string, string>(
"MacBuildEnvironment/9df1e3b3b120_2fc8e616a2e5dfb7907fc42d9576b427e692223c266dc3bc305de4bf03714e30.7z",
"mac-toolchain-11_0/12.0-12A8158a_2b346a6c93e9c82250a1d88c02f24a5dea9f0bd1aa2ef44109896a44800e8c68.zip",
"unity-internal"));
Artifacts.Add("mono-build-tools-extra",
......
......@@ -52,6 +52,7 @@ my $forceDefaultBuildDeps=0;
my $existingMonoRootPath = '';
my $sdk = '';
my $arch32 = 0;
my $targetArch = "";
my $winPerl = "";
my $winMonoRoot = "";
my $msBuildVersion = "14.0";
......@@ -97,6 +98,7 @@ GetOptions(
'runtimetests=i'=>\$runRuntimeTests,
'classlibtests=i'=>\$runClasslibTests,
'arch32=i'=>\$arch32,
'targetarch=s'=>\$targetArch,
'jobs=i'=>\$jobs,
'sdk=s'=>\$sdk,
'existingmono=s'=>\$existingMonoRootPath,
......@@ -206,10 +208,16 @@ if($^O eq "linux")
}
elsif($^O eq 'darwin')
{
$monoHostArch = $arch32 ? "i386" : "x86_64";
$monoHostArch = "x86_64";
$existingExternalMono = "$existingExternalMonoRoot";
$existingExternalMonoBinDir = "bin";
if ($targetArch eq "arm64")
{
$disableMcs = 1;
$test = 0;
}
# From Massi: I was getting failures in install_name_tool about space
# for the commands being too small, and adding here things like
# $ENV{LDFLAGS} = '-headerpad_max_install_names' and
......@@ -447,22 +455,12 @@ if ($build)
}
my $macSdkPath = "";
my $macversion = '10.8';
my $macversion = '10.12';
my $darwinVersion = "10";
if ($^O eq 'darwin')
{
if ($sdk eq '')
{
$sdk='10.11';
}
my $macBuildEnvDir = "$externalBuildDeps/MacBuildEnvironment";
$macSdkPath = "$macBuildEnvDir/builds/MacOSX$sdk.sdk";
if (! -d $macSdkPath)
{
print(">>> Unzipping mac build toolchain\n");
system("unzip", '-qd', "$macBuildEnvDir", "$macBuildEnvDir/builds.zip") eq 0 or die ("failed unzipping mac build toolchain\n");
}
$sdk='11.0';
$macSdkPath = "$externalBuildDeps/mac-toolchain-11_0/MacOSX$sdk.sdk";
}
if ($iphone || $iphoneSimulator)
......@@ -1156,20 +1154,37 @@ if ($build)
$existingMonoRootPath = "$monoInstalls/$monoVersionToUse";
}
if ($targetArch eq "arm64")
{
$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
}
$mcs = "EXTERNAL_MCS=$existingMonoRootPath/bin/mcs";
$ENV{'CC'} = "$macSdkPath/../usr/bin/clang";
$ENV{'CXX'} = "$macSdkPath/../usr/bin/clang++";
$ENV{'CFLAGS'} = $ENV{MACSDKOPTIONS} = "-D_XOPEN_SOURCE -I$macBuildEnvDir/builds/usr/include -mmacosx-version-min=$macversion -isysroot $macSdkPath";
$ENV{'CFLAGS'} = $ENV{MACSDKOPTIONS} = "-mmacosx-version-min=$macversion -isysroot $macSdkPath -g";
$ENV{CFLAGS} = "$ENV{CFLAGS} -g -O0" if $debug;
$ENV{CFLAGS} = "$ENV{CFLAGS} -O0" if $debug;
$ENV{CFLAGS} = "$ENV{CFLAGS} -Os" if not $debug; #optimize for size
$ENV{CC} = "$ENV{CC} -arch $monoHostArch";
$ENV{CXX} = "$ENV{CXX} -arch $monoHostArch";
$ENV{CC} = "$ENV{CC} -arch $targetArch";
$ENV{CXX} = "$ENV{CXX} -arch $targetArch";
# Add OSX specific autogen args
push @configureparams, "--host=$monoHostArch-apple-darwin12.2.0";
if ($targetArch eq "x86_64")
{
push @configureparams, "--host=x86_64-apple-darwin12.2.0";
}
elsif ($targetArch eq "arm64")
{
push @configureparams, "--host=aarch64-apple-darwinmacos12.2.0";
}
else
{
die("Unsupported macOS architecture: $targetArch");
}
# Need to define because Apple's SIP gets in the way of us telling mono where to find this
push @configureparams, "--with-libgdiplus=$addtoresultsdistdir/lib/libgdiplus.dylib";
......@@ -1507,10 +1522,9 @@ if ($artifact)
}
elsif($^O eq 'darwin')
{
# Note these tmp directories will get merged into a single 'osx' directory later by a parent script
$embedDirArchDestination = "$embedDirRoot/osx-tmp-$monoHostArch";
$distDirArchBin = "$distdir/bin-osx-tmp-$monoHostArch";
$versionsOutputFile = $arch32 ? "$buildsroot/versions-osx32.txt" : "$buildsroot/versions-osx64.txt";
$embedDirArchDestination = "$embedDirRoot/osx-tmp-$targetArch";
$distDirArchBin = "$distdir/bin-osx-tmp-$targetArch";
$versionsOutputFile = "$buildsroot/versions-macos-$targetArch.txt";
}
else
{
......@@ -1724,4 +1738,4 @@ else
print(">>> Skipping unit tests\n");
}
chdir ($currentdir);
\ No newline at end of file
chdir ($currentdir);
......@@ -62,48 +62,29 @@ if ($buildUsAndBoo)
}
print(">>> Building x86_64\n");
system("perl", "$buildscriptsdir/build.pl", "--clean=1", "--classlibtests=0", @passAlongArgs) eq 0 or die ('failing building x86_64');
system("perl", "$buildscriptsdir/build.pl", "--clean=1", "--classlibtests=0", "--targetarch=x86_64", @passAlongArgs) eq 0 or die ('failing building x86_64');
print(">>> Building ARM64\n");
system("perl", "$buildscriptsdir/build.pl", "--clean=1", "--classlibtests=0", "--targetarch=arm64", @passAlongArgs) eq 0 or die ("failing building ARM64");
if ($artifact)
{
print(">>> Moving built binaries to final output directories\n");
# Merge stuff in the embedruntimes directory
my $embedDirRoot = "$buildsroot/embedruntimes";
my $embedDirDestination = "$embedDirRoot/osx";
my $embedDirSource64 = "$embedDirRoot/osx-tmp-x86_64";
system("mkdir -p $embedDirDestination");
if (!(-d $embedDirSource64))
{
die("Expected source directory not found : $embedDirSource64\n");
}
for my $file ('libmonobdwgc-2.0.dylib','libmonosgen-2.0.dylib','libMonoPosixHelper.dylib')
{
print(">>> cp $embedDirSource64/$file $embedDirDestination/$file\n\n");
system ('cp', "$embedDirSource64/$file", "$embedDirDestination/$file");
}
if (not $buildMachine)
{
print(">>> Doing non-build machine stuff...\n");
for my $file ('libmonobdwgc-2.0.dylib','libmonosgen-2.0.dylib','libMonoPosixHelper.dylib')
{
print(">>> Removing $embedDirDestination/$file.dSYM\n");
rmtree ("$embedDirDestination/$file.dSYM");
print(">>> 'dsymutil $embedDirDestination/$file\n");
system ('dsymutil', "$embedDirDestination/$file") eq 0 or warn ("Failed creating $embedDirDestination/$file.dSYM");
}
# Copy stuff in the embedruntimes directory
my $embedDirRoot = "$buildsroot/embedruntimes";
my $embedDirSourceX64 = "$embedDirRoot/osx-tmp-x86_64";
my $embedDirSourceARM64 = "$embedDirRoot/osx-tmp-arm64";
print(">>> Done with non-build machine stuff\n");
}
CopyEmbedRuntimeBinaries($embedDirSourceX64, "$embedDirRoot/osx");
CopyEmbedRuntimeBinaries($embedDirSourceARM64, "$embedDirRoot/osx-arm64");
# Merge stuff in the monodistribution directory
my $distDirRoot = "$buildsroot/monodistribution";
my $distDirDestinationBin = "$buildsroot/monodistribution/bin";
my $distDirDestinationLib = "$buildsroot/monodistribution/lib";
my $distDirSourceBin64 = "$distDirRoot/bin-osx-tmp-x86_64";
my $distDirSourceBinX64 = "$distDirRoot/bin-osx-tmp-x86_64";
my $distDirSourceBinARM64 = "$distDirRoot/bin-osx-tmp-arm64";
# Should always exist because build_all would have put stuff in it, but in some situations
# depending on the options it may not. So create it if it does not exist
......@@ -117,27 +98,79 @@ if ($artifact)
system("mkdir -p $distDirDestinationLib");
}
if (!(-d $distDirSourceBin64))
if (!(-d $distDirSourceBinX64))
{
die("Expected source directory not found : $distDirSourceBinX64\n");
}
if (!(-d $distDirSourceBinARM64))
{
die("Expected source directory not found : $distDirSourceBinARM64\n");
}
for my $file ('mono')
{
die("Expected source directory not found : $distDirSourceBin64\n");
MergeIntoFatBinary("$distDirSourceBinX64/$file", "$distDirSourceBinARM64/$file", "$distDirDestinationBin/$file");
}
for my $file ('mono','pedump')
for my $file ('pedump')
{
system ('mv', "$distDirSourceBin64/$file", "$distDirDestinationBin/$file");
# pedump doens't get cross-compiled
system ('mv', "$distDirSourceBinX64/$file", "$distDirDestinationBin/$file") eq 0 or die ("Failed to move '$distDirSourceBinX64/$file' to '$distDirDestinationBin/$file'.");
}
for my $file ('libMonoPosixHelper.dylib')
{
print(">>> cp $embedDirSource64/$file $distDirDestinationLib/$file\n\n");
system ('cp', "$embedDirSource64/$file", "$distDirDestinationLib/$file");
MergeIntoFatBinary("$embedDirSourceX64/$file", "$embedDirSourceARM64/$file", "$distDirDestinationLib/$file");
}
if ($buildMachine)
{
print(">>> Clean up temporary arch specific build directories\n");
rmtree("$distDirSourceBin64");
rmtree("$embedDirSource64");
rmtree("$distDirSourceBinX64");
rmtree("$distDirSourceBinARM64");
rmtree("$embedDirSourceX64");
rmtree("$embedDirSourceARM64");
}
}
sub CopyEmbedRuntimeBinaries
{
my ($embedDirSource, $embedDirDestination) = @_;
system("mkdir -p $embedDirDestination");
if (!(-d $embedDirSource))
{
die("Expected source directory not found : $embedDirSource\n");
}
for my $file ('libmonobdwgc-2.0.dylib','libmonosgen-2.0.dylib','libMonoPosixHelper.dylib')
{
print(">>> cp $embedDirSource/$file $embedDirDestination/$file\n\n");
system('cp', "$embedDirSource/$file", "$embedDirDestination/$file") eq 0 or die("Failed to copy '$embedDirSource/$file' to '$embedDirDestination/$file'.");
}
if (not $buildMachine)
{
print(">>> Doing non-build machine stuff...\n");
for my $file ('libmonobdwgc-2.0.dylib','libmonosgen-2.0.dylib','libMonoPosixHelper.dylib')
{
print(">>> Removing $embedDirDestination/$file.dSYM\n");
rmtree("$embedDirDestination/$file.dSYM");
print(">>> 'dsymutil $embedDirDestination/$file\n");
system('dsymutil', "$embedDirDestination/$file") eq 0 or warn("Failed creating $embedDirDestination/$file.dSYM");
}
print(">>> Done with non-build machine stuff\n");
}
}
sub MergeIntoFatBinary
{
my ($binary1, $binary2, $binaryOutput) = @_;
print(">>> Merging '$binary1' and '$binary2' into '$binaryOutput'\n\n");
system('lipo', "$binary1", "$binary2", "-create", "-output", "$binaryOutput") eq 0 or die("Failed to run lipo!");
}
\ No newline at end of file
......@@ -34,6 +34,7 @@ system(
"--build=$build",
"--clean=$clean",
"--mcsonly=$mcsOnly",
"--targetarch=x86_64",
"--skipmonomake=$skipMonoMake",
"--artifact=1",
"--artifactscommon=1",
......
......@@ -50,6 +50,8 @@ int GC_gcj_debug_kind; /* The kind of objects that is always marked */
ptr_t * GC_gcjobjfreelist;
ptr_t * GC_gcjdebugobjfreelist;
void GC_start_debugging();
/* Caller does not hold allocation lock. */
void GC_init_gcj_malloc(int mp_index, void * /* really GC_mark_proc */mp)
{
......
......@@ -82,7 +82,7 @@ Mono_Posix_Syscall_writev (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcn
}
#endif /* def HAVE_WRITEV */
#ifdef HAVE_PREADV
#if defined(HAVE_PREADV) && !defined(__APPLE__) // Configure incorrectly detects that this function is available on macOS SDK 11.0 (it is not)
gint64
Mono_Posix_Syscall_preadv (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt, gint64 off)
{
......@@ -100,9 +100,9 @@ Mono_Posix_Syscall_preadv (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcn
free (v);
return res;
}
#endif /* def HAVE_PREADV */
#endif /* defined(HAVE_PREADV) && !defined(__APPLE__) */
#ifdef HAVE_PWRITEV
#if defined(HAVE_PWRITEV) && !defined(__APPLE__) // Configure incorrectly detects that this function is available on macOS SDK 11.0 (it is not)
gint64
Mono_Posix_Syscall_pwritev (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt, gint64 off)
{
......@@ -120,7 +120,7 @@ Mono_Posix_Syscall_pwritev (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovc
free (v);
return res;
}
#endif /* def HAVE_PWRITEV */
#endif /* defined(HAVE_PWRITEV) && !defined(__APPLE__) */
/*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册