├── .gitignore ├── go.mod ├── .gitmodules ├── go.sum ├── templates ├── files │ ├── go.mod.template │ └── build.sh.template ├── template_funcs.go ├── gen_go_mod.go └── gen_build_script.go ├── Makefile ├── examples └── gopenpgp.json ├── utils └── utils.go ├── LICENSE ├── configloader └── config_loader.go ├── main.go └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | build/ 3 | gomobile-build-tool -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/ProtonMail/gomobile-build-tool 2 | 3 | go 1.16 4 | 5 | require github.com/hashicorp/go-version v1.2.1 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "mobile"] 2 | path = mobile 3 | url = https://github.com/ProtonMail/go-mobile 4 | branch = tmp/refresh-gomobile-2 5 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI= 2 | github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= 3 | -------------------------------------------------------------------------------- /templates/files/go.mod.template: -------------------------------------------------------------------------------- 1 | module gitlab.protontech.ch/crypto/gomobile-build-script/build 2 | 3 | go {{ formatGoVersion .Config.GoVersion}} 4 | 5 | require ( 6 | {{formatRequirements .Config.Requirements}} 7 | golang.org/x/mobile v0.0.0 8 | ) 9 | 10 | {{formatReplacements .Config.Replacements}} 11 | 12 | // We need to use a fork to build for macos and macos-ui 13 | replace golang.org/x/mobile => {{.Config.GoMobileDir}} 14 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | LINTERS_VERSION=v1.33.0 2 | LINTERS_REPO=github.com/golangci/golangci-lint/cmd/golangci-lint 3 | 4 | setup: 5 | git submodule init && git submodule update 6 | 7 | build: setup 8 | go run . $(cfg) 9 | 10 | clean: 11 | rm -rf build out 12 | 13 | install-linters: 14 | go install golang.org/x/lint/golint@latest 15 | go install $(LINTERS_REPO)@$(LINTERS_VERSION) 16 | 17 | lint: 18 | golangci-lint run ./... 19 | 20 | zip-apple: 21 | cd out && zip -r Crypto.xcframework.zip Crypto.xcframework/ 22 | 23 | zip-android: 24 | cd out && zip -r android.zip android 25 | 26 | -------------------------------------------------------------------------------- /examples/gopenpgp.json: -------------------------------------------------------------------------------- 1 | { 2 | "go_version":"1.15.6", 3 | "build_dir":"build", 4 | "out_dir":"out", 5 | "go_mobile_dir":"mobile", 6 | "go_mobile_flags": [ 7 | "-x", 8 | "-ldflags=\"-s -w\"" 9 | ], 10 | "build_name":"Gopenpgp", 11 | "java_pkg":"com.proton.Gopenpgp", 12 | "targets":["apple", "android"], 13 | "requirements": [ 14 | { 15 | "module": 16 | { 17 | "path":"github.com/ProtonMail/gopenpgp/v2", 18 | "version":"latest" 19 | }, 20 | "packages": ["crypto", "armor", "constants", "models", "subtle", "helper"] 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /templates/template_funcs.go: -------------------------------------------------------------------------------- 1 | package templates 2 | 3 | import ( 4 | "text/template" 5 | 6 | "github.com/ProtonMail/gomobile-build-tool/utils" 7 | ) 8 | 9 | var commonFuncs = template.FuncMap{ 10 | "formatGoVersion": formatGoVersion, 11 | "formatReplacements": formatReplacements, 12 | "formatRequirements": formatRequirements, 13 | "formatModules": formatModules, 14 | "formatFlags": formatFlags, 15 | "formatPackages": formatPackages, 16 | "buildApple": buildApple, 17 | "buildAndroid": buildAndroid, 18 | "go14orAbove": utils.Go14orBelow, 19 | "go16orAbove": utils.Go16orAbove, 20 | } 21 | 22 | func newTemplate(name string) *template.Template { 23 | return template.New(name).Funcs(commonFuncs) 24 | } 25 | -------------------------------------------------------------------------------- /utils/utils.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "os/exec" 5 | "strings" 6 | 7 | "github.com/hashicorp/go-version" 8 | ) 9 | 10 | func GetGoVersion() (string, error) { 11 | cmd := exec.Command("go", "version") 12 | output, err := cmd.Output() 13 | if err != nil { 14 | return "", err 15 | } 16 | versionOutput := strings.Split(string(output), " ") 17 | versionNumber := versionOutput[2][2:] 18 | 19 | return versionNumber, nil 20 | } 21 | 22 | func Go14orBelow(versionNumber string) bool { 23 | v, err := version.NewVersion(versionNumber) 24 | if err != nil { 25 | panic(err) 26 | } 27 | constraints, err := version.NewConstraint("< 1.15.0") 28 | if err != nil { 29 | panic(err) 30 | } 31 | 32 | return constraints.Check(v) 33 | } 34 | 35 | func Go16orAbove(versionNumber string) bool { 36 | v, err := version.NewVersion(versionNumber) 37 | if err != nil { 38 | panic(err) 39 | } 40 | constraints, err := version.NewConstraint(">= 1.16.0") 41 | if err != nil { 42 | panic(err) 43 | } 44 | 45 | return constraints.Check(v) 46 | } 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | (The MIT License) 3 | 4 | Copyright (c) 2021 Proton Technologies AG 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to 8 | deal in the Software without restriction, including without limitation the 9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | sell copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 | IN THE SOFTWARE. -------------------------------------------------------------------------------- /configloader/config_loader.go: -------------------------------------------------------------------------------- 1 | package configloader 2 | 3 | import ( 4 | "encoding/json" 5 | "io/ioutil" 6 | "path/filepath" 7 | ) 8 | 9 | type Config struct { 10 | BuildDir string `json:"build_dir"` 11 | OutDir string `json:"out_dir"` 12 | GoMobileDir string `json:"go_mobile_dir"` 13 | Requirements []Requirement `json:"requirements"` 14 | Replacements []Replacement `json:"replacements"` 15 | GoMobileFlags []string `json:"go_mobile_flags"` 16 | BuildName string `json:"build_name"` 17 | Targets []string `json:"targets"` 18 | JavaPkg string `json:"java_pkg"` 19 | GoVersion string `json:"go_version"` 20 | BuildTag string `json:"build_tag"` 21 | MinIOSVersion string `json:"min_ios_version"` 22 | MinMacOSVersion string `json:"min_macos_version"` 23 | } 24 | 25 | type Requirement struct { 26 | Module Module `json:"module"` 27 | Packages []string `json:"packages"` 28 | } 29 | 30 | type Module struct { 31 | Path string `json:"path"` 32 | Version string `json:"version"` 33 | } 34 | 35 | type Replacement struct { 36 | Old Module `json:"old"` 37 | New Module `json:"new"` 38 | LocalPath string `json:"local_path"` 39 | } 40 | 41 | func LoadConfig(filename string) (config *Config, err error) { 42 | byteValue, err := ioutil.ReadFile(filepath.Clean(filename)) 43 | if err != nil { 44 | return nil, err 45 | } 46 | config = &Config{ 47 | BuildDir: "build", 48 | OutDir: "out", 49 | GoMobileDir: "mobile", 50 | } 51 | err = json.Unmarshal(byteValue, config) 52 | if err != nil { 53 | return nil, err 54 | } 55 | 56 | return 57 | } 58 | -------------------------------------------------------------------------------- /templates/gen_go_mod.go: -------------------------------------------------------------------------------- 1 | package templates 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path" 7 | "strings" 8 | "text/template" 9 | 10 | config "github.com/ProtonMail/gomobile-build-tool/configloader" 11 | ) 12 | 13 | func formatGoVersion(version string) string { 14 | versionSplitted := strings.Split(version, ".") 15 | 16 | return strings.Join(versionSplitted[:2], ".") 17 | } 18 | 19 | func formatModule(module config.Module) string { 20 | return fmt.Sprintf("%s %s", module.Path, module.Version) 21 | } 22 | 23 | func formatRequirements(requirements []config.Requirement) string { 24 | requirementStrings := make([]string, len(requirements)) 25 | for i, requirement := range requirements { 26 | requirementStrings[i] = formatRequirement(requirement) 27 | } 28 | 29 | return strings.Join(requirementStrings, "\n") 30 | } 31 | 32 | func formatRequirement(requirement config.Requirement) string { 33 | return "\t" + formatModule(requirement.Module) 34 | } 35 | 36 | func formatReplacements(replacements []config.Replacement) string { 37 | replacementStrings := make([]string, len(replacements)) 38 | for i, replacement := range replacements { 39 | replacementStrings[i] = formatReplacement(replacement) 40 | } 41 | 42 | return strings.Join(replacementStrings, "\n") 43 | } 44 | 45 | func formatReplacement(replacement config.Replacement) string { 46 | if replacement.New == (config.Module{}) { 47 | return fmt.Sprintf( 48 | "replace %s => %s", 49 | formatModule(replacement.Old), 50 | replacement.LocalPath, 51 | ) 52 | } 53 | 54 | return fmt.Sprintf( 55 | "replace %s => %s", 56 | formatModule(replacement.Old), 57 | formatModule(replacement.New), 58 | ) 59 | } 60 | 61 | type GoModTemplateData struct { 62 | Config *config.Config 63 | } 64 | 65 | func GenerateGoMod(config *config.Config) (err error) { 66 | var template *template.Template = newTemplate("go.mod.template") 67 | template, err = template.ParseFiles("templates/files/go.mod.template") 68 | if err != nil { 69 | return err 70 | } 71 | filename := path.Join(config.BuildDir, "go.mod") 72 | f, err := os.Create(filename) 73 | if err != nil { 74 | return err 75 | } 76 | err = template.Execute(f, &GoModTemplateData{Config: config}) 77 | if err != nil { 78 | return err 79 | } 80 | 81 | return f.Close() 82 | } 83 | -------------------------------------------------------------------------------- /templates/gen_build_script.go: -------------------------------------------------------------------------------- 1 | package templates 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path" 7 | "strings" 8 | "text/template" 9 | 10 | config "github.com/ProtonMail/gomobile-build-tool/configloader" 11 | ) 12 | 13 | func formatFlags(flags []string) string { 14 | return strings.Join(flags, " ") 15 | } 16 | 17 | func formatModules(requirements []config.Requirement) string { 18 | moduleStrings := make([]string, len(requirements)) 19 | for i, requirement := range requirements { 20 | moduleStrings[i] = fmt.Sprintf( 21 | "%s@%s", 22 | requirement.Module.Path, 23 | requirement.Module.Version, 24 | ) 25 | } 26 | 27 | return strings.Join(moduleStrings, " ") 28 | } 29 | 30 | func formatPackages(requirements []config.Requirement) string { 31 | requirementStrings := make([]string, len(requirements)) 32 | for i, requirement := range requirements { 33 | requirementStrings[i] = formatPackage(requirement) 34 | } 35 | 36 | return strings.Join(requirementStrings, " ") 37 | } 38 | 39 | func formatPackage(requirement config.Requirement) string { 40 | if len(requirement.Packages) == 0 { 41 | return requirement.Module.Path 42 | } 43 | packages := make([]string, len(requirement.Packages)) 44 | for i, packageName := range requirement.Packages { 45 | packages[i] = fmt.Sprintf("%s/%s", 46 | requirement.Module.Path, 47 | packageName, 48 | ) 49 | } 50 | 51 | return strings.Join(packages, " ") 52 | } 53 | 54 | func contains(s []string, e string) bool { 55 | for _, a := range s { 56 | if a == e { 57 | return true 58 | } 59 | } 60 | 61 | return false 62 | } 63 | 64 | func buildApple(targets []string) bool { 65 | return len(targets) == 0 || contains(targets, "apple") 66 | } 67 | 68 | func buildAndroid(targets []string) bool { 69 | return len(targets) == 0 || contains(targets, "android") 70 | } 71 | 72 | type BuildScriptTemplateData struct { 73 | Config *config.Config 74 | GomobileDir string 75 | } 76 | 77 | func GenerateBuildScript(config *config.Config) (err error) { 78 | var template *template.Template = newTemplate("build.sh.template") 79 | template, err = template.ParseFiles("templates/files/build.sh.template") 80 | if err != nil { 81 | return err 82 | } 83 | filename := path.Join(config.BuildDir, "build.sh") 84 | f, err := os.Create(filename) 85 | if err != nil { 86 | return err 87 | } 88 | err = template.Execute(f, &BuildScriptTemplateData{Config: config}) 89 | if err != nil { 90 | return err 91 | } 92 | err = f.Close() 93 | if err != nil { 94 | return err 95 | } 96 | 97 | return nil 98 | } 99 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "os/exec" 6 | "path" 7 | "path/filepath" 8 | 9 | config "github.com/ProtonMail/gomobile-build-tool/configloader" 10 | 11 | "github.com/ProtonMail/gomobile-build-tool/templates" 12 | 13 | "github.com/ProtonMail/gomobile-build-tool/utils" 14 | ) 15 | 16 | func loadConfig() (configuration *config.Config, err error) { 17 | configFileName := "config.json" 18 | if len(os.Args) > 1 { 19 | configFileName = os.Args[1] 20 | } 21 | 22 | return config.LoadConfig(configFileName) 23 | } 24 | 25 | func generateTemplates(configuration *config.Config) (err error) { 26 | err = templates.GenerateGoMod(configuration) 27 | if err != nil { 28 | return err 29 | } 30 | 31 | return templates.GenerateBuildScript(configuration) 32 | } 33 | 34 | func createDir(path string) (err error) { 35 | exists, err := exists(path) 36 | if err != nil { 37 | return err 38 | } 39 | if !exists { 40 | return os.Mkdir(path, 0744) 41 | } 42 | 43 | return nil 44 | } 45 | 46 | func exists(path string) (bool, error) { 47 | _, err := os.Stat(path) 48 | if err == nil { 49 | return true, nil 50 | } 51 | if os.IsNotExist(err) { 52 | return false, nil 53 | } 54 | 55 | return false, err 56 | } 57 | 58 | func setDirectories(configuration *config.Config) (err error) { 59 | configuration.BuildDir, err = filepath.Abs(configuration.BuildDir) 60 | if err != nil { 61 | return err 62 | } 63 | configuration.OutDir, err = filepath.Abs(configuration.OutDir) 64 | if err != nil { 65 | return err 66 | } 67 | configuration.GoMobileDir, err = filepath.Abs(configuration.GoMobileDir) 68 | if err != nil { 69 | return err 70 | } 71 | err = createDir(configuration.BuildDir) 72 | if err != nil { 73 | return err 74 | } 75 | 76 | return createDir(configuration.OutDir) 77 | } 78 | 79 | func runScript(configuration *config.Config) (err error) { 80 | buildScript := path.Join(configuration.BuildDir, "build.sh") 81 | cmd := exec.Command("sh", buildScript) // #nosec 82 | cmd.Stdout = os.Stdout 83 | cmd.Stderr = os.Stderr 84 | 85 | return cmd.Run() 86 | } 87 | 88 | func exit(err error) { 89 | println(err.Error()) 90 | os.Exit(1) 91 | } 92 | 93 | func main() { 94 | configuration, err := loadConfig() 95 | if err != nil { 96 | exit(err) 97 | } 98 | version, err := utils.GetGoVersion() 99 | if err != nil { 100 | exit(err) 101 | } 102 | if version != configuration.GoVersion { 103 | println("Err: The output of `go version` does not match the one in your configuration") 104 | return //nolint:nlreturn 105 | } 106 | err = setDirectories(configuration) 107 | if err != nil { 108 | exit(err) 109 | } 110 | err = generateTemplates(configuration) 111 | if err != nil { 112 | exit(err) 113 | } 114 | err = runScript(configuration) 115 | if err != nil { 116 | exit(err) 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gomobile-build-tool 2 | 3 | A go program to build the go libraries needed for mobile clients. 4 | 5 | ## Prerequisites 6 | 7 | - Install golang. (the script has been tested with go 1.15 only) 8 | - Apple platforms: You need xcode (version 12 or above) installed 9 | - Android platforms: 10 | - You need android and android ndk installed. 11 | - You need `$ANDROID_HOME` to point to your installation of Android sdk 12 | - You need to set `$ANDROID_HOME/ndk-bundle` or `$ANDROID_NDK_HOME` to point 13 | to your android ndk 14 | 15 | 16 | ## Build instructions 17 | 18 | - Clone the repository 19 | - Configure the the build (see below). 20 | - Inside the cloned repository, run 21 | ``` 22 | make build cfg=/path/to/config/file 23 | ``` 24 | This should produce the artifacts inside the `out` directory, set in the 25 | configuration. 26 | 27 | You can remove previous builds with `make clean`. 28 | 29 | ## Configuration of the build 30 | 31 | You need to provide the builder program a configuration file. 32 | We provide a few example configuration files in `examples/`. 33 | 34 | - `"go_version"`: Must match the version number of your local golang installation 35 | - `"build_dir"` : the directory to contain the generated the build script, default is `"build"` 36 | - `"out_dir"` : the directory that will contain the artifacts, default is `"out"` 37 | - `"go_mobile_dir"` : the directory where the fork of gomobile was clone, default is `"mobile"` 38 | - `"go_mobile_flags"` : a list of flags given to the `gomobile bind` command, see [this](https://godoc.org/golang.org/x/mobile/cmd/gomobile#hdr-Build_a_library_for_Android_and_iOS) for a list of flags. 39 | - `"build_name"` : the name of the produced artifacts 40 | - `"build_tag"` : Used by gitlab automated builds to tag the builds 41 | - `"java_pkg"` : (for android) the name of the java package representing the go code, it defaults to the `"build_name"`. 42 | - `"min_ios_version"`: (for ios) the minimum version of iOS we want to support. (Forwarded to the `-iosversion` option of gomobile) 43 | - `"targets"`: a list of platforms (`"android"` and `"apple"`) to build artifacts for, if not provided, the program builds for both platforms. 44 | - `"requirements"` : used to specify a list of packages to include in the artifacts. 45 | - `"module"`: the go module containing the package 46 | - `"path"`: the import path of the module 47 | - `"version"`: specifies which module version to use, either a commit tag (e.g `"v2.0.1"`) or a commit hash, or `"latest"`. 48 | - `"packages"`: a list of package names from the module to include in the artifacts (without the full import path of the module). If not provided, the artifact will include the whole module. 49 | - `"replacements"`: a list of module replacements for the artifacts 50 | - `"old"`: the module to replace 51 | - `"path"`: the path of the module 52 | - `"version"`: the version of the module to replace, if not included we replace all versions 53 | 54 | - `"new"`: the module to replace with 55 | - `"path"`: the path of the module 56 | - `"version"`: the version of the module to replace with. 57 | - `"local_path"`: a local path to the replacement module (instead of a remot go module) 58 | 59 | 60 | -------------------------------------------------------------------------------- /templates/files/build.sh.template: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ue pipefail # End the script if any command, or intermediate command, 4 | # returns an error code. 5 | set -x 6 | 7 | trap failed_build EXIT 8 | 9 | # Colors for terminal display 10 | red="\e[0;31m" 11 | green="\e[0;32m" 12 | reset="\033[0m" 13 | 14 | # Trap in case something went wrong 15 | failed_build() { 16 | printf "${red}The build failed!\nRun 'make clean' before retrying...\n${reset}" 17 | } 18 | 19 | install_modules() 20 | { 21 | printf "${green}Start installing go modules and their dependencies ${reset}\n\n" 22 | GO111MODULE=on go mod download 23 | printf "${green}Done ${reset}\n\n" 24 | } 25 | 26 | install_gomobile() 27 | { 28 | printf "${green}Installing gomobile fork${reset}\n\n" 29 | {{if (go16orAbove .Config.GoVersion)}} 30 | go get golang.org/x/mobile/cmd/gomobile@v0.0.0 31 | go get golang.org/x/mobile/cmd/gobind@v0.0.0 32 | {{end}} 33 | go build {{.Config.GoMobileDir}}/cmd/gomobile 34 | go build {{.Config.GoMobileDir}}/cmd/gobind 35 | PATH=$(pwd):$PATH 36 | printf "${green}Done ${reset}\n\n" 37 | } 38 | 39 | {{if (go16orAbove .Config.GoVersion)}} 40 | get_modules(){ 41 | for MODULE in $MODULES 42 | do 43 | go get $MODULE 44 | done 45 | } 46 | {{end}} 47 | 48 | remove_dir() 49 | { 50 | DIR=$1 51 | if [ -d "$DIR" ]; then 52 | printf "removing old $DIR\n" 53 | rm -rf $DIR 54 | fi 55 | } 56 | 57 | build() 58 | { 59 | TARGET=$1 60 | OUTPUT_DIR=$2 61 | TAGS="mobile" 62 | if [ $TARGET = "android" ]; then 63 | {{if .Config.JavaPkg}} 64 | JAVAPKG_FLAG="-javapkg={{.Config.JavaPkg}}" 65 | {{else}} 66 | JAVAPKG_FLAG="" 67 | {{end}} 68 | OUT_EXTENSION="aar" 69 | IOS_VERSION_FLAG="" 70 | MACOS_VERSION_FLAG="" 71 | else 72 | JAVAPKG_FLAG="" 73 | {{if .Config.MinIOSVersion}} 74 | IOS_VERSION_FLAG="-iosversion={{.Config.MinIOSVersion}}" 75 | {{else}} 76 | IOS_VERSION_FLAG="" 77 | {{end}} 78 | {{if .Config.MinMacOSVersion}} 79 | MACOS_VERSION_FLAG="-macosversion={{.Config.MinMacOSVersion}}" 80 | {{else}} 81 | MACOS_VERSION_FLAG="" 82 | {{end}} 83 | OUT_EXTENSION="xcframework" 84 | TAGS="$TAGS,ios" 85 | fi 86 | TARGET_DIR=${OUT_DIR}/${OUTPUT_DIR} 87 | TARGET_OUT_FILE=${TARGET_DIR}/${BUILD_NAME}.${OUT_EXTENSION} 88 | mkdir -p $TARGET_DIR 89 | printf "${green}Start Building ${TARGET} .. Location: ${TARGET_DIR} ${reset}\n\n" 90 | remove_dir $TARGET_OUT_FILE 91 | ./gomobile bind -tags $TAGS -target $TARGET $JAVAPKG_FLAG $IOS_VERSION_FLAG $MACOS_VERSION_FLAG {{formatFlags .Config.GoMobileFlags}} -o ${TARGET_OUT_FILE} ${PACKAGES} 92 | } 93 | 94 | 95 | ## ======== Config =============== 96 | 97 | # ==== Generic parameters ====== 98 | 99 | # output directory 100 | OUT_DIR="{{.Config.OutDir}}" 101 | 102 | # name of the build output 103 | BUILD_NAME="{{.Config.BuildName}}" 104 | 105 | # ==== Packages to include ===== 106 | {{if (go16orAbove .Config.GoVersion)}} 107 | MODULES="{{formatModules .Config.Requirements}}" 108 | {{end}} 109 | PACKAGES="{{formatPackages .Config.Requirements}}" 110 | 111 | ######## ======== Main =========== 112 | 113 | # We get the needed go modules stated in the go.mod file 114 | cd {{.Config.BuildDir}}; 115 | 116 | install_modules 117 | install_gomobile 118 | {{if (go16orAbove .Config.GoVersion)}} 119 | get_modules 120 | {{end}} 121 | go env 122 | echo "PATH=$PATH" 123 | echo "gomobile:$(which gomobile)" 124 | 125 | printf "Packages included : ${PACKAGES}\n" 126 | ## start building 127 | 128 | {{if (buildApple .Config.Targets)}} 129 | # ================= Apple Builds ====================== 130 | # we build the framework for the ios devices and simulator 131 | build ios,iossimulator,maccatalyst,macos apple 132 | 133 | {{end}} 134 | 135 | {{if (buildAndroid .Config.Targets)}} 136 | # ================ Android Build ===================== 137 | build android android 138 | 139 | printf "${green}All Done. ${reset}\n\n" 140 | {{end}} 141 | 142 | trap - EXIT --------------------------------------------------------------------------------