make.bash 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env bash
  2. set -e -u -x
  3. if [ ! -f make.bash ]; then
  4. echo "make.bash must be run from $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/Android"
  5. exit 1
  6. fi
  7. # $1, if specified, is go build tags
  8. if [ -z ${1+x} ]; then BUILD_TAGS=""; else BUILD_TAGS="$1"; fi
  9. # At this time, psiphon-tunnel-core doesn't support modules
  10. export GO111MODULE=off
  11. export GOCACHE=/tmp
  12. BUILDINFOFILE="psiphon-tunnel-core_buildinfo.txt"
  13. BUILDDATE=$(date --iso-8601=seconds)
  14. BUILDREPO="https://github.com/Psiphon-Labs/psiphon-tunnel-core.git"
  15. BUILDREV=$(git rev-parse --short HEAD)
  16. GOVERSION=$(go version | perl -ne '/go version (.*?) / && print $1')
  17. # -checklinkname=0 is a required workaround for an in-proxy dependency:
  18. # https://github.com/wlynxg/anet/tree/5501d401a269290292909e6cc75f105571f97cfa?tab=readme-ov-file#how-to-build-with-go-1230-or-later
  19. #
  20. # TODO: conditional on !PSIPHON_DISABLE_INPROXY build tag?
  21. # 16KB page size alignment for Android compatibility
  22. export CGO_LDFLAGS="${CGO_LDFLAGS:-} -Wl,-z,max-page-size=16384,-z,common-page-size=16384"
  23. LDFLAGS="\
  24. -checklinkname=0 \
  25. -s \
  26. -w \
  27. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildDate=$BUILDDATE \
  28. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRepo=$BUILDREPO \
  29. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRev=$BUILDREV \
  30. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.goVersion=$GOVERSION \
  31. -extldflags=-Wl,-z,max-page-size=16384,-z,common-page-size=16384 \
  32. "
  33. echo -e "${BUILDDATE}\n${BUILDREPO}\n${BUILDREV}\n" > $BUILDINFOFILE
  34. echo "Variables for ldflags:"
  35. echo " Build date: ${BUILDDATE}"
  36. echo " Build repo: ${BUILDREPO}"
  37. echo " Build revision: ${BUILDREV}"
  38. echo " Go version: ${GOVERSION}"
  39. echo ""
  40. gomobile bind -v -x -target=android/arm,android/arm64,android/386,android/amd64 -tags="${BUILD_TAGS}" -ldflags="$LDFLAGS" github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/psi
  41. if [ $? != 0 ]; then
  42. echo "..'gomobile bind' failed, exiting"
  43. exit $?
  44. fi
  45. mkdir -p build-tmp/psi
  46. unzip -o psi.aar -d build-tmp/psi
  47. yes | cp -f PsiphonTunnel/AndroidManifest.xml build-tmp/psi/AndroidManifest.xml
  48. mkdir -p build-tmp/psi/res/xml
  49. yes | cp -f PsiphonTunnel/ca_psiphon_psiphontunnel_backup_rules.xml build-tmp/psi/res/xml/ca_psiphon_psiphontunnel_backup_rules.xml
  50. javac -d build-tmp -bootclasspath $ANDROID_HOME/platforms/android-$ANDROID_PLATFORM_VERSION/android.jar -source 1.8 -target 1.8 -classpath build-tmp/psi/classes.jar PsiphonTunnel/PsiphonTunnel.java
  51. if [ $? != 0 ]; then
  52. echo "..'javac' compiling PsiphonTunnel failed, exiting"
  53. exit $?
  54. fi
  55. cd build-tmp
  56. jar uf psi/classes.jar ca/psiphon/*.class
  57. if [ $? != 0 ]; then
  58. echo "..'jar' failed to add classes, exiting"
  59. exit $?
  60. fi
  61. cd -
  62. cd build-tmp/psi
  63. echo -e "-keep class psi.** { *; }\n-keep class ca.psiphon.** { *; }\n" >> proguard.txt
  64. rm -f ../../ca.psiphon.aar
  65. zip -r ../../ca.psiphon.aar ./
  66. cd -
  67. rm -rf build-tmp
  68. echo "Done"