{"id":22801692,"url":"https://github.com/pojntfx/bagop","last_synced_at":"2025-04-19T18:37:24.476Z","repository":{"id":64305409,"uuid":"389755444","full_name":"pojntfx/bagop","owner":"pojntfx","description":"Build for all Go-supported platforms by default, disable those which you don't want.","archived":false,"fork":false,"pushed_at":"2024-07-30T22:42:51.000Z","size":58,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-29T11:41:42.332Z","etag":null,"topics":["cross-compilation","goarch","golang","goos"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pojntfx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-26T20:07:22.000Z","updated_at":"2024-10-22T15:57:59.000Z","dependencies_parsed_at":"2024-06-20T04:25:43.683Z","dependency_job_id":"247f06cf-4872-4903-bdfe-4a93c1fc3ee1","html_url":"https://github.com/pojntfx/bagop","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pojntfx%2Fbagop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pojntfx%2Fbagop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pojntfx%2Fbagop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pojntfx%2Fbagop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pojntfx","download_url":"https://codeload.github.com/pojntfx/bagop/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249766071,"owners_count":21322533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cross-compilation","goarch","golang","goos"],"created_at":"2024-12-12T08:12:27.121Z","updated_at":"2025-04-19T18:37:24.457Z","avatar_url":"https://github.com/pojntfx.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bagop\n\nBuild for all Go-supported platforms by default, disable those which you don't want.\n\n[![hydrun CI](https://github.com/pojntfx/bagop/actions/workflows/hydrun.yaml/badge.svg)](https://github.com/pojntfx/bagop/actions/workflows/hydrun.yaml)\n[![Matrix](https://img.shields.io/matrix/bagop:matrix.org)](https://matrix.to/#/#bagop:matrix.org?via=matrix.org)\n\n## Overview\n\nbagop is a simple build tool for Go which tries to build your app for all platforms supported by Go by default. Instead of manually adding specific `GOOS`es and `GOARCH`es, bagop builds for all valid targets by default, and gives you the choice to disable those which you don't want to support or which can't be supported.\n\n## Installation\n\nStatic binaries are also available on [GitHub releases](https://github.com/pojntfx/bagop/releases).\n\nOn Linux, you can install them like so:\n\n```shell\n$ curl -L -o /tmp/bagop \"https://github.com/pojntfx/bagop/releases/latest/download/bagop.linux-$(uname -m)\"\n$ sudo install /tmp/bagop /usr/local/bin\n```\n\nOn macOS, you can use the following:\n\n```shell\n$ curl -L -o /tmp/bagop \"https://github.com/pojntfx/bagop/releases/latest/download/bagop.darwin-$(uname -m)\"\n$ sudo install /tmp/bagop /usr/local/bin\n```\n\nOn Windows, the following should work (using PowerShell as administrator):\n\n```shell\nPS\u003e Invoke-WebRequest https://github.com/pojntfx/bagop/releases/latest/download/bagop.windows-x86_64.exe -OutFile \\Windows\\System32\\bagop.exe\n```\n\nYou can find binaries for more operating systems and architectures on [GitHub releases](https://github.com/pojntfx/bagop/releases).\n\n## Tutorial\n\nLet's assume we have a Go app called `hello-world` and we want to build it for as many platforms as possible using bagop. This is the `main.go`:\n\n```go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello, world!\")\n}\n```\n\nWe could now start to manually (cross-)compile by running `go build -o hello-world main.go` and setting `GOOS` or `GOARCH`, or use simplified process with bagop. To build `hello-world` for all Go-supported platforms, simply run:\n\n```shell\n$ bagop -b hello-world main.go\n2021/07/28 14:34:40 building aix/ppc64 (out/hello-world.aix-ppc64)\n2021/07/28 14:34:40 building android/386 (out/hello-world.android-i686)\n2021/07/28 14:34:41 building android/amd64 (out/hello-world.android-x86_64)\n2021/07/28 14:34:41 building android/arm (out/hello-world.android-armv7l)\n2021/07/28 14:34:41 could not build for platform android/arm: err=exit status 2, stdout=, stderr=# command-line-arguments\nloadinternal: cannot find runtime/cgo\n/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1\ngcc: error: unrecognized command line option ‘-marm’; did you mean ‘-mabm’?\n```\n\nAs you can see, we get an error for Android (Android and iOS require additional support). We decide we don't want to support Android (and iOS), so let's re-run the command with these platforms disabled:\n\n```shell\n$ bagop -b hello-world -x '(android/*|ios/*|openbsd/mips64)' main.go\n2021/07/28 14:36:50 building aix/ppc64 (out/hello-world.aix-ppc64)\n2021/07/28 14:36:51 skipping android/386 (platform matched the provided regex)\n2021/07/28 14:36:51 skipping android/amd64 (platform matched the provided regex)\n2021/07/28 14:36:51 skipping android/arm (platform matched the provided regex)\n2021/07/28 14:36:51 skipping android/arm64 (platform matched the provided regex)\n2021/07/28 14:36:51 building darwin/amd64 (out/hello-world.darwin-x86_64)\n2021/07/28 14:36:51 building darwin/arm64 (out/hello-world.darwin-aarch64)\n2021/07/28 14:36:51 building dragonfly/amd64 (out/hello-world.dragonfly-x86_64)\n2021/07/28 14:36:51 building freebsd/386 (out/hello-world.freebsd-i686)\n2021/07/28 14:36:51 building freebsd/amd64 (out/hello-world.freebsd-x86_64)\n2021/07/28 14:36:51 building freebsd/arm (out/hello-world.freebsd-armv7l)\n2021/07/28 14:36:52 building freebsd/arm64 (out/hello-world.freebsd-aarch64)\n2021/07/28 14:36:52 building illumos/amd64 (out/hello-world.illumos-x86_64)\n2021/07/28 14:36:52 skipping ios/amd64 (platform matched the provided regex)\n2021/07/28 14:36:52 skipping ios/arm64 (platform matched the provided regex)\n2021/07/28 14:36:52 building js/wasm (out/hello-world.js-wasm.wasm)\n2021/07/28 14:36:52 building linux/386 (out/hello-world.linux-i686)\n2021/07/28 14:36:52 building linux/amd64 (out/hello-world.linux-x86_64)\n2021/07/28 14:36:52 building linux/arm (out/hello-world.linux-armv7l)\n2021/07/28 14:36:53 building linux/arm64 (out/hello-world.linux-aarch64)\n# ...\n2021/07/28 14:36:55 building openbsd/arm64 (out/hello-world.openbsd-aarch64)\n2021/07/28 14:36:56 skipping openbsd/mips64 (platform matched the provided regex)\n2021/07/28 14:36:56 building plan9/386 (out/hello-world.plan9-i686)\n2021/07/28 14:36:56 building plan9/amd64 (out/hello-world.plan9-x86_64)\n2021/07/28 14:36:56 building plan9/arm (out/hello-world.plan9-armv7l)\n2021/07/28 14:36:56 building solaris/amd64 (out/hello-world.solaris-x86_64)\n2021/07/28 14:36:56 building windows/386 (out/hello-world.windows-i686.exe)\n2021/07/28 14:36:56 building windows/amd64 (out/hello-world.windows-x86_64.exe)\n2021/07/28 14:36:56 building windows/arm (out/hello-world.windows-armv7l.exe)\n```\n\nIf we now check the `out` directory, we can see that we now have successfully built binaries for all supported platforms:\n\n```shell\n$ file out/*\nout/hello-world.aix-ppc64:          64-bit XCOFF executable or object module\nout/hello-world.darwin-aarch64:     Mach-O 64-bit arm64 executable, flags:\u003c|DYLDLINK|PIE\u003e\nout/hello-world.darwin-x86_64:      Mach-O 64-bit x86_64 executable\nout/hello-world.freebsd-x86_64:     ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), statically linked, Go BuildID=fV2BDKuHDCvCOj7-m7vv/W9RphXmMqdRiU2gaOpqn/3IGIUAncn0Ru4SxodzxW/c9mup3kmDEeCEdArhSBs, not stripped\nout/hello-world.illumos-x86_64:     ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/amd64/ld.so.1, Go BuildID=Kw7ILaj6FXiE9AjDNTsP/iQzcICQFRvgwBPBBHmyx/X-HuChFgFJmkDLQE17-7/bBmY7Qsz1mOL63EZfHxx, not stripped\nout/hello-world.linux-mips64:       ELF 64-bit MSB executable, MIPS, MIPS-III version 1 (SYSV), statically linked, Go BuildID=a89_1vHuZqx8j8tbx6rv/h6exUcnTnEzLeg5zwG2j/8JEsGrUTMIDOL_mdzYYe/bzMrWSV38cJMDdF71rn6, not stripped\nout/hello-world.plan9-i686:         Plan 9 executable, Intel 386\nout/hello-world.plan9-x86_64:       data\n# ...\nout/hello-world.solaris-x86_64:     ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/amd64/ld.so.1, Go BuildID=GjGEjnApRUWlg95uaQOs/Z-0sBhR9hzCdM8RVekoQ/2-IjmJ6MK_M0nMTUXJhC/2cHkBOpKkPh7F6-rgmBa, not stripped\nout/hello-world.windows-armv7l.exe: PE32 executable (console) ARMv7 Thumb (stripped to external PDB), for MS Windows\nout/hello-world.windows-i686.exe:   PE32 executable (console) Intel 80386 (stripped to external PDB), for MS Windows\nout/hello-world.windows-x86_64.exe: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows\n```\n\nNow, let's add a few compiler flags to make the build binaries fully static; we can do this by using the `-p` flag and manually setting the build command. We'll also set `-j` to allow parallel builds:\n\n```shell\n$ CGO_ENABLED=0 bagop -j \"$(nproc)\" -b hello-world -x '(android/*|ios/*|openbsd/mips64)' -p \"go build -a -ldflags '-extldflags \\\"-static\\\"' -o \\$DST main.go\"\n2021/07/28 14:36:50 building aix/ppc64 (out/hello-world.aix-ppc64)\n2021/07/28 14:36:51 skipping android/386 (platform matched the provided regex)\n2021/07/28 14:36:51 skipping android/amd64 (platform matched the provided regex)\n2021/07/28 14:36:51 skipping android/arm (platform matched the provided regex)\n# ...\n```\n\nIf we now check the output again, you can see that the binaries are now fully static:\n\n```shell\n$  ldd out/hello-world.linux-x86_64\n        not a dynamic executable\n```\n\n🚀 **That's it!** We've successfully added support for a total of _38_ target platforms to this app.\n\nIf you're enjoying bagop, the following projects might also be of help to you too:\n\n- Also want to test these cross-compiled binaries? Check out [hydrun](https://github.com/pojntfx/hydrun)!\n- Need to cross-compile CGo? Check out [bagccgop](https://github.com/pojntfx/bagccgop)!\n- Want to build fully-featured desktop GUI for all these platforms without CGo? Check out [Lorca](https://github.com/zserge/lorca)!\n- Want to use SQLite without CGo? Check out [cznic/sqlite](https://gitlab.com/cznic/sqlite)!\n\n## Reference\n\n```shell\n$ bagop --help\nBuild for all Go-supported platforms by default, disable those which you don't want.\n\nExample usage: bagop -b mybin -x '(android/arm|ios/*|openbsd/mips64)' -j \"$(nproc)\" 'main.go'\nExample usage (with plain flag): bagop -b mybin -x '(android/arm|ios/*|openbsd/mips64)' -j \"$(nproc)\" -p 'go build -o $DST main.go'\n\nSee https://github.com/pojntfx/bagop for more information.\n\nUsage: bagop [OPTION...] '\u003cINPUT\u003e'\n  -b, --bin string          Prefix of resulting binary (default \"mybin\")\n  -d, --dist string         Directory build into (default \"out\")\n  -x, --exclude string      Regex of platforms not to build for, i.e. (windows/386|linux/mips64)\n  -e, --extra-args string   Extra arguments to pass to the Go compiler\n  -g, --goisms              Use Go's conventions (i.e. amd64) instead of uname's conventions (i.e. x86_64)\n  -j, --jobs int            Maximum amount of parallel jobs (default 1)\n  -p, --plain               Sets GOARCH, GOARCH and DST and leaves the rest up to you (see example usage)\n  -v, --verbose             Enable logging of executed commands\n```\n\n## Contributing\n\nTo contribute, please use the [GitHub flow](https://guides.github.com/introduction/flow/) and follow our [Code of Conduct](./CODE_OF_CONDUCT.md).\n\nTo build bagop locally, run:\n\n```shell\n$ git clone https://github.com/pojntfx/bagop.git\n$ cd bagop\n$ go run ./cmd/bagop/main.go --help\n```\n\nHave any questions or need help? Chat with us [on Matrix](https://matrix.to/#/#bagop:matrix.org?via=matrix.org)!\n\n## License\n\nbagop (c) 2024 Felicitas Pojtinger and contributors\n\nSPDX-License-Identifier: AGPL-3.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpojntfx%2Fbagop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpojntfx%2Fbagop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpojntfx%2Fbagop/lists"}