Skip to content

Commit

Permalink
[backport 24.05] treewide: Rename android sdkVer and ndkVer (#336577)
Browse files Browse the repository at this point in the history
  • Loading branch information
Artturin authored Aug 26, 2024
2 parents 0239aeb + 799b445 commit 592e7c3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
16 changes: 16 additions & 0 deletions lib/systems/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,22 @@ let
if final.isMacOS then "MACOSX_DEPLOYMENT_TARGET"
else if final.isiOS then "IPHONEOS_DEPLOYMENT_TARGET"
else null;

# Remove before 25.05
androidSdkVersion =
if (args ? sdkVer && !args ? androidSdkVersion) then
throw "For android `sdkVer` has been renamed to `androidSdkVersion`"
else if (args ? androidSdkVersion) then
args.androidSdkVersion
else
null;
androidNdkVersion =
if (args ? ndkVer && !args ? androidNdkVersion) then
throw "For android `ndkVer` has been renamed to `androidNdkVersion`"
else if (args ? androidSdkVersion) then
args.androidNdkVersion
else
null;
} // (
let
selectEmulator = pkgs:
Expand Down
12 changes: 6 additions & 6 deletions lib/systems/examples.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ rec {
armv7a-android-prebuilt = {
config = "armv7a-unknown-linux-androideabi";
rustc.config = "armv7-linux-androideabi";
sdkVer = "28";
ndkVer = "24";
androidSdkVersion = "28";
androidNdkVersion = "24";
useAndroidPrebuilt = true;
} // platforms.armv7a-android;

aarch64-android-prebuilt = {
config = "aarch64-unknown-linux-android";
rustc.config = "aarch64-linux-android";
sdkVer = "28";
ndkVer = "24";
androidSdkVersion = "28";
androidNdkVersion = "24";
useAndroidPrebuilt = true;
};

aarch64-android = {
config = "aarch64-unknown-linux-android";
sdkVer = "30";
ndkVer = "24";
androidSdkVersion = "30";
androidNdkVersion = "24";
libc = "bionic";
useAndroidPrebuilt = false;
useLLVM = true;
Expand Down
16 changes: 8 additions & 8 deletions pkgs/development/androidndk-pkgs/androidndk-pkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let
buildInfo = ndkBuildInfoFun stdenv.buildPlatform;
targetInfo = ndkTargetInfoFun stdenv.targetPlatform;

inherit (stdenv.targetPlatform) sdkVer;
androidSdkVersion = if (stdenv.targetPlatform ? androidSdkVersion && stdenv.targetPlatform.androidSdkVersion != null) then stdenv.targetPlatform.androidSdkVersion else (throw "`androidSdkVersion` is not set during the importing of nixpkgs");
suffixSalt = lib.replaceStrings ["-" "."] ["_" "_"] stdenv.targetPlatform.config;

# targetInfo.triple is what Google thinks the toolchain should be, this is a little
Expand Down Expand Up @@ -76,17 +76,17 @@ rec {
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}";
if [ ! -d $out/toolchain/sysroot/usr/lib/${targetInfo.triple}/${androidSdkVersion} ]; then
echo "NDK does not contain libraries for SDK version ${androidSdkVersion}";
exit 1
fi
ln -vfs $out/toolchain/sysroot/usr/lib $out/lib
ln -s $out/toolchain/sysroot/usr/lib/${targetInfo.triple}/*.so $out/lib/
ln -s $out/toolchain/sysroot/usr/lib/${targetInfo.triple}/*.a $out/lib/
chmod +w $out/lib/*
ln -s $out/toolchain/sysroot/usr/lib/${targetInfo.triple}/${sdkVer}/*.so $out/lib/
ln -s $out/toolchain/sysroot/usr/lib/${targetInfo.triple}/${sdkVer}/*.o $out/lib/
ln -s $out/toolchain/sysroot/usr/lib/${targetInfo.triple}/${androidSdkVersion}/*.so $out/lib/
ln -s $out/toolchain/sysroot/usr/lib/${targetInfo.triple}/${androidSdkVersion}/*.o $out/lib/
echo "INPUT(-lc++_static)" > $out/lib/libc++.a
Expand Down Expand Up @@ -129,7 +129,7 @@ rec {
bintools = binutils;
libc = targetAndroidndkPkgs.libraries;
extraBuildCommands = ''
echo "-D__ANDROID_API__=${stdenv.targetPlatform.sdkVer}" >> $out/nix-support/cc-cflags
echo "-D__ANDROID_API__=${stdenv.targetPlatform.androidSdkVersion}" >> $out/nix-support/cc-cflags
# 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
Expand All @@ -150,9 +150,9 @@ rec {
# cross-compiling packages to wrap incorrectly wrap binaries we don't include
# anyways.
libraries = runCommand "bionic-prebuilt" {} ''
lpath=${buildAndroidndk}/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/${buildInfo.double}/sysroot/usr/lib/${targetInfo.triple}/${sdkVer}
lpath=${buildAndroidndk}/libexec/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/${buildInfo.double}/sysroot/usr/lib/${targetInfo.triple}/${androidSdkVersion}
if [ ! -d $lpath ]; then
echo "NDK does not contain libraries for SDK version ${sdkVer} <$lpath>"
echo "NDK does not contain libraries for SDK version ${androidSdkVersion} <$lpath>"
exit 1
fi
mkdir -p $out/lib
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/cross/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,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}".clang
then buildPackages."androidndkPkgs_${crossSystem.androidNdkVersion}".clang
else if targetPlatform.isGhcjs
# Need to use `throw` so tryEval for splicing works, ugh. Using
# `null` or skipping the attribute would cause an eval failure
Expand Down
2 changes: 1 addition & 1 deletion pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20105,7 +20105,7 @@ with pkgs;

# TODO(@Ericson2314): Build bionic libc from source
bionic = if stdenv.hostPlatform.useAndroidPrebuilt
then pkgs."androidndkPkgs_${stdenv.hostPlatform.ndkVer}".libraries
then pkgs."androidndkPkgs_${stdenv.hostPlatform.androidNdkVer}".libraries
else callPackage ../os-specific/linux/bionic-prebuilt { };

boolstuff = callPackage ../development/libraries/boolstuff { };
Expand Down

0 comments on commit 592e7c3

Please sign in to comment.