nix: Fix non-deterministic gomobile path for iOS

This commit is contained in:
Pedro Pombeiro 2019-07-18 13:52:17 +02:00
parent 4d8891e35f
commit 75d0af862f
No known key found for this signature in database
GPG Key ID: C4A24185B2AA48A1
2 changed files with 17 additions and 17 deletions

View File

@ -20,19 +20,22 @@ let
buildMessage = "Building mobile library for ${targetConfig.name}";
# Build mobile libraries
buildPhase = ''
mkdir $NIX_BUILD_TOP/go-build
buildPhase =
let
NIX_GOWORKDIR = "$NIX_BUILD_TOP/go-build";
in ''
mkdir ${NIX_GOWORKDIR}
GOPATH=${gomobile.dev}:$GOPATH \
PATH=${makeBinPath [ gomobile.bin ]}:$PATH \
NIX_GOWORKDIR=${NIX_GOWORKDIR} \
${concatStringsSep " " targetConfig.envVars} \
NIX_GOWORKDIR=$NIX_BUILD_TOP/go-build \
gomobile bind ${goBuildFlags} -target=${targetConfig.name} ${concatStringsSep " " targetConfig.gomobileExtraFlags} \
-o ${targetConfig.outputFileName} \
${goBuildLdFlags} \
${goPackagePath}/mobile
rm -rf $NIX_BUILD_TOP/go-build
rm -rf ${NIX_GOWORKDIR}
'';
installPhase = ''

View File

@ -27,17 +27,17 @@ in buildGoPackage rec {
patches = [ ./ndk-search-path.patch ./resolve-nix-android-sdk.patch ]
++ optional isDarwin ./ignore-nullability-error-on-ios.patch;
postPatch =
optionalString platform.targetAndroid ''
substituteInPlace cmd/gomobile/install.go --replace "\`adb\`" "\`${platform-tools}/bin/adb\`"
'' + ''
WORK=$NIX_BUILD_TOP/gomobile-work
postPatch = ''
${optionalString platform.targetAndroid ''substituteInPlace cmd/gomobile/install.go --replace "\`adb\`" "\`${platform-tools}/bin/adb\`"''}
# Prevent a non-deterministic temporary directory from polluting the resulting object files
substituteInPlace cmd/gomobile/env.go --replace \
'tmpdir, err = ioutil.TempDir("", "gomobile-work-")' \
"tmpdir = \"$WORK\"" \
"tmpdir = \"$NIX_BUILD_TOP/gomobile-work\"" \
--replace '"io/ioutil"' ""
substituteInPlace cmd/gomobile/init.go --replace \
'tmpdir, err = ioutil.TempDir(gomobilepath, "work-")' \
"tmpdir = \"$NIX_BUILD_TOP/work\""
echo "Creating $dev"
mkdir -p $dev/src/$goPackagePath
@ -46,10 +46,7 @@ in buildGoPackage rec {
'';
preBuild = ''
mkdir $WORK
'';
postBuild = ''
rm -rf $WORK
mkdir $NIX_BUILD_TOP/gomobile-work $NIX_BUILD_TOP/work
'';
postInstall =
@ -59,14 +56,14 @@ in buildGoPackage rec {
mkdir -p $out $bin/lib
ln -s ${ncurses5}/lib/libncursesw.so.5 $bin/lib/libtinfo.so.5
'' + (if isDarwin then ''
${if isDarwin then ''
wrapProgram $bin/bin/gomobile \
--prefix "PATH" : "${makeBinPath [ xcodeWrapper ]}" \
--prefix "LD_LIBRARY_PATH" : "${makeLibraryPath [ ncurses5 zlib ]}:$bin/lib"
'' else ''
wrapProgram $bin/bin/gomobile \
--prefix "LD_LIBRARY_PATH" : "${makeLibraryPath [ ncurses5 zlib ]}:$bin/lib"
'') + ''
''}
$bin/bin/gomobile init
'';