Skip to content

Commit

Permalink
Update to go 1.16 for mobile builds (#121)
Browse files Browse the repository at this point in the history
* modified build script to work with updated fork of go-mobile

* changed spacing and added trace for easier debugging

* fixed issue with user input overwritten

* removed mentions of make

* use go 1.16 in builds

* disabled some linters

* updated change log

Co-authored-by: wussler <aron@wussler.it>
  • Loading branch information
marinthiercelin and wussler committed Mar 29, 2021
1 parent 7b16cf9 commit b5823b9
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 57 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/android.yml
Expand Up @@ -17,10 +17,10 @@ jobs:
with:
java-version: 1.8

- name: Set up Go 1.15
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.15.6
go-version: ^1.16
id: go

- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ios.yml
Expand Up @@ -18,10 +18,10 @@ jobs:
xcode-version: 12.2
id: xcode

- name: Set up Go 1.15
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.15.6
go-version: ^1.16
id: go

- name: Checkout
Expand Down
4 changes: 3 additions & 1 deletion .golangci.yml
Expand Up @@ -37,4 +37,6 @@ linters:
- forbidigo # Static analysis tool to forbid use of particular identifiers
- thelper # Enforce test helper formatting
- revive # Force CamelCase instead of all caps
- nilerr # Force return err when not nil
- nilerr # Force return err when not nil
- wrapcheck # Force wrapping of external error TODO: when the bug is fixed update the linter
- gomoddirectives # Prohibits the use of replace statements
7 changes: 6 additions & 1 deletion CHANGELOG.md
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed
- Updated the x/mobile fork and the build script to work with golang 1.16

## [2.1.6] 2021-03-17
### Added
- Decryption tests for attachments
Expand Down Expand Up @@ -734,4 +739,4 @@ VerifyCleartextMessageArmored(publicKey, armored string, verifyTime int64) (stri
```
## [1.0.0] - 2019-05-15
Initial release, opensourcing of the internal library `PMCrypto`, and subsequent renaming to `gopenpgp`
Initial release, opensourcing of the internal library `PMCrypto`, and subsequent renaming to `gopenpgp`
120 changes: 70 additions & 50 deletions build.sh
@@ -1,67 +1,86 @@
#!/bin/bash

USER_INPUT=$1
NB_INPUTS=$#

set -ue pipefail # End the script if any command, or intermediate command,
# returns an error code.

trap failed_build EXIT

# Colors for terminal display
red="\e[0;31m"
green="\e[0;32m"
reset="\033[0m"

# Trap in case something went wrong
failed_build() {
printf "${red}The build failed!\n${reset}"
}

install_modules()
{
printf "\e[0;32mStart installing go modules and their dependencies \033[0m\n\n"
GO111MODULE=on
go mod download
printf "\e[0;32mDone \033[0m\n\n"
printf "${green}Start installing go modules and their dependencies ${reset}\n\n"
GO111MODULE=on go mod download
printf "${green}Done ${reset}\n\n"
}

install_gomobile()
{
printf "\e[0;32mInstalling gomobile fork\033[0m\n\n"
printf "${green}Installing gomobile fork${reset}\n\n"
go build golang.org/x/mobile/cmd/gomobile
go build golang.org/x/mobile/cmd/gobind
printf "\e[0;32mDone \033[0m\n\n"
PATH=$(pwd):$PATH
printf "${green}Done ${reset}\n\n"
}

# import function, add internal package in the build
import()
remove_dir()
{
PACKAGES="${PACKAGES} $1"
DIR=$1
if [ -d "$DIR" ]; then
printf "removing old $DIR\n"
rm -rf $DIR
fi
}

build()
{
TARGET=$1
JAVA_PKG=$2
if [ $TARGET = "android" ]; then
JAVAPKG_FLAG="-javapkg=${ANDROID_JAVA_PKG}"
OUT_EXTENSION="aar"
if [ -z "$JAVA_PKG" ]; then
JAVAPKG_FLAG="-javapkg=$JAVA_PKG"
else
JAVAPKG_FLAG=""
fi
else
OUT_EXTENSION="framework"
JAVAPKG_FLAG=""
OUT_EXTENSION="framework"
fi
TARGET_DIR=${BUILD_DIR}/${TARGET}
TARGET_DIR=${OUT_DIR}/${TARGET}
TARGET_OUT_FILE=${TARGET_DIR}/${BUILD_NAME}.${OUT_EXTENSION}
mkdir -p $TARGET_DIR
printf "\e[0;32mStart Building ${TARGET} .. Location: ${TARGET_DIR} \033[0m\n\n"
gomobile bind -tags mobile -target $TARGET $JAVAPKG_FLAG -x -o ${TARGET_OUT_FILE} -ldflags="${LDFLAGS}" ${PACKAGES}
printf "${green}Start Building ${TARGET} .. Location: ${TARGET_DIR} ${reset}\n\n"
remove_dir $TARGET_OUT_FILE
./gomobile bind -tags mobile -target $TARGET $JAVAPKG_FLAG -x -ldflags="-s -w" -o ${TARGET_OUT_FILE} ${PACKAGES}
}

# import function, add internal package in the build
import()
{
PACKAGES="${PACKAGES} $1"
}

## ======== Config ===============

## ======== Config ===============
# ==== Generic parameters ======

# output directory
BUILD_DIR="./dist"

# linkage flags
LDFLAGS="'all=-s -w'"
OUT_DIR="./dist"

# name of the build output
BUILD_NAME="Gopenpgp"

# ==== Packages to include =====
PACKAGES=""
ANDROID_JAVA_PKG="com.proton.${BUILD_NAME}"

# ==== Packages to included =====
PACKAGES=""
## crypto must be the first one, and the framework name better same with the first package name
import github.com/ProtonMail/gopenpgp/v2/crypto
import github.com/ProtonMail/gopenpgp/v2/armor
Expand All @@ -76,30 +95,23 @@ import github.com/ProtonMail/gopenpgp/v2/helper
install_modules
install_gomobile
go env
echo "gomobile: $(which gomobile)"
echo "gobind: $(which gobind)"
echo "PATH=$PATH"
echo "gomobile:$(which gomobile)"

printf "Packages included : ${PACKAGES}\n"
## start building


# ================= Apple Builds ======================
if [ "$#" -ne 1 ] || [ $1 = apple ]; then
# ========== iOS and Simulator =========
if [ $NB_INPUTS -ne 1 ] || [ $USER_INPUT = apple ]; then
# we build the framework for the ios sim on arm64 macs

build ios-simulator

# we build the framework for the ios devices
build ios

# we make a copy of the framework for the simulator
IOSSIM_OUT=${BUILD_DIR}/"ios-simulator"
mkdir -p $IOSSIM_OUT
IOS_OUT_FILE=${BUILD_DIR}/ios/${BUILD_NAME}.framework
IOSSIM_OUT_FILE=${IOSSIM_OUT}/${BUILD_NAME}.framework

cp -R $IOS_OUT_FILE $IOSSIM_OUT_FILE;

# we remove the unwanted archs for ios and simulator
lipo $IOSSIM_OUT_FILE/Versions/A/${BUILD_NAME} -remove arm64 -output $IOSSIM_OUT_FILE/Versions/A/${BUILD_NAME};
lipo $IOS_OUT_FILE/Versions/A/${BUILD_NAME} -remove x86_64 -output $IOS_OUT_FILE/Versions/A/${BUILD_NAME};


# ========== macOs ====================

# we build the framework for the macos devices
Expand All @@ -113,15 +125,23 @@ build macos
build macos-ui

# we join all platform's framework in a xcframework
XCFRAMEWORK_OUT_FILE=$BUILD_DIR/$BUILD_NAME.xcframework

xcodebuild -create-xcframework -framework $BUILD_DIR/ios/$BUILD_NAME.framework -framework $BUILD_DIR/macos/$BUILD_NAME.framework -framework $BUILD_DIR/macos-ui/$BUILD_NAME.framework -framework $BUILD_DIR/ios-simulator/$BUILD_NAME.framework -output $XCFRAMEWORK_OUT_FILE
XCFRAMEWORK_OUT_FILE=$OUT_DIR/$BUILD_NAME.xcframework
remove_dir $XCFRAMEWORK_OUT_FILE;
xcodebuild -create-xcframework \
-framework $OUT_DIR/ios/$BUILD_NAME.framework \
-framework $OUT_DIR/macos/$BUILD_NAME.framework \
-framework $OUT_DIR/macos-ui/$BUILD_NAME.framework \
-framework $OUT_DIR/ios-simulator/$BUILD_NAME.framework \
-output $XCFRAMEWORK_OUT_FILE

fi
# ================ Android Build =====================
if [ "$#" -ne 1 ] || [ $1 = android ]; then
ANDROID_JAVA_PAG="com.proton.${BUILD_NAME}"
build android $ANDROID_JAVA_PAG

printf "\e[0;32mAll Done. \033[0m\n\n"

# ================ Android Build =====================
if [ $NB_INPUTS -ne 1 ] || [ $USER_INPUT = android ]; then
build android
fi

printf "${green}All Done. ${reset}\n\n"

trap - EXIT
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -10,4 +10,4 @@ require (
golang.org/x/mobile v0.0.0-20200801112145-973feb4309de
)

replace golang.org/x/mobile => github.com/ProtonMail/go-mobile v0.0.0-20201014085805-7a2d68bf792f
replace golang.org/x/mobile => github.com/ProtonMail/go-mobile v0.0.0-20210326110230-f181c70e4e2b
12 changes: 12 additions & 0 deletions go.sum
@@ -1,13 +1,18 @@
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOCMdNH+CiXJVYJh5UQNCOBG7jbELc=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ProtonMail/go-crypto v0.0.0-20210317131446-1ce7a431ff79 h1:Y6Zid4OqXGXRaaowOfYf2+kNE0BYmnqACXnix/VtXQg=
github.com/ProtonMail/go-crypto v0.0.0-20210317131446-1ce7a431ff79/go.mod h1:HTM9X7e9oLwn7RiqLG0UVwVRJenLs3wN+tQ0NPAfwMQ=
github.com/ProtonMail/go-mime v0.0.0-20190923161245-9b5a4261663a h1:W6RrgN/sTxg1msqzFFb+G80MFmpjMw61IU+slm+wln4=
github.com/ProtonMail/go-mime v0.0.0-20190923161245-9b5a4261663a/go.mod h1:NYt+V3/4rEeDuaev/zw1zCq8uqVEuPHzDPo3OZrlGJ4=
github.com/ProtonMail/go-mobile v0.0.0-20201014085805-7a2d68bf792f h1:u2i2ZBaZNzyJlIpyZWRJAoYMYqKObfJxvja3lr2olWw=
github.com/ProtonMail/go-mobile v0.0.0-20201014085805-7a2d68bf792f/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4=
github.com/ProtonMail/go-mobile v0.0.0-20210326110230-f181c70e4e2b h1:XVeh08xp93T+xK6rzpCSQTZ+LwEo+ASHvOifrQ5ZgEE=
github.com/ProtonMail/go-mobile v0.0.0-20210326110230-f181c70e4e2b/go.mod h1:Naot1YTww71UdzhpocCmKjmnb8+3Jlcww/TW6kP6/yc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
Expand All @@ -17,30 +22,37 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 h1:estk1glOnSVeJ9tdEZZc5mAMDZk5lNJNyJ6DvrBkTEU=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.1.1-0.20191209134235-331c550502dd h1:ePuNC7PZ6O5BzgPn9bZayERXBdfZjUYoXEf5BTfDfh8=
golang.org/x/mod v0.1.1-0.20191209134235-331c550502dd/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
Expand Down

0 comments on commit b5823b9

Please sign in to comment.