Merge pull request #59253 from matthewbauer/android-fixes
Get Android cross working again
This commit is contained in:
commit
da3ad842c2
@ -44,14 +44,6 @@ rec {
|
|||||||
platform = platforms.aarch64-multiplatform;
|
platform = platforms.aarch64-multiplatform;
|
||||||
};
|
};
|
||||||
|
|
||||||
armv5te-android-prebuilt = rec {
|
|
||||||
config = "armv5tel-unknown-linux-androideabi";
|
|
||||||
sdkVer = "21";
|
|
||||||
ndkVer = "18b";
|
|
||||||
platform = platforms.armv5te-android;
|
|
||||||
useAndroidPrebuilt = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
armv7a-android-prebuilt = rec {
|
armv7a-android-prebuilt = rec {
|
||||||
config = "armv7a-unknown-linux-androideabi";
|
config = "armv7a-unknown-linux-androideabi";
|
||||||
sdkVer = "24";
|
sdkVer = "24";
|
||||||
|
@ -253,16 +253,6 @@ rec {
|
|||||||
kernelTarget = "zImage";
|
kernelTarget = "zImage";
|
||||||
};
|
};
|
||||||
|
|
||||||
# https://developer.android.com/ndk/guides/abis#armeabi
|
|
||||||
armv5te-android = {
|
|
||||||
name = "armeabi";
|
|
||||||
gcc = {
|
|
||||||
arch = "armv5te";
|
|
||||||
float = "soft";
|
|
||||||
float-abi = "soft";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
# https://developer.android.com/ndk/guides/abis#v7a
|
# https://developer.android.com/ndk/guides/abis#v7a
|
||||||
armv7a-android = {
|
armv7a-android = {
|
||||||
name = "armeabi-v7a";
|
name = "armeabi-v7a";
|
||||||
|
@ -18,19 +18,28 @@ let
|
|||||||
"x86_64-unknown-linux-gnu" = {
|
"x86_64-unknown-linux-gnu" = {
|
||||||
double = "linux-x86_64";
|
double = "linux-x86_64";
|
||||||
};
|
};
|
||||||
"armv5tel-unknown-linux-androideabi" = {
|
"i686-unknown-linux-android" = {
|
||||||
arch = "arm";
|
triple = "i686-linux-android";
|
||||||
triple = "arm-linux-androideabi";
|
arch = "x86";
|
||||||
gccVer = "4.8";
|
toolchain = "x86";
|
||||||
|
gccVer = "4.9";
|
||||||
|
};
|
||||||
|
"x86_64-unknown-linux-android" = {
|
||||||
|
triple = "x86_64-linux-android";
|
||||||
|
arch = "x86_64";
|
||||||
|
toolchain = "x86_64";
|
||||||
|
gccVer = "4.9";
|
||||||
};
|
};
|
||||||
"armv7a-unknown-linux-androideabi" = {
|
"armv7a-unknown-linux-androideabi" = {
|
||||||
arch = "arm";
|
arch = "arm";
|
||||||
triple = "arm-linux-androideabi";
|
triple = "arm-linux-androideabi";
|
||||||
|
toolchain = "arm-linux-androideabi";
|
||||||
gccVer = "4.9";
|
gccVer = "4.9";
|
||||||
};
|
};
|
||||||
"aarch64-unknown-linux-android" = {
|
"aarch64-unknown-linux-android" = {
|
||||||
arch = "arm64";
|
arch = "arm64";
|
||||||
triple = "aarch64-linux-android";
|
triple = "aarch64-linux-android";
|
||||||
|
toolchain = "aarch64-linux-android";
|
||||||
gccVer = "4.9";
|
gccVer = "4.9";
|
||||||
};
|
};
|
||||||
}.${config} or
|
}.${config} or
|
||||||
@ -38,49 +47,49 @@ let
|
|||||||
|
|
||||||
hostInfo = ndkInfoFun stdenv.hostPlatform;
|
hostInfo = ndkInfoFun stdenv.hostPlatform;
|
||||||
targetInfo = ndkInfoFun stdenv.targetPlatform;
|
targetInfo = ndkInfoFun stdenv.targetPlatform;
|
||||||
|
|
||||||
|
prefix = stdenv.lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) (stdenv.targetPlatform.config + "-");
|
||||||
in
|
in
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
# Misc tools
|
# Misc tools
|
||||||
binaries = let
|
binaries = runCommand "ndk-gcc-binutils" {
|
||||||
ndkBinDir =
|
isClang = true; # clang based cc, but bintools ld
|
||||||
"${androidndk}/libexec/android-sdk/ndk-bundle/toolchains/${targetInfo.triple}-${targetInfo.gccVer}/prebuilt/${hostInfo.double}/bin";
|
nativeBuildInputs = [ makeWrapper ];
|
||||||
ndkGCCLibDir =
|
propgatedBuildInputs = [ androidndk ];
|
||||||
"${androidndk}/libexec/android-sdk/ndk-bundle/toolchains/${targetInfo.triple}-${targetInfo.gccVer}/prebuilt/${hostInfo.double}/lib/gcc/${targetInfo.triple}/4.9.x";
|
} ''
|
||||||
|
mkdir -p $out/bin
|
||||||
|
|
||||||
in runCommand "ndk-gcc-binutils" {
|
# llvm toolchain
|
||||||
isGNU = true; # for cc-wrapper
|
for prog in ${androidndk}/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/${hostInfo.double}/bin/*; do
|
||||||
nativeBuildInputs = [ makeWrapper ];
|
ln -s $prog $out/bin/$(basename $prog)
|
||||||
propgatedBuildInputs = [ androidndk ];
|
ln -s $prog $out/bin/${prefix}$(basename $prog)
|
||||||
} ''
|
done
|
||||||
mkdir -p $out/bin
|
|
||||||
for prog in ${ndkBinDir}/${targetInfo.triple}-*; do
|
|
||||||
prog_suffix=$(basename $prog | sed 's/${targetInfo.triple}-//')
|
|
||||||
cat > $out/bin/${stdenv.targetPlatform.config}-$prog_suffix <<EOF
|
|
||||||
#! ${stdenv.shell} -e
|
|
||||||
$prog "\$@"
|
|
||||||
EOF
|
|
||||||
chmod +x $out/bin/${stdenv.targetPlatform.config}-$prog_suffix
|
|
||||||
done
|
|
||||||
|
|
||||||
ln -s $out/bin/${stdenv.targetPlatform.config}-ld $out/bin/ld
|
# bintools toolchain
|
||||||
ln -s ${ndkGCCLibDir} $out/lib
|
for prog in ${androidndk}/libexec/android-sdk/ndk-bundle/toolchains/${targetInfo.toolchain}-${targetInfo.gccVer}/prebuilt/${hostInfo.double}/bin/*; do
|
||||||
'';
|
prog_suffix=$(basename $prog | sed 's/${targetInfo.triple}-//')
|
||||||
|
ln -s $prog $out/bin/${stdenv.targetPlatform.config}-$prog_suffix
|
||||||
|
done
|
||||||
|
|
||||||
|
# shitty googly wrappers
|
||||||
|
rm -f $out/bin/${stdenv.targetPlatform.config}-gcc $out/bin/${stdenv.targetPlatform.config}-g++
|
||||||
|
'';
|
||||||
|
|
||||||
binutils = wrapBintoolsWith {
|
binutils = wrapBintoolsWith {
|
||||||
bintools = binaries;
|
bintools = binaries;
|
||||||
libc = targetAndroidndkPkgs.libraries;
|
libc = targetAndroidndkPkgs.libraries;
|
||||||
extraBuildCommands = ''
|
|
||||||
echo "--build-id" >> $out/nix-support/libc-ldflags
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
gcc = wrapCCWith {
|
clang = wrapCCWith {
|
||||||
cc = binaries;
|
cc = binaries;
|
||||||
bintools = binutils;
|
bintools = binutils;
|
||||||
libc = targetAndroidndkPkgs.libraries;
|
libc = targetAndroidndkPkgs.libraries;
|
||||||
extraBuildCommands = ''
|
extraBuildCommands = ''
|
||||||
echo "-D__ANDROID_API__=${stdenv.targetPlatform.sdkVer}" >> $out/nix-support/cc-cflags
|
echo "-D__ANDROID_API__=${stdenv.targetPlatform.sdkVer}" >> $out/nix-support/cc-cflags
|
||||||
|
echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
|
||||||
|
echo "-resource-dir=$(echo ${androidndk}/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/${hostInfo.double}/lib*/clang/*)" >> $out/nix-support/cc-cflags
|
||||||
|
echo "--gcc-toolchain=${androidndk}/libexec/android-sdk/ndk-bundle/toolchains/${targetInfo.toolchain}-${targetInfo.gccVer}/prebuilt/${hostInfo.double}" >> $out/nix-support/cc-cflags
|
||||||
''
|
''
|
||||||
+ lib.optionalString stdenv.targetPlatform.isAarch32 (let
|
+ lib.optionalString stdenv.targetPlatform.isAarch32 (let
|
||||||
p = stdenv.targetPlatform.platform.gcc or {}
|
p = stdenv.targetPlatform.platform.gcc or {}
|
||||||
@ -98,17 +107,10 @@ rec {
|
|||||||
sed -E -i \
|
sed -E -i \
|
||||||
$out/bin/${stdenv.targetPlatform.config}-cc \
|
$out/bin/${stdenv.targetPlatform.config}-cc \
|
||||||
$out/bin/${stdenv.targetPlatform.config}-c++ \
|
$out/bin/${stdenv.targetPlatform.config}-c++ \
|
||||||
$out/bin/${stdenv.targetPlatform.config}-gcc \
|
$out/bin/${stdenv.targetPlatform.config}-clang \
|
||||||
$out/bin/${stdenv.targetPlatform.config}-g++ \
|
$out/bin/${stdenv.targetPlatform.config}-clang++ \
|
||||||
-e '130i extraBefore+=(-Wl,--fix-cortex-a8)' \
|
-e 's|^(extraBefore=)\((.*)\)$|\1(\2 -Wl,--fix-cortex-a8 ${builtins.toString flags})|'
|
||||||
-e 's|^(extraBefore=)\(\)$|\1(${builtins.toString flags})|'
|
'');
|
||||||
'')
|
|
||||||
# GCC 4.9 is the first relase with "-fstack-protector"
|
|
||||||
+ lib.optionalString (lib.versionOlder targetInfo.gccVer "4.9") ''
|
|
||||||
sed -E \
|
|
||||||
-i $out/nix-support/add-hardening.sh \
|
|
||||||
-e 's|(-fstack-protector)-strong|\1|g'
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# Bionic lib C and other libraries.
|
# Bionic lib C and other libraries.
|
||||||
@ -116,17 +118,11 @@ rec {
|
|||||||
# We use androidndk from the previous stage, else we waste time or get cycles
|
# We use androidndk from the previous stage, else we waste time or get cycles
|
||||||
# cross-compiling packages to wrap incorrectly wrap binaries we don't include
|
# cross-compiling packages to wrap incorrectly wrap binaries we don't include
|
||||||
# anyways.
|
# anyways.
|
||||||
libraries =
|
libraries = runCommand "bionic-prebuilt" {} ''
|
||||||
let
|
mkdir -p $out
|
||||||
includePath = "${buildAndroidndk}/libexec/android-sdk/ndk-bundle/sysroot/usr/include";
|
cp -r ${buildAndroidndk}/libexec/android-sdk/ndk-bundle/sysroot/usr/include $out/include
|
||||||
asmIncludePath = "${buildAndroidndk}/libexec/android-sdk/ndk-bundle/sysroot/usr/include/${targetInfo.triple}";
|
chmod +w $out/include
|
||||||
libPath = "${buildAndroidndk}/libexec/android-sdk/ndk-bundle/platforms/android-${stdenv.hostPlatform.sdkVer}/arch-${hostInfo.arch}/usr/lib/";
|
cp -r ${buildAndroidndk}/libexec/android-sdk/ndk-bundle/sysroot/usr/include/${targetInfo.triple}/* $out/include
|
||||||
in
|
ln -s ${buildAndroidndk}/libexec/android-sdk/ndk-bundle/platforms/android-${stdenv.hostPlatform.sdkVer}/arch-${hostInfo.arch}/usr/lib $out/lib
|
||||||
runCommand "bionic-prebuilt" {} ''
|
'';
|
||||||
mkdir -p $out
|
|
||||||
cp -r ${includePath} $out/include
|
|
||||||
chmod +w $out/include
|
|
||||||
cp -r ${asmIncludePath}/* $out/include
|
|
||||||
ln -s ${libPath} $out/lib
|
|
||||||
'';
|
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ stdenv.mkDerivation rec {
|
|||||||
patches =
|
patches =
|
||||||
[ ./link-against-ncurses.patch
|
[ ./link-against-ncurses.patch
|
||||||
./no-arch_only-6.3.patch
|
./no-arch_only-6.3.patch
|
||||||
]
|
] ++ stdenv.lib.optional stdenv.hostPlatform.useAndroidPrebuilt ./android.patch
|
||||||
++
|
++
|
||||||
(let
|
(let
|
||||||
patch = nr: sha256:
|
patch = nr: sha256:
|
||||||
|
16
pkgs/development/libraries/readline/android.patch
Normal file
16
pkgs/development/libraries/readline/android.patch
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
diff --git histlib.h histlib.h
|
||||||
|
index c938a10..925ab72 100644
|
||||||
|
--- histlib.h
|
||||||
|
+++ histlib.h
|
||||||
|
@@ -51,9 +51,9 @@
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef member
|
||||||
|
-# ifndef strchr
|
||||||
|
+# if !defined (strchr) && !defined (__STDC__)
|
||||||
|
extern char *strchr ();
|
||||||
|
-# endif
|
||||||
|
+# endif /* !strchr && !__STDC__ */
|
||||||
|
#define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0)
|
||||||
|
#endif
|
||||||
|
|
@ -53,7 +53,7 @@ in lib.init bootStages ++ [
|
|||||||
cc = if crossSystem.useiOSPrebuilt or false
|
cc = if crossSystem.useiOSPrebuilt or false
|
||||||
then buildPackages.darwin.iosSdkPkgs.clang
|
then buildPackages.darwin.iosSdkPkgs.clang
|
||||||
else if crossSystem.useAndroidPrebuilt or false
|
else if crossSystem.useAndroidPrebuilt or false
|
||||||
then buildPackages."androidndkPkgs_${crossSystem.ndkVer}".gcc
|
then buildPackages."androidndkPkgs_${crossSystem.ndkVer}".clang
|
||||||
else if crossSystem.useLLVM or false
|
else if crossSystem.useLLVM or false
|
||||||
then buildPackages.llvmPackages_7.lldClang
|
then buildPackages.llvmPackages_7.lldClang
|
||||||
else buildPackages.gcc;
|
else buildPackages.gcc;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user