androidndk: Add makeStandaloneToolchain
support
Example: ``` let toolchain = (androidenv.androidndk.makeStandaloneToolchain 24 "arm64"); in ... ```
This commit is contained in:
parent
48bdf31f58
commit
dd0b3dafc9
@ -1,100 +1,110 @@
|
|||||||
{ stdenv, fetchurl, zlib, ncurses5, unzip, lib, makeWrapper
|
{ stdenv, fetchurl, zlib, ncurses5, unzip, lib, makeWrapper
|
||||||
, coreutils, file, findutils, gawk, gnugrep, gnused, jdk, which
|
, coreutils, file, findutils, gawk, gnugrep, gnused, jdk, which
|
||||||
, platformTools, python3, libcxx, version, sha256, bash
|
, platformTools, python3, libcxx, version, sha256, bash, runCommand
|
||||||
, fullNDK ? false # set to true if you want other parts of the NDK
|
, fullNDK ? false # set to true if you want other parts of the NDK
|
||||||
# that is not used by Nixpkgs like sources,
|
# that is not used by Nixpkgs like sources,
|
||||||
# examples, docs, or LLVM toolchains
|
# examples, docs, or LLVM toolchains
|
||||||
}:
|
}:
|
||||||
|
|
||||||
stdenv.mkDerivation rec {
|
let
|
||||||
name = "android-ndk-r${version}";
|
makeStandaloneToolchain = api: arch: let
|
||||||
inherit version;
|
full_ndk = (ndk true);
|
||||||
|
in runCommand "makeStandaloneToolchain-${version}" {} ''
|
||||||
|
${full_ndk}/libexec/${full_ndk.name}/build/tools/make_standalone_toolchain.py --api ${toString api} --arch ${arch} --install-dir $out
|
||||||
|
'';
|
||||||
|
ndk = fullNDK: stdenv.mkDerivation rec {
|
||||||
|
name = "android-ndk-r${version}";
|
||||||
|
inherit version;
|
||||||
|
|
||||||
src = if stdenv.hostPlatform.system == "x86_64-linux" then fetchurl {
|
src = if stdenv.hostPlatform.system == "x86_64-linux" then fetchurl {
|
||||||
url = "https://dl.google.com/android/repository/${name}-linux-x86_64.zip";
|
url = "https://dl.google.com/android/repository/${name}-linux-x86_64.zip";
|
||||||
inherit sha256;
|
inherit sha256;
|
||||||
} else throw "platform ${stdenv.hostPlatform.system} not supported!";
|
} else throw "platform ${stdenv.hostPlatform.system} not supported!";
|
||||||
|
|
||||||
phases = "buildPhase";
|
phases = "buildPhase";
|
||||||
|
|
||||||
nativeBuildInputs = [ unzip makeWrapper file ];
|
nativeBuildInputs = [ unzip makeWrapper file ];
|
||||||
|
|
||||||
buildCommand = let
|
buildCommand = let
|
||||||
bin_path = "$out/bin";
|
bin_path = "$out/bin";
|
||||||
pkg_path = "$out/libexec/${name}";
|
pkg_path = "$out/libexec/${name}";
|
||||||
sed_script_1 =
|
sed_script_1 =
|
||||||
"'s|^PROGDIR=`dirname $0`" +
|
"'s|^PROGDIR=`dirname $0`" +
|
||||||
"|PROGDIR=`dirname $(readlink -f $(which $0))`|'";
|
"|PROGDIR=`dirname $(readlink -f $(which $0))`|'";
|
||||||
runtime_paths = (lib.makeBinPath [
|
runtime_paths = (lib.makeBinPath [
|
||||||
coreutils file findutils
|
coreutils file findutils
|
||||||
gawk gnugrep gnused
|
gawk gnugrep gnused
|
||||||
jdk python3 which
|
jdk python3 which
|
||||||
]) + ":${platformTools}/platform-tools";
|
]) + ":${platformTools}/platform-tools";
|
||||||
in ''
|
in ''
|
||||||
mkdir -pv $out/libexec
|
mkdir -pv $out/libexec
|
||||||
cd $out/libexec
|
cd $out/libexec
|
||||||
unzip -qq $src
|
unzip -qq $src
|
||||||
|
|
||||||
# so that it doesn't fail because of read-only permissions set
|
# so that it doesn't fail because of read-only permissions set
|
||||||
cd -
|
cd -
|
||||||
${if (version == "10e") then
|
${if (version == "10e") then
|
||||||
''
|
''
|
||||||
patch -p1 \
|
patch -p1 \
|
||||||
--no-backup-if-mismatch \
|
--no-backup-if-mismatch \
|
||||||
-d $out/libexec/${name} < ${ ./make-standalone-toolchain_r10e.patch }
|
-d $out/libexec/${name} < ${ ./make-standalone-toolchain_r10e.patch }
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
''
|
''
|
||||||
patch -p1 \
|
patch -p1 \
|
||||||
--no-backup-if-mismatch \
|
--no-backup-if-mismatch \
|
||||||
-d $out/libexec/${name} < ${ ./. + "/make_standalone_toolchain.py_${version}.patch" }
|
-d $out/libexec/${name} < ${ ./. + "/make_standalone_toolchain.py_" + "${version}" + ".patch" }
|
||||||
|
|
||||||
sed -i 's,#!/usr/bin/env python,#!${python3}/bin/python,g' ${pkg_path}/build/tools/make_standalone_toolchain.py
|
sed -i 's,#!/usr/bin/env python,#!${python3}/bin/python,g' ${pkg_path}/build/tools/make_standalone_toolchain.py
|
||||||
sed -i 's,#!/bin/bash,#!${bash}/bin/bash,g' ${pkg_path}/build/tools/make_standalone_toolchain.py
|
sed -i 's,#!/bin/bash,#!${bash}/bin/bash,g' ${pkg_path}/build/tools/make_standalone_toolchain.py
|
||||||
wrapProgram ${pkg_path}/build/tools/make_standalone_toolchain.py --prefix PATH : "${runtime_paths}"
|
wrapProgram ${pkg_path}/build/tools/make_standalone_toolchain.py --prefix PATH : "${runtime_paths}"
|
||||||
''
|
''
|
||||||
}
|
}
|
||||||
|
|
||||||
patchShebangs ${pkg_path}
|
patchShebangs ${pkg_path}
|
||||||
|
|
||||||
cd ${pkg_path}
|
cd ${pkg_path}
|
||||||
|
|
||||||
'' + lib.optionalString (!fullNDK) ''
|
'' + lib.optionalString (!fullNDK) ''
|
||||||
# Steps to reduce output size
|
# Steps to reduce output size
|
||||||
rm -rf docs sources tests
|
rm -rf docs sources tests
|
||||||
# We only support cross compiling with gcc for now
|
# We only support cross compiling with gcc for now
|
||||||
rm -rf toolchains/*-clang* toolchains/llvm*
|
rm -rf toolchains/*-clang* toolchains/llvm*
|
||||||
'' +
|
'' +
|
||||||
|
|
||||||
''
|
''
|
||||||
find ${pkg_path}/toolchains \( \
|
find ${pkg_path}/toolchains \( \
|
||||||
\( -type f -a -name "*.so*" \) -o \
|
\( -type f -a -name "*.so*" \) -o \
|
||||||
\( -type f -a -perm -0100 \) \
|
\( -type f -a -perm -0100 \) \
|
||||||
\) -exec patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-*so.? \
|
\) -exec patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-*so.? \
|
||||||
--set-rpath ${stdenv.lib.makeLibraryPath [ libcxx zlib ncurses5 ]} {} \;
|
--set-rpath ${stdenv.lib.makeLibraryPath [ libcxx zlib ncurses5 ]} {} \;
|
||||||
# fix ineffective PROGDIR / MYNDKDIR determination
|
# fix ineffective PROGDIR / MYNDKDIR determination
|
||||||
for i in ndk-build ${lib.optionalString (version == "10e") "ndk-gdb ndk-gdb-py"}
|
for i in ndk-build ${lib.optionalString (version == "10e") "ndk-gdb ndk-gdb-py"}
|
||||||
do
|
do
|
||||||
sed -i -e ${sed_script_1} $i
|
sed -i -e ${sed_script_1} $i
|
||||||
done
|
done
|
||||||
|
|
||||||
# wrap
|
# wrap
|
||||||
for i in ndk-build ${lib.optionalString (version == "10e") "ndk-gdb ndk-gdb-py ndk-which"}
|
for i in ndk-build ${lib.optionalString (version == "10e") "ndk-gdb ndk-gdb-py ndk-which"}
|
||||||
do
|
do
|
||||||
wrapProgram "$(pwd)/$i" --prefix PATH : "${runtime_paths}"
|
wrapProgram "$(pwd)/$i" --prefix PATH : "${runtime_paths}"
|
||||||
done
|
done
|
||||||
# make some executables available in PATH
|
# make some executables available in PATH
|
||||||
mkdir -pv ${bin_path}
|
mkdir -pv ${bin_path}
|
||||||
for i in \
|
for i in \
|
||||||
ndk-build ${lib.optionalString (version == "10e") "ndk-depends ndk-gdb ndk-gdb-py ndk-gdb.py ndk-stack ndk-which"}
|
ndk-build ${lib.optionalString (version == "10e") "ndk-depends ndk-gdb ndk-gdb-py ndk-gdb.py ndk-stack ndk-which"}
|
||||||
do
|
do
|
||||||
ln -sf ${pkg_path}/$i ${bin_path}/$i
|
ln -sf ${pkg_path}/$i ${bin_path}/$i
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
platforms = stdenv.lib.platforms.linux;
|
platforms = stdenv.lib.platforms.linux;
|
||||||
hydraPlatforms = [];
|
hydraPlatforms = [];
|
||||||
license = stdenv.lib.licenses.asl20;
|
license = stdenv.lib.licenses.asl20;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
passthru = {
|
||||||
|
inherit makeStandaloneToolchain;
|
||||||
|
};
|
||||||
|
in lib.extendDerivation true passthru (ndk fullNDK)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user