From 7fdf74bb932e479f6f68760fb1472967adad9aa4 Mon Sep 17 00:00:00 2001 From: Ken Micklas Date: Tue, 2 Apr 2019 12:45:37 -0400 Subject: [PATCH 1/6] androidndk-pkgs: Fix cc-wrapper flags (cherry picked from commit 5f4bf240f51124ffa19a5fa0ac48bf144768d9ff) --- pkgs/development/androidndk-pkgs/androidndk-pkgs.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix b/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix index e43dacce6250..aa266eb97feb 100644 --- a/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix +++ b/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix @@ -100,8 +100,7 @@ rec { $out/bin/${stdenv.targetPlatform.config}-c++ \ $out/bin/${stdenv.targetPlatform.config}-gcc \ $out/bin/${stdenv.targetPlatform.config}-g++ \ - -e '130i extraBefore+=(-Wl,--fix-cortex-a8)' \ - -e 's|^(extraBefore=)\(\)$|\1(${builtins.toString flags})|' + -e 's|^(extraBefore=)\((.*)\)$|\1(\2 -Wl,--fix-cortex-a8 ${builtins.toString flags})|' '') # GCC 4.9 is the first relase with "-fstack-protector" + lib.optionalString (lib.versionOlder targetInfo.gccVer "4.9") '' From fcbe865414256c3e03c02926e5592e24c5be801b Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Wed, 10 Apr 2019 01:23:02 -0400 Subject: [PATCH 2/6] androidndk: fixup mess MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New android ndk (18) now uses clang. We were going through the wrapper that are provided. This lead to surprising errors when building. Ideally we could use the llvm linker as well, but this leads to errors as many packages don’t support the llvm linker. --- lib/systems/examples.nix | 8 -- .../androidndk-pkgs/androidndk-pkgs.nix | 101 +++++++++--------- pkgs/stdenv/cross/default.nix | 2 +- 3 files changed, 50 insertions(+), 61 deletions(-) diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index ac1633a1a15f..657180ebcb6d 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -44,14 +44,6 @@ rec { 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 { config = "armv7a-unknown-linux-androideabi"; sdkVer = "24"; diff --git a/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix b/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix index aa266eb97feb..ab206158959d 100644 --- a/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix +++ b/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix @@ -18,19 +18,28 @@ let "x86_64-unknown-linux-gnu" = { double = "linux-x86_64"; }; - "armv5tel-unknown-linux-androideabi" = { - arch = "arm"; - triple = "arm-linux-androideabi"; - gccVer = "4.8"; + "i686-unknown-linux-android" = { + triple = "i686-linux-android"; + arch = "x86"; + toolchain = "x86"; + gccVer = "4.9"; + }; + "x86_64-unknown-linux-android" = { + triple = "x86_64-linux-android"; + arch = "x86_64"; + toolchain = "x86"; + gccVer = "4.9"; }; "armv7a-unknown-linux-androideabi" = { arch = "arm"; triple = "arm-linux-androideabi"; + toolchain = "arm-linux-androideabi"; gccVer = "4.9"; }; "aarch64-unknown-linux-android" = { arch = "arm64"; triple = "aarch64-linux-android"; + toolchain = "aarch64-linux-android"; gccVer = "4.9"; }; }.${config} or @@ -38,49 +47,49 @@ let hostInfo = ndkInfoFun stdenv.hostPlatform; targetInfo = ndkInfoFun stdenv.targetPlatform; + + prefix = stdenv.lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) (stdenv.targetPlatform.config + "-"); in rec { # Misc tools - binaries = let - ndkBinDir = - "${androidndk}/libexec/android-sdk/ndk-bundle/toolchains/${targetInfo.triple}-${targetInfo.gccVer}/prebuilt/${hostInfo.double}/bin"; - ndkGCCLibDir = - "${androidndk}/libexec/android-sdk/ndk-bundle/toolchains/${targetInfo.triple}-${targetInfo.gccVer}/prebuilt/${hostInfo.double}/lib/gcc/${targetInfo.triple}/4.9.x"; + binaries = runCommand "ndk-gcc-binutils" { + isClang = true; # clang based cc, but bintools ld + nativeBuildInputs = [ makeWrapper ]; + propgatedBuildInputs = [ androidndk ]; + } '' + mkdir -p $out/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}-//') - cat > $out/bin/${stdenv.targetPlatform.config}-$prog_suffix <> $out/nix-support/libc-ldflags - ''; }; - gcc = wrapCCWith { + clang = wrapCCWith { cc = binaries; 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 "-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 p = stdenv.targetPlatform.platform.gcc or {} @@ -98,16 +107,10 @@ rec { sed -E -i \ $out/bin/${stdenv.targetPlatform.config}-cc \ $out/bin/${stdenv.targetPlatform.config}-c++ \ - $out/bin/${stdenv.targetPlatform.config}-gcc \ - $out/bin/${stdenv.targetPlatform.config}-g++ \ + $out/bin/${stdenv.targetPlatform.config}-clang \ + $out/bin/${stdenv.targetPlatform.config}-clang++ \ -e 's|^(extraBefore=)\((.*)\)$|\1(\2 -Wl,--fix-cortex-a8 ${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. @@ -115,17 +118,11 @@ 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 = - let - includePath = "${buildAndroidndk}/libexec/android-sdk/ndk-bundle/sysroot/usr/include"; - asmIncludePath = "${buildAndroidndk}/libexec/android-sdk/ndk-bundle/sysroot/usr/include/${targetInfo.triple}"; - libPath = "${buildAndroidndk}/libexec/android-sdk/ndk-bundle/platforms/android-${stdenv.hostPlatform.sdkVer}/arch-${hostInfo.arch}/usr/lib/"; - in - 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 - ''; + 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/lib $out/lib + ''; } diff --git a/pkgs/stdenv/cross/default.nix b/pkgs/stdenv/cross/default.nix index aafc0855dbe3..7f3c1dd12348 100644 --- a/pkgs/stdenv/cross/default.nix +++ b/pkgs/stdenv/cross/default.nix @@ -53,7 +53,7 @@ in lib.init bootStages ++ [ cc = if crossSystem.useiOSPrebuilt or false then buildPackages.darwin.iosSdkPkgs.clang else if crossSystem.useAndroidPrebuilt or false - then buildPackages."androidndkPkgs_${crossSystem.ndkVer}".gcc + then buildPackages."androidndkPkgs_${crossSystem.ndkVer}".clang else buildPackages.gcc; extraNativeBuildInputs = old.extraNativeBuildInputs From 54b18fff9ab833e334bd76366606251e20ef4b1a Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Wed, 10 Apr 2019 01:25:52 -0400 Subject: [PATCH 3/6] readline: add android patch --- pkgs/development/libraries/readline/6.3.nix | 2 +- .../development/libraries/readline/android.patch | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/libraries/readline/android.patch diff --git a/pkgs/development/libraries/readline/6.3.nix b/pkgs/development/libraries/readline/6.3.nix index cbe6c083cb44..f9a20a535cb3 100644 --- a/pkgs/development/libraries/readline/6.3.nix +++ b/pkgs/development/libraries/readline/6.3.nix @@ -23,7 +23,7 @@ stdenv.mkDerivation rec { patches = [ ./link-against-ncurses.patch ./no-arch_only-6.3.patch - ] + ] ++ stdenv.lib.optional stdenv.hostPlatform.useAndroidPrebuilt ./android.patch ++ (let patch = nr: sha256: diff --git a/pkgs/development/libraries/readline/android.patch b/pkgs/development/libraries/readline/android.patch new file mode 100644 index 000000000000..7e81774be369 --- /dev/null +++ b/pkgs/development/libraries/readline/android.patch @@ -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 + From 9e1dd3b7c6453728792eb4adebd3fa4282d7f24d Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Wed, 10 Apr 2019 01:31:04 -0400 Subject: [PATCH 4/6] systems: remove android armv5te platform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this isn’t useful any more because the ndk we use no longer supports it. --- lib/systems/platforms.nix | 10 ---------- pkgs/development/androidndk-pkgs/androidndk-pkgs.nix | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/systems/platforms.nix b/lib/systems/platforms.nix index 03bfce256103..92de30162666 100644 --- a/lib/systems/platforms.nix +++ b/lib/systems/platforms.nix @@ -253,16 +253,6 @@ rec { 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 armv7a-android = { name = "armeabi-v7a"; diff --git a/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix b/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix index ab206158959d..fbd4fdf3d6bd 100644 --- a/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix +++ b/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix @@ -27,7 +27,7 @@ let "x86_64-unknown-linux-android" = { triple = "x86_64-linux-android"; arch = "x86_64"; - toolchain = "x86"; + toolchain = "x86_64"; gccVer = "4.9"; }; "armv7a-unknown-linux-androideabi" = { From f07df17b74a1d47549d310cb2f50d3627be3030c Mon Sep 17 00:00:00 2001 From: Ken Micklas Date: Tue, 16 Apr 2019 16:21:51 -0400 Subject: [PATCH 5/6] androidndk-pkgs: Remove -mfloat flag --- lib/systems/platforms.nix | 1 - pkgs/development/androidndk-pkgs/androidndk-pkgs.nix | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/systems/platforms.nix b/lib/systems/platforms.nix index 92de30162666..a2b43c970a41 100644 --- a/lib/systems/platforms.nix +++ b/lib/systems/platforms.nix @@ -258,7 +258,6 @@ rec { name = "armeabi-v7a"; gcc = { arch = "armv7-a"; - float = "hard"; float-abi = "softfp"; fpu = "vfpv3-d16"; }; diff --git a/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix b/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix index fbd4fdf3d6bd..b62dc2def7f1 100644 --- a/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix +++ b/pkgs/development/androidndk-pkgs/androidndk-pkgs.nix @@ -99,7 +99,6 @@ rec { (lib.optional (p ? cpu) "-mcpu=${p.cpu}") (lib.optional (p ? abi) "-mabi=${p.abi}") (lib.optional (p ? fpu) "-mfpu=${p.fpu}") - (lib.optional (p ? float) "-mfloat=${p.float}") (lib.optional (p ? float-abi) "-mfloat-abi=${p.float-abi}") (lib.optional (p ? mode) "-mmode=${p.mode}") ]; From 2529c0ccda944e0cf06499ec4823430a206d42d4 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Mon, 11 Feb 2019 19:32:11 -0500 Subject: [PATCH 6/6] =?UTF-8?q?llvm:=20don=E2=80=99t=20use=20targetPlatfor?= =?UTF-8?q?m?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LLVM should be target independent because it will work with all machine types. This is different from GCC where it needs to know what target to build ahead of time. --- pkgs/development/compilers/llvm/3.8/llvm.nix | 4 ++-- pkgs/development/compilers/llvm/3.9/llvm.nix | 4 ++-- pkgs/development/compilers/llvm/4/llvm.nix | 4 ++-- pkgs/development/compilers/llvm/6/llvm.nix | 2 +- pkgs/development/compilers/llvm/7/llvm.nix | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkgs/development/compilers/llvm/3.8/llvm.nix b/pkgs/development/compilers/llvm/3.8/llvm.nix index ca6723172d7a..261a1d0f94ca 100644 --- a/pkgs/development/compilers/llvm/3.8/llvm.nix +++ b/pkgs/development/compilers/llvm/3.8/llvm.nix @@ -79,8 +79,8 @@ in stdenv.mkDerivation rec { "-DLLVM_ENABLE_RTTI=ON" "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.targetPlatform.config}" - "-DTARGET_TRIPLE=${stdenv.targetPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DTARGET_TRIPLE=${stdenv.hostPlatform.config}" ] ++ stdenv.lib.optional enableSharedLibraries [ "-DLLVM_LINK_LLVM_DYLIB=ON" ] ++ stdenv.lib.optional (!isDarwin) diff --git a/pkgs/development/compilers/llvm/3.9/llvm.nix b/pkgs/development/compilers/llvm/3.9/llvm.nix index 678ec759425d..6c935fd88de5 100644 --- a/pkgs/development/compilers/llvm/3.9/llvm.nix +++ b/pkgs/development/compilers/llvm/3.9/llvm.nix @@ -120,8 +120,8 @@ in stdenv.mkDerivation rec { "-DCOMPILER_RT_INCLUDE_TESTS=OFF" # FIXME: requires clang source code "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.targetPlatform.config}" - "-DTARGET_TRIPLE=${stdenv.targetPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DTARGET_TRIPLE=${stdenv.hostPlatform.config}" ] ++ stdenv.lib.optional enableSharedLibraries [ "-DLLVM_LINK_LLVM_DYLIB=ON" ] ++ stdenv.lib.optional (!isDarwin) diff --git a/pkgs/development/compilers/llvm/4/llvm.nix b/pkgs/development/compilers/llvm/4/llvm.nix index aac9c4275ad4..5cd7901fe22c 100644 --- a/pkgs/development/compilers/llvm/4/llvm.nix +++ b/pkgs/development/compilers/llvm/4/llvm.nix @@ -100,8 +100,8 @@ in stdenv.mkDerivation (rec { "-DCOMPILER_RT_INCLUDE_TESTS=OFF" # FIXME: requires clang source code "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.targetPlatform.config}" - "-DTARGET_TRIPLE=${stdenv.targetPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DTARGET_TRIPLE=${stdenv.hostPlatform.config}" ] ++ stdenv.lib.optional enableSharedLibraries "-DLLVM_LINK_LLVM_DYLIB=ON" diff --git a/pkgs/development/compilers/llvm/6/llvm.nix b/pkgs/development/compilers/llvm/6/llvm.nix index f16f3f721379..16a716d32fa6 100644 --- a/pkgs/development/compilers/llvm/6/llvm.nix +++ b/pkgs/development/compilers/llvm/6/llvm.nix @@ -94,7 +94,7 @@ in stdenv.mkDerivation (rec { "-DLLVM_ENABLE_FFI=ON" "-DLLVM_ENABLE_RTTI=ON" "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.targetPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly" "-DLLVM_ENABLE_DUMP=ON" ] ++ optionals enableSharedLibraries [ diff --git a/pkgs/development/compilers/llvm/7/llvm.nix b/pkgs/development/compilers/llvm/7/llvm.nix index fa5c48ec3eae..34f8a5478d1b 100644 --- a/pkgs/development/compilers/llvm/7/llvm.nix +++ b/pkgs/development/compilers/llvm/7/llvm.nix @@ -106,7 +106,7 @@ in stdenv.mkDerivation (rec { "-DLLVM_ENABLE_FFI=ON" "-DLLVM_ENABLE_RTTI=ON" "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.targetPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly" "-DLLVM_ENABLE_DUMP=ON" ] ++ optionals enableSharedLibraries [