Update to go 1.16 for mobile builds (#121)
* 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>
This commit is contained in:
parent
7b16cf94c8
commit
b5823b9dee
7 changed files with 105 additions and 66 deletions
138
build.sh
138
build.sh
|
|
@ -1,20 +1,64 @@
|
|||
#!/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"
|
||||
}
|
||||
|
||||
remove_dir()
|
||||
{
|
||||
DIR=$1
|
||||
if [ -d "$DIR" ]; then
|
||||
printf "removing old $DIR\n"
|
||||
rm -rf $DIR
|
||||
fi
|
||||
}
|
||||
|
||||
build()
|
||||
{
|
||||
TARGET=$1
|
||||
if [ $TARGET = "android" ]; then
|
||||
JAVAPKG_FLAG="-javapkg=${ANDROID_JAVA_PKG}"
|
||||
OUT_EXTENSION="aar"
|
||||
else
|
||||
JAVAPKG_FLAG=""
|
||||
OUT_EXTENSION="framework"
|
||||
fi
|
||||
TARGET_DIR=${OUT_DIR}/${TARGET}
|
||||
TARGET_OUT_FILE=${TARGET_DIR}/${BUILD_NAME}.${OUT_EXTENSION}
|
||||
mkdir -p $TARGET_DIR
|
||||
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
|
||||
|
|
@ -23,45 +67,20 @@ import()
|
|||
PACKAGES="${PACKAGES} $1"
|
||||
}
|
||||
|
||||
build()
|
||||
{
|
||||
TARGET=$1
|
||||
JAVA_PKG=$2
|
||||
if [ $TARGET = "android" ]; then
|
||||
OUT_EXTENSION="aar"
|
||||
if [ -z "$JAVA_PKG" ]; then
|
||||
JAVAPKG_FLAG="-javapkg=$JAVA_PKG"
|
||||
else
|
||||
JAVAPKG_FLAG=""
|
||||
fi
|
||||
else
|
||||
OUT_EXTENSION="framework"
|
||||
JAVAPKG_FLAG=""
|
||||
fi
|
||||
TARGET_DIR=${BUILD_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}
|
||||
}
|
||||
|
||||
|
||||
## ======== 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
|
||||
|
|
@ -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
|
||||
|
|
@ -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"
|
||||
if [ $NB_INPUTS -ne 1 ] || [ $USER_INPUT = android ]; then
|
||||
build android
|
||||
fi
|
||||
|
||||
printf "${green}All Done. ${reset}\n\n"
|
||||
|
||||
trap - EXIT
|
||||
Loading…
Add table
Add a link
Reference in a new issue