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}"; buildMessage = "Building mobile library for ${targetConfig.name}";
# Build mobile libraries # Build mobile libraries
buildPhase = '' buildPhase =
mkdir $NIX_BUILD_TOP/go-build let
NIX_GOWORKDIR = "$NIX_BUILD_TOP/go-build";
in ''
mkdir ${NIX_GOWORKDIR}
GOPATH=${gomobile.dev}:$GOPATH \ GOPATH=${gomobile.dev}:$GOPATH \
PATH=${makeBinPath [ gomobile.bin ]}:$PATH \ PATH=${makeBinPath [ gomobile.bin ]}:$PATH \
NIX_GOWORKDIR=${NIX_GOWORKDIR} \
${concatStringsSep " " targetConfig.envVars} \ ${concatStringsSep " " targetConfig.envVars} \
NIX_GOWORKDIR=$NIX_BUILD_TOP/go-build \
gomobile bind ${goBuildFlags} -target=${targetConfig.name} ${concatStringsSep " " targetConfig.gomobileExtraFlags} \ gomobile bind ${goBuildFlags} -target=${targetConfig.name} ${concatStringsSep " " targetConfig.gomobileExtraFlags} \
-o ${targetConfig.outputFileName} \ -o ${targetConfig.outputFileName} \
${goBuildLdFlags} \ ${goBuildLdFlags} \
${goPackagePath}/mobile ${goPackagePath}/mobile
rm -rf $NIX_BUILD_TOP/go-build rm -rf ${NIX_GOWORKDIR}
''; '';
installPhase = '' installPhase = ''

View File

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