Skip to content

Commit

Permalink
fix for intel & rosetta macs to build android
Browse files Browse the repository at this point in the history
- Get rid of `optionalString` and use isDarwin conditional for deciding when to run `patchPhase` and `installPhase`
  • Loading branch information
siddarthkay committed Jun 8, 2023
1 parent 68d8749 commit 5c951b8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions nix/pkgs/aapt2/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{ lib, stdenv, pkgs, fetchurl }:

let
inherit (lib) getAttr optionalString;
inherit (lib) getAttr;
inherit (stdenv) isLinux isDarwin;

pname = "aapt2";
Expand Down Expand Up @@ -50,8 +50,8 @@ in stdenv.mkDerivation {
inherit pname version;

srcs = with urls; [ jar sha pom ];
# patchPhase and installPhase are not neede on osx platform
phases = ["unpackPhase" "patchPhase" "installPhase"];
# patchelf is Linux specific and won't work on Darwin Platform
phases = if isDarwin then ["unpackPhase"] else ["unpackPhase" "patchPhase" "installPhase"];
buildInputs = with pkgs; [ zip unzip patchelf ];

unpackPhase = ''
Expand All @@ -66,13 +66,13 @@ in stdenv.mkDerivation {

# On Linux, we need to patch the interpreter in Java packages
# that contain native executables to use Nix's interpreter instead.
patchPhase = optionalString isLinux ''
patchPhase = ''
# Patch executables from maven dependency to use Nix's interpreter
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $tmpDir/aapt2
'';

# Rebuild the .jar file with patched binaries
installPhase = optionalString isLinux ''
installPhase = ''
pushd $tmpDir > /dev/null
chmod u+w $out/${filenames.jar}
zip -fr $out/${filenames.jar}
Expand Down

0 comments on commit 5c951b8

Please sign in to comment.