2020-01-06 04:21:44 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2021-03-29 16:29:34 +02:00
|
|
|
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() {
|
2023-03-03 15:27:37 +01:00
|
|
|
printf "${red}The build failed!\nRun 'make clean' before retrying...\n${reset}"
|
2021-03-29 16:29:34 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
install_modules()
|
|
|
|
|
{
|
2021-03-29 16:29:34 +02:00
|
|
|
printf "${green}Start installing go modules and their dependencies ${reset}\n\n"
|
|
|
|
|
GO111MODULE=on go mod download
|
|
|
|
|
printf "${green}Done ${reset}\n\n"
|
2020-10-19 10:07:25 +02:00
|
|
|
}
|
2020-01-06 04:21:44 -08:00
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
install_gomobile()
|
2020-01-06 04:21:44 -08:00
|
|
|
{
|
2021-03-29 16:29:34 +02:00
|
|
|
printf "${green}Installing gomobile fork${reset}\n\n"
|
2023-03-03 15:27:37 +01:00
|
|
|
|
|
|
|
|
go get golang.org/x/mobile/cmd/gomobile@latest
|
|
|
|
|
go get golang.org/x/mobile/cmd/gobind@latest
|
|
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
go build golang.org/x/mobile/cmd/gomobile
|
|
|
|
|
go build golang.org/x/mobile/cmd/gobind
|
|
|
|
|
PATH=$(pwd):$PATH
|
2021-03-29 16:29:34 +02:00
|
|
|
printf "${green}Done ${reset}\n\n"
|
2020-01-06 04:21:44 -08:00
|
|
|
}
|
|
|
|
|
|
2023-03-03 15:27:37 +01:00
|
|
|
|
|
|
|
|
get_modules(){
|
|
|
|
|
printf "${green}Start installing go modules and their dependencies ${reset}\n\n"
|
|
|
|
|
GO111MODULE=on go mod download
|
|
|
|
|
printf "${green}Done ${reset}\n\n"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-03-29 16:29:34 +02:00
|
|
|
remove_dir()
|
2020-01-06 04:21:44 -08:00
|
|
|
{
|
2021-03-29 16:29:34 +02:00
|
|
|
DIR=$1
|
|
|
|
|
if [ -d "$DIR" ]; then
|
|
|
|
|
printf "removing old $DIR\n"
|
|
|
|
|
rm -rf $DIR
|
|
|
|
|
fi
|
2020-01-06 04:21:44 -08:00
|
|
|
}
|
|
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
build()
|
2020-01-06 04:21:44 -08:00
|
|
|
{
|
2020-10-19 10:07:25 +02:00
|
|
|
TARGET=$1
|
2023-03-03 15:27:37 +01:00
|
|
|
OUTPUT_DIR=$2
|
|
|
|
|
TAGS="mobile"
|
2020-10-19 10:07:25 +02:00
|
|
|
if [ $TARGET = "android" ]; then
|
2023-03-03 15:27:37 +01:00
|
|
|
JAVAPKG_FLAG="-javapkg=com.proton.gopenpgp"
|
2020-10-19 10:07:25 +02:00
|
|
|
OUT_EXTENSION="aar"
|
|
|
|
|
else
|
2020-12-09 01:03:39 -08:00
|
|
|
JAVAPKG_FLAG=""
|
2023-03-03 15:27:37 +01:00
|
|
|
OUT_EXTENSION="xcframework"
|
|
|
|
|
TAGS="$TAGS,ios"
|
2020-10-19 10:07:25 +02:00
|
|
|
fi
|
2023-03-03 15:27:37 +01:00
|
|
|
TARGET_DIR=${OUT_DIR}/${OUTPUT_DIR}
|
2020-10-19 10:07:25 +02:00
|
|
|
TARGET_OUT_FILE=${TARGET_DIR}/${BUILD_NAME}.${OUT_EXTENSION}
|
|
|
|
|
mkdir -p $TARGET_DIR
|
2021-03-29 16:29:34 +02:00
|
|
|
printf "${green}Start Building ${TARGET} .. Location: ${TARGET_DIR} ${reset}\n\n"
|
|
|
|
|
remove_dir $TARGET_OUT_FILE
|
2023-03-03 15:27:37 +01:00
|
|
|
./gomobile bind -tags $TAGS -target $TARGET $JAVAPKG_FLAG -x -ldflags="-s -w " -o ${TARGET_OUT_FILE} ${PACKAGES}
|
2020-01-06 04:21:44 -08:00
|
|
|
}
|
|
|
|
|
|
2021-03-29 16:29:34 +02:00
|
|
|
# import function, add internal package in the build
|
|
|
|
|
import()
|
|
|
|
|
{
|
|
|
|
|
PACKAGES="${PACKAGES} $1"
|
|
|
|
|
}
|
2020-01-06 04:21:44 -08:00
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
|
2021-03-29 16:29:34 +02:00
|
|
|
## ======== Config ===============
|
2023-03-03 15:27:37 +01:00
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
# ==== Generic parameters ======
|
|
|
|
|
|
|
|
|
|
# output directory
|
2023-03-03 15:27:37 +01:00
|
|
|
OUT_DIR="dist"
|
2020-10-19 10:07:25 +02:00
|
|
|
|
|
|
|
|
# name of the build output
|
2023-03-03 15:27:37 +01:00
|
|
|
BUILD_NAME="gopenpgp"
|
2020-01-06 04:21:44 -08:00
|
|
|
|
2021-03-29 16:29:34 +02:00
|
|
|
# ==== Packages to included =====
|
|
|
|
|
PACKAGES=""
|
2020-10-19 10:07:25 +02:00
|
|
|
## 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
|
|
|
|
|
import github.com/ProtonMail/gopenpgp/v2/constants
|
|
|
|
|
import github.com/ProtonMail/gopenpgp/v2/models
|
|
|
|
|
import github.com/ProtonMail/gopenpgp/v2/subtle
|
|
|
|
|
import github.com/ProtonMail/gopenpgp/v2/helper
|
|
|
|
|
|
|
|
|
|
######## ======== Main ===========
|
|
|
|
|
|
|
|
|
|
install_modules
|
|
|
|
|
install_gomobile
|
2023-03-03 15:27:37 +01:00
|
|
|
|
|
|
|
|
get_modules
|
|
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
go env
|
2021-03-29 16:29:34 +02:00
|
|
|
echo "PATH=$PATH"
|
|
|
|
|
echo "gomobile:$(which gomobile)"
|
|
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
printf "Packages included : ${PACKAGES}\n"
|
2020-01-06 04:21:44 -08:00
|
|
|
## start building
|
2021-03-29 16:29:34 +02:00
|
|
|
|
|
|
|
|
|
2020-10-19 10:07:25 +02:00
|
|
|
# ================= Apple Builds ======================
|
2023-03-03 15:27:37 +01:00
|
|
|
# we build the framework for the ios devices and simulator
|
2021-03-29 16:29:34 +02:00
|
|
|
if [ $NB_INPUTS -ne 1 ] || [ $USER_INPUT = apple ]; then
|
2023-03-03 15:27:37 +01:00
|
|
|
build ios,iossimulator,macos apple
|
2020-10-19 10:07:25 +02:00
|
|
|
fi
|
|
|
|
|
|
2021-03-29 16:29:34 +02:00
|
|
|
# ================ Android Build =====================
|
|
|
|
|
if [ $NB_INPUTS -ne 1 ] || [ $USER_INPUT = android ]; then
|
2023-03-03 15:27:37 +01:00
|
|
|
build android android
|
2020-10-19 10:07:25 +02:00
|
|
|
fi
|
2021-03-29 16:29:34 +02:00
|
|
|
|
|
|
|
|
printf "${green}All Done. ${reset}\n\n"
|
|
|
|
|
|
2023-03-03 15:27:37 +01:00
|
|
|
|
2021-03-29 16:29:34 +02:00
|
|
|
trap - EXIT
|