Use ProtonMail's GopenPGP library

This allows for a simpler setup and the usage of a recent version of Go. The library provides a build script which creates an XCFramework containing binaries for multiple target architectures. The gnu-dummy.patch is taken from mssun/gopenpgp. The forks are not needed anymore.
This commit is contained in:
Danny Moesch 2021-06-20 00:33:48 +02:00
parent 867931ab89
commit 93954f3bec
6 changed files with 158 additions and 49 deletions

View file

@ -2,27 +2,29 @@
set -euox pipefail
GOPENPGP_VERSION="v2.1.10"
export GOPATH="$(pwd)/go"
export PATH="$PATH:$GOPATH/bin"
PACKAGE_PATH="github.com/mssun/gopenpgp"
GOPENPGP_REVISION="gnu-dummy"
OUTPUT_PATH="$GOPATH/dist"
mkdir -p "$GOPATH"
go get golang.org/x/mobile/cmd/gomobile || true
( cd "$GOPATH/src/golang.org/x/mobile/cmd/gomobile" && git checkout 0df4eb2385467a487d418c6358313e9e838256ae )
GO111MODULE=on go get golang.org/x/mobile/cmd/gomobile@0df4eb2385467a487d418c6358313e9e838256ae || true
GO111MODULE=on go get golang.org/x/mobile/cmd/gobind@0df4eb2385467a487d418c6358313e9e838256ae || true
go get -u "$PACKAGE_PATH" || true
mkdir -p "$GOPATH/src/github.com/ProtonMail"
ln -f -s "$GOPATH/src/$PACKAGE_PATH" "$GOPATH/src/github.com/ProtonMail/gopenpgp"
( cd "$GOPATH/src/$PACKAGE_PATH" && git checkout "$GOPENPGP_REVISION" && GO111MODULE=on go mod vendor )
OUTPUT_PATH="go/dist"
CHECKOUT_PATH="go/checkout"
GOPENPGP_PATH="$CHECKOUT_PATH/gopenpgp"
mkdir -p "$OUTPUT_PATH"
mkdir -p "$CHECKOUT_PATH"
go env -w GO111MODULE=auto
go get golang.org/x/mobile/cmd/gomobile
gomobile init
git clone --depth 1 --branch "$GOPENPGP_VERSION" git@github.com:ProtonMail/gopenpgp.git "$GOPENPGP_PATH"
git apply patch/gnu-dummy.patch --directory "$GOPENPGP_PATH"
sed -i '' 's/build android/echo "Skipping Android build."/g' "$GOPENPGP_PATH/build.sh"
(cd "$GOPENPGP_PATH" && ./build.sh)
cp -R "$GOPENPGP_PATH/dist/Gopenpgp.xcframework" "$OUTPUT_PATH"
"$GOPATH/bin/gomobile" bind -v -ldflags="-s -w" -target ios -o "${OUTPUT_PATH}/Crypto.framework" \
"$PACKAGE_PATH"/{crypto,armor,constants,models,subtle}