androidndk: remove legacy ndks

allows us to remove python2 dependencies and lot more
This commit is contained in:
Jari Vetoniemi 2022-06-29 18:24:50 +09:00
parent 539222e8d4
commit 2408ef3c6f
5 changed files with 19 additions and 143 deletions

View File

@ -1,5 +1,4 @@
{ lib, stdenv
, makeWrapper, python
{ lib, stdenv, makeWrapper
, runCommand, wrapBintoolsWith, wrapCCWith, autoPatchelfHook
, buildAndroidndk, androidndk, targetAndroidndkPkgs
}:
@ -24,30 +23,18 @@ let
i686-unknown-linux-android = {
triple = "i686-linux-android";
arch = "x86";
# LEGACY
toolchain = "x86";
gccVer = "4.9";
};
x86_64-unknown-linux-android = {
triple = "x86_64-linux-android";
arch = "x86_64";
# LEGACY
toolchain = "x86_64";
gccVer = "4.9";
};
armv7a-unknown-linux-androideabi = {
arch = "arm";
triple = "arm-linux-androideabi";
# LEGACY
toolchain = "arm-linux-androideabi";
gccVer = "4.9";
};
aarch64-unknown-linux-android = {
arch = "arm64";
triple = "aarch64-linux-android";
# LEGACY
toolchain = "aarch64-linux-android";
gccVer = "4.9";
};
}.${config} or
(throw "Android NDK doesn't support ${config}, as far as we know");
@ -70,7 +57,7 @@ rec {
binaries = stdenv.mkDerivation {
pname = "${targetConfig}-ndk-toolchain";
inherit (androidndk) version;
nativeBuildInputs = [ makeWrapper python autoPatchelfHook ];
nativeBuildInputs = [ makeWrapper autoPatchelfHook ];
propagatedBuildInputs = [ androidndk ];
passthru = {
isClang = true; # clang based cc, but bintools ld
@ -82,16 +69,10 @@ rec {
dontPatch = true;
autoPatchelfIgnoreMissingDeps = true;
installPhase = ''
if [ ! -d ${androidndk}/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/${buildInfo.double} ]; then
# LEGACY: make-standalone-toolchain is deprecated
# https://developer.android.com/ndk/guides/standalone_toolchain
${androidndk}/libexec/android-sdk/ndk-bundle/build/tools/make-standalone-toolchain.sh --arch=${targetInfo.arch} --install-dir=$out/toolchain --platform=${sdkVer} --force
else
# https://developer.android.com/ndk/guides/other_build_systems
mkdir -p $out
cp -r ${androidndk}/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/${buildInfo.double} $out/toolchain
find $out/toolchain -type d -exec chmod 777 {} \;
fi
# https://developer.android.com/ndk/guides/other_build_systems
mkdir -p $out
cp -r ${androidndk}/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/${buildInfo.double} $out/toolchain
find $out/toolchain -type d -exec chmod 777 {} \;
if [ ! -d $out/toolchain/sysroot/usr/lib/${targetInfo.triple}/${sdkVer} ]; then
echo "NDK does not contain libraries for SDK version ${sdkVer}";
@ -116,17 +97,8 @@ rec {
ln -s $f ''${f/${targetInfo.triple}/${targetConfig}}
done
# LEGACY: get rid of gcc and g++, otherwise wrapCCWith will use them instead of clang
rm -f $out/bin/${targetConfig}-gcc $out/bin/${targetConfig}-g++
# LEGACY: ld doesn't properly include transitive library dependencies.
# Let's use gold instead
rm -f $out/bin/${targetConfig}-ld
if [[ -f $out/bin/${targetConfig}-ld.gold ]]; then
ln -s $out/bin/${targetConfig}-ld.gold $out/bin/${targetConfig}-ld
else
ln -s $out/bin/lld $out/bin/${targetConfig}-ld
fi
ln -s $out/bin/lld $out/bin/${targetConfig}-ld
(cd $out/bin;
for tool in llvm-*; do
@ -156,18 +128,12 @@ rec {
libc = targetAndroidndkPkgs.libraries;
extraBuildCommands = ''
echo "-D__ANDROID_API__=${stdenv.targetPlatform.sdkVer}" >> $out/nix-support/cc-cflags
if [ ! -d ${androidndk}/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/${hostInfo.double} ]; then
# LEGACY: probably won't work for any recent android
echo "--gcc-toolchain=${androidndk}/libexec/android-sdk/ndk-bundle/toolchains/${targetInfo.toolchain}-${targetInfo.gccVer}/prebuilt/${hostInfo.double}" >> $out/nix-support/cc-cflags
echo "-fuse-ld=$out/bin/${targetConfig}-ld.gold -L${binaries}/lib" >> $out/nix-support/cc-ldflags
else
# Android needs executables linked with -pie since version 5.0
# Use -fPIC for compilation, and link with -pie if no -shared flag used in ldflags
echo "-target ${targetInfo.triple} -fPIC" >> $out/nix-support/cc-cflags
echo "-z,noexecstack -z,relro -z,now" >> $out/nix-support/cc-ldflags
echo 'if [[ ! " $@ " =~ " -shared " ]]; then NIX_LDFLAGS_${suffixSalt}+=" -pie"; fi' >> $out/nix-support/add-flags.sh
echo "-Xclang -mnoexecstack" >> $out/nix-support/cc-cxxflags
fi
# Android needs executables linked with -pie since version 5.0
# Use -fPIC for compilation, and link with -pie if no -shared flag used in ldflags
echo "-target ${targetInfo.triple} -fPIC" >> $out/nix-support/cc-cflags
echo "-z,noexecstack -z,relro -z,now" >> $out/nix-support/cc-ldflags
echo 'if [[ ! " $@ " =~ " -shared " ]]; then NIX_LDFLAGS_${suffixSalt}+=" -pie"; fi' >> $out/nix-support/add-flags.sh
echo "-Xclang -mnoexecstack" >> $out/nix-support/cc-cxxflags
if [ ${targetInfo.triple} == arm-linux-androideabi ]; then
# https://android.googlesource.com/platform/external/android-cmake/+/refs/heads/cmake-master-dev/android.toolchain.cmake
echo "--fix-cortex-a8" >> $out/nix-support/cc-ldflags
@ -181,12 +147,7 @@ rec {
# cross-compiling packages to wrap incorrectly wrap binaries we don't include
# anyways.
libraries = runCommand "bionic-prebuilt" {} ''
if [ -d ${buildAndroidndk}/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt ]; then
lpath=${buildAndroidndk}/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/${buildInfo.double}/sysroot/usr/lib/${targetInfo.triple}/${sdkVer}
else
# LEGACY
lpath=${buildAndroidndk}/libexec/android-sdk/ndk-bundle/platforms/android-${sdkVer}/arch-${hostInfo.arch}/usr/${if hostInfo.arch == "x86_64" then "lib64" else "lib"}
fi
lpath=${buildAndroidndk}/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/${buildInfo.double}/sysroot/usr/lib/${targetInfo.triple}/${sdkVer}
if [ ! -d $lpath ]; then
echo "NDK does not contain libraries for SDK version ${sdkVer} <$lpath>"
exit 1

View File

@ -2,36 +2,6 @@
}:
{
"18b" =
let
ndkVersion = "18.1.5063045";
buildAndroidComposition = buildPackages.buildPackages.androidenv.composeAndroidPackages {
includeNDK = true;
inherit ndkVersion;
};
androidComposition = androidenv.composeAndroidPackages {
includeNDK = true;
inherit ndkVersion;
};
in
import ./androidndk-pkgs.nix {
inherit lib;
inherit (buildPackages)
makeWrapper python autoPatchelfHook;
inherit (pkgs)
stdenv
runCommand wrapBintoolsWith wrapCCWith;
# buildPackages.foo rather than buildPackages.buildPackages.foo would work,
# but for splicing messing up on infinite recursion for the variants we
# *dont't* use. Using this workaround, but also making a test to ensure
# these two really are the same.
buildAndroidndk = buildAndroidComposition.ndk-bundle;
androidndk = androidComposition.ndk-bundle;
targetAndroidndkPkgs = targetPackages.androidndkPkgs_18b;
};
"21" =
let
ndkVersion = "21.0.6113669";
@ -49,7 +19,7 @@
import ./androidndk-pkgs.nix {
inherit lib;
inherit (buildPackages)
makeWrapper python autoPatchelfHook;
makeWrapper autoPatchelfHook;
inherit (pkgs)
stdenv
runCommand wrapBintoolsWith wrapCCWith;
@ -79,7 +49,7 @@
import ./androidndk-pkgs.nix {
inherit lib;
inherit (buildPackages)
makeWrapper python autoPatchelfHook;
makeWrapper autoPatchelfHook;
inherit (pkgs)
stdenv
runCommand wrapBintoolsWith wrapCCWith;
@ -109,7 +79,7 @@
import ./androidndk-pkgs.nix {
inherit lib;
inherit (buildPackages)
makeWrapper python autoPatchelfHook;
makeWrapper autoPatchelfHook;
inherit (pkgs)
stdenv
runCommand wrapBintoolsWith wrapCCWith;

View File

@ -12,20 +12,10 @@ deployAndroidPackage {
nativeBuildInputs = [ makeWrapper ]
++ lib.optionals stdenv.isLinux [ autoPatchelfHook ];
autoPatchelfIgnoreMissingDeps = true;
buildInputs = lib.optional (os == "linux") [ pkgs.glibc pkgs.stdenv.cc.cc pkgs.python2 pkgs.ncurses5 pkgs.zlib pkgs.libcxx.out pkgs.libxml2 ];
buildInputs = lib.optional (os == "linux") [ pkgs.zlib ];
patchInstructions = lib.optionalString (os == "linux") (''
patchShebangs .
# LEGACY: Fix the shebangs of the auto-generated scripts.
substituteInPlace ./build/tools/make_standalone_toolchain.py \
--replace '#!/bin/bash' '#!${pkgs.bash}/bin/bash'
'' + lib.optionalString (builtins.compareVersions (lib.getVersion package) "21" > 0) ''
patch -p1 \
--no-backup-if-mismatch < ${./make_standalone_toolchain.py_18.patch} || true
wrapProgram ./build/tools/make_standalone_toolchain.py --prefix PATH : "${runtime_paths}"
'' + ''
# TODO: allow this stuff
rm -rf docs tests

View File

@ -1,44 +0,0 @@
diff -Naur android-ndk-r18b/build/tools/make_standalone_toolchain.py android-ndk-r18b-new/build/tools/make_standalone_toolchain.py
--- android-ndk-r18b/build/tools/make_standalone_toolchain.py 2018-10-11 12:49:38.000000000 +0200
+++ android-ndk-r18b-new/build/tools/make_standalone_toolchain.py 2018-11-20 21:55:52.689991420 +0100
@@ -30,7 +30,7 @@
import sys
import tempfile
import textwrap
-
+import subprocess
THIS_DIR = os.path.realpath(os.path.dirname(__file__))
NDK_DIR = os.path.realpath(os.path.join(THIS_DIR, '../..'))
@@ -173,6 +173,7 @@
logger().debug('Copying %s', src_file)
shutil.copy2(src_file, dst_dir)
+ subprocess.check_call(["chmod", "-R", "+w", dst])
def make_clang_scripts(install_dir, triple, api, windows):
"""Creates Clang wrapper scripts.
@@ -365,6 +366,7 @@
install_headers = os.path.join(install_sysroot, 'usr/include')
os.makedirs(os.path.dirname(install_headers))
shutil.copytree(headers, install_headers)
+ subprocess.check_call(["chmod", "-R", "+w", install_path])
arch_headers = os.path.join(sysroot, 'usr/include', triple)
copy_directory_contents(arch_headers, os.path.join(install_headers))
@@ -375,6 +377,7 @@
install_sysroot, 'usr/lib{}'.format(lib_suffix))
if os.path.exists(lib_path):
shutil.copytree(lib_path, lib_install)
+ subprocess.check_call(["chmod", "-R", "+w", install_path])
static_lib_path = os.path.join(sysroot, 'usr/lib', triple)
static_lib_install = os.path.join(install_sysroot, 'usr/lib')
@@ -389,6 +392,7 @@
NDK_DIR, 'prebuilt', 'android-' + arch, 'gdbserver')
gdbserver_install = os.path.join(install_path, 'share', 'gdbserver')
shutil.copytree(gdbserver_path, gdbserver_install)
+ subprocess.check_call(["chmod", "-R", "+w", install_path])
toolchain_lib_dir = os.path.join(gcc_path, 'lib/gcc', triple)
dirs = os.listdir(toolchain_lib_dir)

View File

@ -2656,8 +2656,7 @@ with pkgs;
pkgs_i686 = pkgsi686Linux;
};
androidndkPkgs = androidndkPkgs_18b;
androidndkPkgs_18b = (callPackage ../development/androidndk-pkgs {})."18b";
androidndkPkgs = androidndkPkgs_21;
androidndkPkgs_21 = (callPackage ../development/androidndk-pkgs {})."21";
androidndkPkgs_23b = (callPackage ../development/androidndk-pkgs {})."23b";
androidndkPkgs_24 = (callPackage ../development/androidndk-pkgs {})."24";