Skip to content

Commit 58f9211

Browse files
committed
Build Mono for Android with NDK r16b
Change the compiler used to build Mono for Android from gcc to clang, and update the NDK to version r16b. Also, remove some unused ARM architectures.
1 parent 6774cef commit 58f9211

File tree

3 files changed

+38
-79
lines changed

3 files changed

+38
-79
lines changed

external/buildscripts/build.pl

Lines changed: 37 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -652,32 +652,31 @@
652652
die("mono build deps are required and the directory was not found : $externalBuildDeps\n");
653653
}
654654

655-
my $ndkVersion = "r13b";
656-
my $isArmArch = 1;
657-
my $toolchainName = "";
655+
my $ndkVersion = "r16b";
656+
my $apiLevel = 16;
657+
my $hostTriple = "";
658658
my $platformRootPostfix = "";
659659
my $useKraitPatch = 1;
660660
my $kraitPatchPath = "$monoroot/../../android_krait_signal_handler/build";
661661
my $toolChainExtension = "";
662662

663-
$isArmArch = 0 if ($androidArch eq "x86");
664-
665-
$ENV{ANDROID_PLATFORM} = "android-9";
666-
$ENV{GCC_VERSION} = "4.9";
663+
$ENV{ANDROID_PLATFORM} = "android-$apiLevel";
667664

668-
if ($isArmArch)
665+
if ($androidArch eq "armv7a")
669666
{
670-
$ENV{GCC_PREFIX} = "arm-linux-androideabi-";
671-
$toolchainName = "$ENV{GCC_PREFIX}$ENV{GCC_VERSION}";
667+
$hostTriple = "arm-linux-androideabi";
672668
$platformRootPostfix = "arm";
673669
}
674-
else
670+
elsif ($androidArch eq "x86")
675671
{
676-
$ENV{GCC_PREFIX} = "i686-linux-android-";
677-
$toolchainName = "x86-$ENV{GCC_VERSION}";
672+
$hostTriple = "i686-linux-android";
678673
$platformRootPostfix = "x86";
679674
$useKraitPatch = 0;
680675
}
676+
else
677+
{
678+
die("Unsupported android architecture: $androidArch\n");
679+
}
681680

682681
if ($^O eq "linux")
683682
{
@@ -695,8 +694,6 @@
695694
print "\n";
696695
print(">>> Android Platform = $ENV{ANDROID_PLATFORM}\n");
697696
print(">>> Android NDK Version = $ndkVersion\n");
698-
print(">>> Android GCC Prefix = $ENV{GCC_PREFIX}\n");
699-
print(">>> Android GCC Version = $ENV{GCC_VERSION}\n");
700697

701698
my $ndkName = "";
702699
if($^O eq "linux")
@@ -772,19 +769,11 @@
772769

773770
my $androidNdkRoot = $ENV{ANDROID_NDK_ROOT};
774771
my $androidPlatformRoot = "$androidNdkRoot/platforms/$ENV{ANDROID_PLATFORM}/arch-$platformRootPostfix";
775-
my $androidToolchain = "$androidNdkRoot/toolchains/$toolchainName/prebuilt/$ENV{HOST_ENV}";
776772

777-
if (!(-d "$androidToolchain"))
778-
{
779-
if (-d "$androidToolchain-x86")
780-
{
781-
$androidToolchain = "$androidToolchain-x86";
782-
}
783-
else
784-
{
785-
$androidToolchain = "$androidToolchain-x86_64";
786-
}
787-
}
773+
my $androidToolchain = "$androidNdkRoot/toolchains/$hostTriple-clang";
774+
775+
print(">>> Generating android toolchain\n");
776+
system("$androidNdkRoot/build/tools/make_standalone_toolchain.py --arch $platformRootPostfix --api $apiLevel --install-dir $androidToolchain");
788777

789778
if ($runningOnWindows)
790779
{
@@ -817,56 +806,39 @@
817806
die("Failed to locate android platform root\n");
818807
}
819808

820-
if ("$androidArch" eq 'armv5')
821-
{
822-
$ENV{CFLAGS} = "-DARM_FPU_NONE=1 -march=armv5te -mtune=xscale -msoft-float";
823-
}
824-
elsif ("$androidArch" eq 'armv6_vfp')
809+
if ($androidArch eq "armv7a")
825810
{
826-
$ENV{CFLAGS} = "-DARM_FPU_VFP=1 -march=armv6 -mtune=xscale -msoft-float -mfloat-abi=softfp -mfpu=vfp -DHAVE_ARMV6=1";
827-
}
828-
elsif ("$androidArch" eq 'armv7a')
829-
{
830-
$ENV{CFLAGS} = "-DARM_FPU_VFP=1 -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -DHAVE_ARMV6=1";
831-
$ENV{LDFLAGS} = "-Wl,--fix-cortex-a8";
832-
}
833-
elsif ("$androidArch" eq 'x86')
834-
{
835-
$ENV{LDFLAGS} = "-lgcc"
836-
}
837-
else
838-
{
839-
die("Unsupported android arch : $androidArch\n");
811+
$ENV{CFLAGS} = "-DARM_FPU_VFP=1 -march=armv7-a -target armv7-none-linux-androideabi -DHAVE_ARMV6=1 -funwind-tables $ENV{CFLAGS}";
812+
$ENV{LDFLAGS} = "-Wl,--fix-cortex-a8 -Wl,-rpath-link=$androidPlatformRoot/usr/lib $ENV{LDFLAGS}";
840813
}
841814

842-
if ($isArmArch)
843-
{
844-
$ENV{CFLAGS} = "-funwind-tables $ENV{CFLAGS}";
845-
$ENV{LDFLAGS} = "-Wl,-rpath-link=$androidPlatformRoot/usr/lib $ENV{LDFLAGS}";
846-
}
815+
my $compilerSysroot = "$androidNdkRoot/sysroot";
816+
my $archISystem = "$compilerSysroot/usr/include/$hostTriple";
817+
my $unifiedISystem = "$compilerSysroot/usr/include";
818+
819+
$ENV{CC} = "$androidToolchain/bin/clang -v -isystem $archISystem -isystem $unifiedISystem";
820+
$ENV{CXX} = "$androidToolchain/bin/clang++ -isystem $archISystem -isystem $unifiedISystem";
821+
$ENV{CPP} = "$androidToolchain/bin/clang -E -isystem $archISystem -isystem $unifiedISystem";
822+
$ENV{CXXCPP} = "$androidToolchain/bin/clang++ -E -isystem $archISystem -isystem $unifiedISystem";
847823

848-
$ENV{PATH} = "$androidToolchain/bin:$ENV{PATH}";
849-
$ENV{CC} = "$androidToolchain/bin/$ENV{GCC_PREFIX}gcc$toolChainExtension --sysroot=$androidPlatformRoot";
850-
$ENV{CXX} = "$androidToolchain/bin/$ENV{GCC_PREFIX}g++$toolChainExtension --sysroot=$androidPlatformRoot";
851-
$ENV{CPP} = "$androidToolchain/bin/$ENV{GCC_PREFIX}cpp$toolChainExtension";
852-
$ENV{CXXCPP} = "$androidToolchain/bin/$ENV{GCC_PREFIX}cpp$toolChainExtension";
853824
$ENV{CPATH} = "$androidPlatformRoot/usr/include";
854-
$ENV{LD} = "$androidToolchain/bin/$ENV{GCC_PREFIX}ld$toolChainExtension";
855-
$ENV{AS} = "$androidToolchain/bin/$ENV{GCC_PREFIX}as$toolChainExtension";
856-
$ENV{AR} = "$androidToolchain/bin/$ENV{GCC_PREFIX}ar$toolChainExtension";
857-
$ENV{RANLIB} = "$androidToolchain/bin/$ENV{GCC_PREFIX}ranlib$toolChainExtension";
858-
$ENV{STRIP} = "$androidToolchain/bin/$ENV{GCC_PREFIX}strip$toolChainExtension";
859825

860-
$ENV{CFLAGS} = "-DANDROID -DPLATFORM_ANDROID -DLINUX -D__linux__ -DHAVE_USR_INCLUDE_MALLOC_H -DPAGE_SIZE=0x1000 -D_POSIX_PATH_MAX=256 -DS_IWRITE=S_IWUSR -DHAVE_PTHREAD_MUTEX_TIMEDLOCK -fpic -g -ffunction-sections -fdata-sections $ENV{CFLAGS}";
826+
$ENV{LD} = "$androidToolchain/bin/$hostTriple-ld";
827+
$ENV{AS} = "$androidToolchain/bin/$hostTriple-as";
828+
$ENV{AR} = "$androidToolchain/bin/$hostTriple-ar";
829+
$ENV{RANLIB} = "$androidToolchain/bin/$hostTriple-ranlib";
830+
$ENV{STRIP} = "$androidToolchain/bin/$hostTriple-strip";
831+
832+
$ENV{CFLAGS} = "-DANDROID -D__ANDROID_API__=16 -DPLATFORM_ANDROID -DLINUX -D__linux__ -DHAVE_USR_INCLUDE_MALLOC_H -D_POSIX_PATH_MAX=256 -DS_IWRITE=S_IWUSR -DHAVE_PTHREAD_MUTEX_TIMEDLOCK -fpic -g -ffunction-sections -fdata-sections $ENV{CFLAGS}";
861833
$ENV{CXXFLAGS} = $ENV{CFLAGS};
862834
$ENV{CPPFLAGS} = $ENV{CFLAGS};
863835

864836
if ($useKraitPatch)
865837
{
866-
$ENV{LDFLAGS} = "-Wl,--wrap,sigaction -L$kraitPatchPath/obj/local/armeabi -lkrait-signal-handler $ENV{LDFLAGS}";
838+
$ENV{LDFLAGS} = "-Wl,--wrap,sigaction -L$kraitPatchPath/obj/local/armeabi-v7a -lkrait-signal-handler $ENV{LDFLAGS}";
867839
}
868840

869-
$ENV{LDFLAGS} = "-Wl,--no-undefined -Wl,--gc-sections -ldl -lm -llog -lc $ENV{LDFLAGS}";
841+
$ENV{LDFLAGS} = "--sysroot=$androidPlatformRoot -Wl,--no-undefined -Wl,--gc-sections -ldl -lm -llog -lc $ENV{LDFLAGS}";
870842

871843
print "\n";
872844
print ">>> Environment:\n";
@@ -903,18 +875,7 @@
903875
chdir("$monoroot") eq 1 or die ("failed to chdir to $monoroot\n");
904876
}
905877

906-
if ($isArmArch)
907-
{
908-
push @configureparams, "--host=armv5-linux-androideabi";
909-
}
910-
elsif ("$androidArch" eq 'x86')
911-
{
912-
push @configureparams, "--host=i686-linux-android";
913-
}
914-
else
915-
{
916-
die("Unsupported android arch : $androidArch\n");
917-
}
878+
push @configureparams, "--host=$hostTriple";
918879

919880
push @configureparams, "--cache-file=android-$androidArch.cache" if ($enableCacheFile);
920881

external/buildscripts/build_runtime_android.pl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
# By default, build runtime for all the variants we need. But allow something to specify an individual variation to build
2222
if ($androidArch eq "")
2323
{
24-
system("perl", "$buildScriptsRoot/build.pl", "--build=1", "--clean=1", "--artifact=1", "--arch32=1", "--androidarch=armv5", "--forcedefaultbuilddeps=1", "--windowssubsystemforlinux=$windowsSubsystemForLinux") eq 0 or die ("Failed building mono for armv5\n");
25-
system("perl", "$buildScriptsRoot/build.pl", "--build=1", "--clean=1", "--artifact=1", "--arch32=1", "--androidarch=armv6_vfp", "--forcedefaultbuilddeps=1", "--windowssubsystemforlinux=$windowsSubsystemForLinux") eq 0 or die ("Failed building mono for armv6_vfp\n");
2624
system("perl", "$buildScriptsRoot/build.pl", "--build=1", "--clean=1", "--artifact=1", "--arch32=1", "--androidarch=armv7a", "--forcedefaultbuilddeps=1", "--windowssubsystemforlinux=$windowsSubsystemForLinux") eq 0 or die ("Failed building mono for armv7a\n");
2725
system("perl", "$buildScriptsRoot/build.pl", "--build=1", "--clean=1", "--artifact=1", "--arch32=1", "--androidarch=x86", "--forcedefaultbuilddeps=1", "--windowssubsystemforlinux=$windowsSubsystemForLinux") eq 0 or die ("Failed building mono for x86\n");
2826
}

mono/utils/mono-compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ typedef int32_t __mono_off32_t;
178178
* we must carefully declare the 32-bit mmap here without changing the ABI along the way. Carefully because
179179
* in this instance off_t is redeclared to be 64-bit and that's not what we want.
180180
*/
181-
void* mmap (void*, size_t, int, int, int, __mono_off32_t);
181+
//void* mmap (void*, size_t, int, int, int, __mono_off32_t);
182182
#endif /* !mmap */
183183

184184
#ifdef HAVE_SYS_SENDFILE_H

0 commit comments

Comments
 (0)