# Pastebin ICXIis3t --- a/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix +++ b/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix @@ -1,6 +1,7 @@ -{ lib, stdenv +{ lib , makeWrapper -, runCommand, wrapBintoolsWith, wrapCCWith +, pkgs +#, runCommand, wrapBintoolsWith, wrapCCWith , buildAndroidndk, androidndk, targetAndroidndkPkgs }: @@ -45,56 +46,62 @@ let }.${config} or (throw "Android NDK doesn't support ${config}, as far as we know"); - hostInfo = ndkInfoFun stdenv.hostPlatform; - targetInfo = ndkInfoFun stdenv.targetPlatform; + hostInfo = ndkInfoFun pkgs.stdenv.hostPlatform; + targetInfo = ndkInfoFun pkgs.stdenv.targetPlatform; - prefix = lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) (stdenv.targetPlatform.config + "-"); + sdkVer = pkgs.stdenv.targetPlatform.sdkVer; + prefix = lib.optionalString (pkgs.stdenv.targetPlatform != pkgs.stdenv.hostPlatform) (pkgs.stdenv.targetPlatform.config + "-"); in rec { # Misc tools - binaries = runCommand "ndk-toolchain-binutils" { + binaries = pkgs.runCommand "ndk-toolchain-binutils" { pname = "ndk-toolchain-binutils"; inherit (androidndk) version; isClang = true; # clang based cc, but bintools ld - nativeBuildInputs = [ makeWrapper ]; + nativeBuildInputs = [ makeWrapper pkgs.python ]; + propagatedBuildInputs = [ androidndk ]; } '' - mkdir -p $out/bin + mkdir -p $out/ + ${androidndk}/libexec/android-sdk/ndk-bundle/build/tools/make-standalone-toolchain.sh --arch=${targetInfo.arch} --install-dir=$out/toolchain --platform=${sdkVer} + mkdir -p $out/lib + cp $out/toolchain/sysroot/usr/lib/${targetInfo.triple}/*.so $out/lib/ + cp $out/toolchain/sysroot/usr/lib/${targetInfo.triple}/*.a $out/lib/ + chmod +w $out/lib/* + cp $out/toolchain/sysroot/usr/lib/${targetInfo.triple}/${sdkVer}/*.so $out/lib/ + cp $out/toolchain/sysroot/usr/lib/${targetInfo.triple}/${sdkVer}/*.a $out/lib/ + cp $out/toolchain/sysroot/usr/lib/${targetInfo.triple}/${sdkVer}/*.o $out/lib/ - # llvm toolchain - for prog in ${androidndk}/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/${hostInfo.double}/bin/*; do - ln -s $prog $out/bin/$(basename $prog) - ln -s $prog $out/bin/${prefix}$(basename $prog) - done + ln -s $out/toolchain/bin $out/bin + patchShebangs $out/bin/ - # bintools toolchain - 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 + for f in $out/toolchain/${targetInfo.triple}/bin/*; do + ln -s $f $out/bin/$(basename $f) done - # shitty googly wrappers - rm -f $out/bin/${stdenv.targetPlatform.config}-gcc $out/bin/${stdenv.targetPlatform.config}-g++ + ''; - binutils = wrapBintoolsWith { + binutils = pkgs.wrapBintoolsWith { bintools = binaries; libc = targetAndroidndkPkgs.libraries; }; - clang = wrapCCWith { + clang = pkgs.wrapCCWith { cc = binaries // { - # for packages expecting libcompiler-rt, etc. to come from here (stdenv.cc.cc.lib) + # for packages expecting libcompiler-rt, etc. to come from here (pkgs.stdenv.cc.cc.lib) lib = targetAndroidndkPkgs.libraries; }; bintools = binutils; libc = targetAndroidndkPkgs.libraries; extraBuildCommands = '' - echo "-D__ANDROID_API__=${stdenv.targetPlatform.sdkVer}" >> $out/nix-support/cc-cflags - echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags + echo "NIX_SUPPORT": $out/nix-support + echo "-D__ANDROID_API__=${pkgs.stdenv.targetPlatform.sdkVer}" >> $out/nix-support/cc-cflags + echo "-target ${targetInfo.toolchain}" >> $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 + echo "-L${binaries}/lib" >> $out/nix-support/cc-cflags ''; }; @@ -103,11 +110,10 @@ rec { # 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 # anyways. - libraries = runCommand "bionic-prebuilt" {} '' - mkdir -p $out - cp -r ${buildAndroidndk}/libexec/android-sdk/ndk-bundle/sysroot/usr/include $out/include - chmod +w $out/include - cp -r ${buildAndroidndk}/libexec/android-sdk/ndk-bundle/sysroot/usr/include/${targetInfo.triple}/* $out/include - ln -s ${buildAndroidndk}/libexec/android-sdk/ndk-bundle/platforms/android-${stdenv.hostPlatform.sdkVer}/arch-${hostInfo.arch}/usr/${if hostInfo.arch == "x86_64" then "lib64" else "lib"} $out/lib + libraries = pkgs.runCommand "bionic-prebuilt" {} '' + mkdir -p $out/lib + cp ${buildAndroidndk}/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/${targetInfo.triple}/*.so $out/lib + cp ${buildAndroidndk}/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/${targetInfo.triple}/*.a $out/lib + cp ${buildAndroidndk}/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/${targetInfo.triple}/${sdkVer}/* $out/lib ''; } diff --git a/pkgs/development/androidndk-pkgs/default.nix b/pkgs/development/androidndk-pkgs/default.nix index 5f71304d385..14531a2879e 100644 --- a/pkgs/development/androidndk-pkgs/default.nix +++ b/pkgs/development/androidndk-pkgs/default.nix @@ -50,9 +50,7 @@ inherit lib; inherit (buildPackages) makeWrapper; - inherit (pkgs) - stdenv - runCommand wrapBintoolsWith wrapCCWith; + inherit pkgs; # 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