{"id":19298634,"url":"https://github.com/ibbd-dev/xgo","last_synced_at":"2025-11-09T11:03:12.431Z","repository":{"id":117525367,"uuid":"93024938","full_name":"ibbd-dev/xgo","owner":"ibbd-dev","description":"Golang交叉编译工具","archived":false,"fork":false,"pushed_at":"2017-06-01T07:20:12.000Z","size":11,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-03T01:26:58.072Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ibbd-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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":"2017-06-01T06:41:47.000Z","updated_at":"2020-01-11T18:11:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"943ec421-fd85-4138-ac44-ebecc19ec822","html_url":"https://github.com/ibbd-dev/xgo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ibbd-dev/xgo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibbd-dev%2Fxgo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibbd-dev%2Fxgo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibbd-dev%2Fxgo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibbd-dev%2Fxgo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibbd-dev","download_url":"https://codeload.github.com/ibbd-dev/xgo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibbd-dev%2Fxgo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283496071,"owners_count":26845317,"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","status":"online","status_checked_at":"2025-11-09T02:00:05.828Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-09T23:08:35.437Z","updated_at":"2025-11-09T11:03:12.415Z","avatar_url":"https://github.com/ibbd-dev.png","language":"Go","readme":"# xgo - Go CGO cross compiler\n\nAlthough Go strives to be a cross platform language, cross compilation from one\nplatform to another is not as simple as it could be, as you need the Go sources\nbootstrapped to each platform and architecture.\n\nThe first step towards cross compiling was Dave Cheney's [golang-crosscompile](https://github.com/davecheney/golang-crosscompile)\npackage, which automatically bootstrapped the necessary sources based on your\nexisting Go installation. Although this was enough for a lot of cases, certain\ndrawbacks became apparent where the official libraries used CGO internally: any\ndependency to third party platform code is unavailable, hence those parts don't\ncross compile nicely (native DNS resolution, system certificate access, etc).\n\nA step forward in enabling cross compilation was Alan Shreve's [gonative](https://github.com/inconshreveable/gonative)\npackage, which instead of bootstrapping the different platforms based on the\nexisting Go installation, downloaded the official pre-compiled binaries from the\ngolang website and injected those into the local toolchain. Since the pre-built\nbinaries already contained the necessary platform specific code, the few missing\ndependencies were resolved, and true cross compilation could commence... of pure\nGo code.\n\nHowever, there was still one feature missing: cross compiling Go code that used\nCGO itself, which isn't trivial since you need access to OS specific headers and\nlibraries. This becomes very annoying when you need access only to some trivial\nOS specific functionality (e.g. query the CPU load), but need to configure and\nmaintain separate build environments to do it.\n\n## Enter xgo\n\nMy solution to the challenge of cross compiling Go code with embedded C/C++ snippets\n(i.e. CGO_ENABLED=1) is based on the concept of [lightweight Linux containers](http://en.wikipedia.org/wiki/LXC).\nAll the necessary Go tool-chains, C cross compilers and platform headers/libraries\nhave been assembled into a single Docker container, which can then be called as if\na single command to compile a Go package to various platforms and architectures.\n\n## Installation\n\nAlthough you could build the container manually, it is available as an automatic\ntrusted build from Docker's container registry (not insignificant in size):\n\n    docker pull karalabe/xgo-latest\n\nTo prevent having to remember a potentially complex Docker command every time,\na lightweight Go wrapper was written on top of it.\n\n    go get github.com/karalabe/xgo\n\n## Usage\n\nSimply specify the import path you want to build, and xgo will do the rest:\n\n    $ xgo github.com/project-iris/iris\n    ...\n\n    $ ls -al\n    -rwxr-xr-x  1 root  root    9995000 Nov 24 16:44 iris-android-16-arm\n    -rwxr-xr-x  1 root  root    6776500 Nov 24 16:44 iris-darwin-10.6-386\n    -rwxr-xr-x  1 root  root    8755532 Nov 24 16:44 iris-darwin-10.6-amd64\n    -rwxr-xr-x  1 root  root    7114176 Nov 24 16:45 iris-ios-5.0-arm\n    -rwxr-xr-x  1 root  root   10135248 Nov 24 16:44 iris-linux-386\n    -rwxr-xr-x  1 root  root   12598472 Nov 24 16:44 iris-linux-amd64\n    -rwxr-xr-x  1 root  root   10040464 Nov 24 16:44 iris-linux-arm\n    -rwxr-xr-x  1 root  root    7516368 Nov 24 16:44 iris-windows-4.0-386.exe\n    -rwxr-xr-x  1 root  root    9549416 Nov 24 16:44 iris-windows-4.0-amd64.exe\n\n\nIf the path is not a canonical import path, but rather a local path (starts with\na dot `.` or a dash `/`), xgo will use the local GOPATH contents for the cross\ncompilation.\n\n\n### Build flags\n\nA handful of flags can be passed to `go build`. The currently supported ones are\n\n  - `-v`: prints the names of packages as they are compiled\n  - `-x`: prints the build commands as compilation progresses\n  - `-race`: enables data race detection (supported only on amd64, rest built without)\n  - `-tags='tag list'`: list of build tags to consider satisfied during the build\n  - `-ldflags='flag list'`: arguments to pass on each go tool link invocation\n  - `-buildmode=mode`: binary type to produce by the compiler\n\n\n### Go releases\n\nAs newer versions of the language runtime, libraries and tools get released,\nthese will get incorporated into xgo too as extensions layers to the base cross\ncompilation image (only Go 1.3 and above will be supported).\n\nYou can select which Go release to work with through the `-go` command line flag\nto xgo and if the specific release was already integrated, it will automatically\nbe retrieved and installed.\n\n    $ xgo -go 1.6.1 github.com/project-iris/iris\n\nAdditionally, a few wildcard release strings are also supported:\n\n  - `latest` will use the latest Go release (this is the default)\n  - `1.6.x` will use the latest point release of a specific Go version\n  - `1.6-develop` will use the develop branch of a specific Go version\n  - `develop` will use the develop branch of the entire Go repository\n\n### Output prefixing\n\nxgo by default uses the name of the package being cross compiled as the output\nfile prefix. This can be overridden with the `-out` flag.\n\n    $ xgo -out iris-v0.3.2 github.com/project-iris/iris\n    ...\n\n    $ ls -al\n    -rwxr-xr-x  1 root  root   9995000 Nov 24 16:44 iris-v0.3.2-android-16-arm\n    -rwxr-xr-x  1 root  root   6776500 Nov 24 16:44 iris-v0.3.2-darwin-10.6-386\n    -rwxr-xr-x  1 root  root   8755532 Nov 24 16:44 iris-v0.3.2-darwin-10.6-amd64\n    -rwxr-xr-x  1 root  root   7114176 Nov 24 16:45 iris-v0.3.2-ios-5.0-arm\n    -rwxr-xr-x  1 root  root  10135248 Nov 24 16:44 iris-v0.3.2-linux-386\n    -rwxr-xr-x  1 root  root  12598472 Nov 24 16:44 iris-v0.3.2-linux-amd64\n    -rwxr-xr-x  1 root  root  10040464 Nov 24 16:44 iris-v0.3.2-linux-arm\n    -rwxr-xr-x  1 root  root   7516368 Nov 24 16:44 iris-v0.3.2-windows-4.0-386.exe\n    -rwxr-xr-x  1 root  root   9549416 Nov 24 16:44 iris-v0.3.2-windows-4.0-amd64.exe\n\n\n### Branch selection\n\nSimilarly to `go get`, xgo also uses the `master` branch of a repository during\nsource code retrieval. To switch to a different branch before compilation pass\nthe desired branch name through the `--branch` argument.\n\n    $ xgo --branch release-branch.go1.4 golang.org/x/tools/cmd/goimports\n    ...\n\n    $ ls -al\n    -rwxr-xr-x  1 root  root   4171248 Nov 24 16:40 goimports-android-16-arm\n    -rwxr-xr-x  1 root  root   4139868 Nov 24 16:40 goimports-darwin-10.6-386\n    -rwxr-xr-x  1 root  root   5186720 Nov 24 16:40 goimports-darwin-10.6-amd64\n    -rwxr-xr-x  1 root  root   3202364 Nov 24 16:40 goimports-ios-5.0-arm\n    -rwxr-xr-x  1 root  root   4189456 Nov 24 16:40 goimports-linux-386\n    -rwxr-xr-x  1 root  root   5264136 Nov 24 16:40 goimports-linux-amd64\n    -rwxr-xr-x  1 root  root   4209416 Nov 24 16:40 goimports-linux-arm\n    -rwxr-xr-x  1 root  root   4348416 Nov 24 16:40 goimports-windows-4.0-386.exe\n    -rwxr-xr-x  1 root  root   5415424 Nov 24 16:40 goimports-windows-4.0-amd64.exe\n\n\n### Remote selection\n\nYet again similarly to `go get`, xgo uses the repository remote corresponding to\nthe import path being built. To switch to a different remote while preserving the\noriginal import path, use the `--remote` argument.\n\n    $ xgo --remote github.com/golang/tools golang.org/x/tools/cmd/goimports\n    ...\n\n### Package selection\n\nIf you used the above *branch* or *remote* selection machanisms, it may happen\nthat the path you are trying to build is only present in the specific branch and\nnot the default respoitory, causing Go to fail at locating it. To circumvent this,\nyou may specify only the repository root for xgo, and use an additional `--pkg`\nparameter to select the exact package within, honoring any prior *branch* and\n*remote* selections.\n\n    $ xgo --pkg cmd/goimports golang.org/x/tools\n    ...\n\n    $ ls -al\n    -rwxr-xr-x  1 root  root   4194956 Nov 24 16:38 goimports-android-16-arm\n    -rwxr-xr-x  1 root  root   4164448 Nov 24 16:38 goimports-darwin-10.6-386\n    -rwxr-xr-x  1 root  root   5223584 Nov 24 16:38 goimports-darwin-10.6-amd64\n    -rwxr-xr-x  1 root  root   3222848 Nov 24 16:39 goimports-ios-5.0-arm\n    -rwxr-xr-x  1 root  root   4217184 Nov 24 16:38 goimports-linux-386\n    -rwxr-xr-x  1 root  root   5295768 Nov 24 16:38 goimports-linux-amd64\n    -rwxr-xr-x  1 root  root   4233120 Nov 24 16:38 goimports-linux-arm\n    -rwxr-xr-x  1 root  root   4373504 Nov 24 16:38 goimports-windows-4.0-386.exe\n    -rwxr-xr-x  1 root  root   5450240 Nov 24 16:38 goimports-windows-4.0-amd64.exe\n\nThis argument may at some point be integrated into the import path itself, but for\nnow it exists as an independent build parameter. Also, there is not possibility\nfor now to build mulitple commands in one go.\n\n### Limit build targets\n\nBy default `xgo` will try and build the specified package to all platforms and\narchitectures supported by the underlying Go runtime. If you wish to restrict\nthe build to only a few target systems, use the comma separated `--targets` CLI\nargument:\n\n  * `--targets=linux/arm`: builds only the ARMv5 Linux binaries (`arm-6`/`arm-7` allowed)\n  * `--targets=windows/*,darwin/*`: builds all Windows and OSX binaries\n  * `--targets=*/arm`: builds ARM binaries for all platforms\n  * `--targets=*/*`: builds all suppoted targets (default)\n\nThe supported targets are:\n\n * Platforms: `android`, `darwin`, `ios`, `linux`, `windows`\n * Achitectures: `386`, `amd64`, `arm-5`, `arm-6`, `arm-7`, `arm64`, `mips`, `mipsle`, `mips64`, `mips64le`\n\n### Platform versions\n\nBy default `xgo` tries to cross compile to the lowest possible versions of every\nsupported platform, in order to produce binaries that are portable among various\nversions of the same operating system. This however can lead to issues if a used\ndependency is only supported by more recent systems. As such, `xgo` supports the\nselection of specific platform versions by appending them to the OS target string.\n\n * `--targets=ios-8.1/*`: cross compile to iOS 8.1\n * `--targets=android-16/*`: cross compile to Android Jelly Bean\n * `--targets=darwin-10.9/*`: cross compile to Mac OS X Mavericks\n * `--targets=windows-6.0/*`: cross compile to Windows Vista\n\nThe supported platforms are:\n\n * All Android APIs up to Android Lollipop 5.0 ([API level ids](https://source.android.com/source/build-numbers.html))\n * All Windows APIs up to Windows 8.1 limited by `mingw-w64` ([API level ids](https://en.wikipedia.org/wiki/Windows_NT#Releases))\n * OSX APIs in the range of 10.6 - 10.11\n * All iOS APIs up to iOS 9.3\n\n### Mobile libraries\n\nApart from the usual runnable binaries, `xgo` also supports building library\narchives for Android (`android/aar`) and iOS (`ios/framework`). Opposed to\n`gomobile` however `xgo` does not derive library APIs from the Go code, so\nproper CGO C external methods must be defined within the package.\n\nIn the case of Android archives, all architectures will be bundled that are\nsupported by the requested Android platform version. For iOS frameworks `xgo`\nwill bundle armv7 and arm64 by default, and also the x86_64 simulator builds\nif the iPhoneSimulator.sdk was injected by the user:\n\n* Create a new docker image based on xgo: `FROM karalabe/xgo-latest`\n* Inject the simulator SDK: `ADD iPhoneSimulator9.3.sdk.tar.xz /iPhoneSimulator9.3.sdk.tar.xz`\n* Bootstrap the simulator SDK: `$UPDATE_IOS /iPhoneSimulator9.3.sdk.tar.xz`\n\n### CGO dependencies\n\nThe main differentiator of xgo versus other cross compilers is support for basic\nembedded C/C++ code and target-platform specific OS SDK availability. The current\nxgo release introduces an experimental CGO *dependency* cross compilation, enabling\nbuilding Go programs that require external C/C++ libraries.\n\nIt is assumed that the dependent C/C++ library is `configure/make` based, was\nproperly prepared for cross compilation and is available as a tarball download\n(`.tar`, `.tar.gz` or `.tar.bz2`). Further plans include extending this to cmake\nbased projects, if need arises (please open an issue if it's important to you).\n\nSuch dependencies can be added via the `--deps` argument. They will be retrieved\nprior to starting the cross compilation and the packages cached to save bandwidth\non subsequent calls.\n\nA complex sample for such a scenario is building the Ethereum CLI node, which has\nthe GNU Multiple Precision Arithmetic Library as it's dependency.\n\n    $ xgo --deps=https://gmplib.org/download/gmp/gmp-6.1.0.tar.bz2  \\\n        --targets=windows/* github.com/ethereum/go-ethereum/cmd/geth\n    ...\n\n    $ ls -al\n    -rwxr-xr-x 1 root root 16315679 Nov 24 16:39 geth-windows-4.0-386.exe\n    -rwxr-xr-x 1 root root 19452036 Nov 24 16:38 geth-windows-4.0-amd64.exe\n\nSome trivial arguments may be passed to the dependencies' configure script via\n`--depsargs`.\n\n    $ xgo --deps=https://gmplib.org/download/gmp/gmp-6.1.0.tar.bz2  \\\n        --targets=ios/* --depsargs=--disable-assembly               \\\n        github.com/ethereum/go-ethereum/cmd/geth\n    ...\n\n    $ ls -al\n    -rwxr-xr-x 1 root root 14804160 Nov 24 16:32 geth-ios-5.0-arm\n\nNote, that since xgo needs to cross compile the dependencies for each platform\nand architecture separately, build time can increase significantly.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibbd-dev%2Fxgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibbd-dev%2Fxgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibbd-dev%2Fxgo/lists"}