summary refs log tree commit diff
path: root/pkgs/development
diff options
context:
space:
mode:
authorJohn Ericson <Ericson2314@yahoo.com>2018-02-27 18:21:55 -0500
committerGitHub <noreply@github.com>2018-02-27 18:21:55 -0500
commitd31fb808af6273afd076cc6333fd0d7f28a675de (patch)
treeeddfd7f0fa0e2e3cf06bc60c8578cb4dcb4ddc17 /pkgs/development
parent822526f09e91f65081bc780803f23cc0997ff4ab (diff)
parent3a672cb7d2194f859bf8b576359488ddb088aca5 (diff)
downloadnixlib-d31fb808af6273afd076cc6333fd0d7f28a675de.tar
nixlib-d31fb808af6273afd076cc6333fd0d7f28a675de.tar.gz
nixlib-d31fb808af6273afd076cc6333fd0d7f28a675de.tar.bz2
nixlib-d31fb808af6273afd076cc6333fd0d7f28a675de.tar.lz
nixlib-d31fb808af6273afd076cc6333fd0d7f28a675de.tar.xz
nixlib-d31fb808af6273afd076cc6333fd0d7f28a675de.tar.zst
nixlib-d31fb808af6273afd076cc6333fd0d7f28a675de.zip
Merge pull request #35451 from obsidiansystems/android-cross
Android Cross compilation
Diffstat (limited to 'pkgs/development')
-rw-r--r--pkgs/development/libraries/libiconv/default.nix5
-rw-r--r--pkgs/development/libraries/ncurses/default.nix4
-rw-r--r--pkgs/development/mobile/androidenv/androidndk-pkgs.nix82
-rw-r--r--pkgs/development/mobile/androidenv/default.nix15
4 files changed, 104 insertions, 2 deletions
diff --git a/pkgs/development/libraries/libiconv/default.nix b/pkgs/development/libraries/libiconv/default.nix
index 091c6377cb1c..b55fc18cb69b 100644
--- a/pkgs/development/libraries/libiconv/default.nix
+++ b/pkgs/development/libraries/libiconv/default.nix
@@ -1,5 +1,6 @@
 { fetchurl, stdenv, lib
 , buildPlatform, hostPlatform
+, enableStatic ? stdenv.hostPlatform.useAndroidPrebuilt
 }:
 
 # assert !stdenv.isLinux || hostPlatform != buildPlatform; # TODO: improve on cross
@@ -19,8 +20,8 @@ stdenv.mkDerivation rec {
         sed '/^_GL_WARN_ON_USE (gets/d' -i srclib/stdio.in.h
       '';
 
-  configureFlags =
-    lib.optional stdenv.isFreeBSD "--with-pic";
+  configureFlags = lib.optional stdenv.isFreeBSD "--with-pic"
+    ++ lib.optional enableStatic "--enable-static";
 
   meta = {
     description = "An iconv(3) implementation";
diff --git a/pkgs/development/libraries/ncurses/default.nix b/pkgs/development/libraries/ncurses/default.nix
index d63536e75f06..f8a35e41cd61 100644
--- a/pkgs/development/libraries/ncurses/default.nix
+++ b/pkgs/development/libraries/ncurses/default.nix
@@ -3,6 +3,8 @@
 , abiVersion
 , mouseSupport ? false
 , unicode ? true
+, enableStatic ? stdenv.hostPlatform.useAndroidPrebuilt
+, withCxx ? !stdenv.hostPlatform.useAndroidPrebuilt
 
 , gpm
 
@@ -36,6 +38,8 @@ stdenv.mkDerivation rec {
     "--enable-pc-files"
     "--enable-symlinks"
   ] ++ lib.optional unicode "--enable-widec"
+    ++ lib.optional enableStatic "--enable-static"
+    ++ lib.optional (!withCxx) "--without-cxx"
     ++ lib.optional (abiVersion == "5") "--with-abi-version=5";
 
   # Only the C compiler, and explicitly not C++ compiler needs this flag on solaris:
diff --git a/pkgs/development/mobile/androidenv/androidndk-pkgs.nix b/pkgs/development/mobile/androidenv/androidndk-pkgs.nix
new file mode 100644
index 000000000000..19fc0dc812d8
--- /dev/null
+++ b/pkgs/development/mobile/androidenv/androidndk-pkgs.nix
@@ -0,0 +1,82 @@
+{ lib, hostPlatform, targetPlatform
+, makeWrapper
+, runCommand, wrapBintoolsWith, wrapCCWith
+, buildAndroidndk, androidndk, targetAndroidndkPkgs
+}:
+
+let
+  # Mapping from a platform to information needed to unpack NDK stuff for that
+  # platform.
+  #
+  # N.B. The Android NDK uses slightly different LLVM-style platform triples
+  # than we do. We don't just use theirs because ours are less ambiguous and
+  # some builds need that clarity.
+  ndkInfoFun = { config, ... }: {
+    "x86_64-unknown-linux-gnu" = {
+      double = "linux-x86_64";
+    };
+    "arm-unknown-linux-androideabi" = {
+      arch = "arm";
+      triple = "arm-linux-androideabi";
+      gccVer = "4.8";
+    };
+    "aarch64-unknown-linux-android" = {
+      arch = "arm64";
+      triple = "aarch64-linux-android";
+      gccVer = "4.9";
+    };
+  }.${config} or
+    (throw "Android NDK doesn't support ${config}, as far as we know");
+
+  hostInfo = ndkInfoFun hostPlatform;
+  targetInfo = ndkInfoFun targetPlatform;
+
+in
+
+rec {
+  # Misc tools
+  binaries = let
+      ndkBinDir =
+        "${androidndk}/libexec/${androidndk.name}/toolchains/${targetInfo.triple}-${targetInfo.gccVer}/prebuilt/${hostInfo.double}/bin";
+    in runCommand "ndk-gcc-binutils" {
+      isGNU = true; # for cc-wrapper
+      nativeBuildInputs = [ makeWrapper ];
+      propgatedBuildInputs = [ androidndk ];
+    } ''
+      mkdir -p $out/bin
+      for prog in ${ndkBinDir}/${targetInfo.triple}-*; do
+        prog_suffix=$(basename $prog | sed 's/${targetInfo.triple}-//')
+        ln -s $prog $out/bin/${targetPlatform.config}-$prog_suffix
+      done
+    '';
+
+  binutils = wrapBintoolsWith {
+    bintools = binaries;
+    libc = targetAndroidndkPkgs.libraries;
+  };
+
+  gcc = wrapCCWith {
+    cc = binaries;
+    bintools = binutils;
+    libc = targetAndroidndkPkgs.libraries;
+    extraBuildCommands =
+      # 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.
+  #
+  # 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 = {
+    name = "bionic-prebuilt";
+    type = "derivation";
+    outPath = "${buildAndroidndk}/libexec/${buildAndroidndk.name}/platforms/android-21/arch-${hostInfo.arch}/usr/";
+    drvPath = throw "fake derivation, build ${buildAndroidndk} to use";
+  };
+}
diff --git a/pkgs/development/mobile/androidenv/default.nix b/pkgs/development/mobile/androidenv/default.nix
index 98531eeb069e..c053712302dd 100644
--- a/pkgs/development/mobile/androidenv/default.nix
+++ b/pkgs/development/mobile/androidenv/default.nix
@@ -242,4 +242,19 @@ rec {
     inherit (pkgs) stdenv;
     inherit androidsdk;
   };
+
+  androidndkPkgs = import ./androidndk-pkgs.nix {
+    inherit (buildPackages)
+      makeWrapper;
+    inherit (pkgs)
+      lib hostPlatform targetPlatform
+      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 = buildPackages.buildPackages.androidenv.androidndk;
+    inherit androidndk;
+    targetAndroidndkPkgs = targetPackages.androidenv.androidndkPkgs;
+  };
 }