{"id":18610467,"url":"https://github.com/neilotoole/xcgo","last_synced_at":"2025-04-10T22:32:10.634Z","repository":{"id":44766432,"uuid":"245323267","full_name":"neilotoole/xcgo","owner":"neilotoole","description":"Golang cross-platform builder docker image with CGo and other tooling","archived":false,"fork":false,"pushed_at":"2023-09-24T17:00:08.000Z","size":36,"stargazers_count":65,"open_issues_count":1,"forks_count":16,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T05:41:54.528Z","etag":null,"topics":["cgo","cross-compile","cross-compiler-toolchain","docker","go","golang","golang-cross","goreleaser","linux","macos","windows"],"latest_commit_sha":null,"homepage":null,"language":"Dockerfile","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/neilotoole.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}},"created_at":"2020-03-06T03:39:20.000Z","updated_at":"2024-08-19T09:28:49.000Z","dependencies_parsed_at":"2022-09-09T23:40:45.213Z","dependency_job_id":null,"html_url":"https://github.com/neilotoole/xcgo","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neilotoole%2Fxcgo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neilotoole%2Fxcgo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neilotoole%2Fxcgo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neilotoole%2Fxcgo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neilotoole","download_url":"https://codeload.github.com/neilotoole/xcgo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248310058,"owners_count":21082338,"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":["cgo","cross-compile","cross-compiler-toolchain","docker","go","golang","golang-cross","goreleaser","linux","macos","windows"],"created_at":"2024-11-07T03:10:06.768Z","updated_at":"2025-04-10T22:32:10.303Z","avatar_url":"https://github.com/neilotoole.png","language":"Dockerfile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# neilotoole/xcgo\n\n\u003e **Note**\n\u003e With the advent of the Apple Silicon architecture, this project has become even more work to maintain.\n\u003e I originally developed `xcgo` as a build tool for [`sq`](https://github.com/neilotoole/sq), as\n\u003e no other tool readily supported all of `sq`'s various build targets. However, recent releases\n\u003e of [GoReleaser](https://goreleaser.com) plus GitHub workflows now satisify `sq`'s needs. This project will no longer\n\u003e be actively maintained, although PRs will still be accepted.\n\n`xcgo` is a maximalist Docker image for cross-compiling and\nreleasing/distributing CGo-enabled Go/Golang applications. At this time, it can build and dist\nmacOS, Windows and Linux CGo projects for arch `amd64`.\n\n`xcgo` has what gophers crave:\n\n- `go 1.17`\n- `OSX SDK` Catalina / `macOS 10.15` (will build on later versions)\n- `docker`\n- `snapcraft`\n- `goreleaser`\n- `golangci-lint`\n- `mage`\n- `zsh`\n- and a bunch of other stuff.\n\nThe primary source of documentation for `xcgo` is the [wiki](https://github.com/neilotoole/xcgo/wiki). \nStart there. There's a companion example project ([neilotoole/sqlitr](https://github.com/neilotoole/sqlitr)) \nthat was created explicitly to exhibit `xcgo`: it demonstrates pretty much the entire array of `xcgo`'s capabilities, \nshowing how to release to `brew`, `scoop`, `snap`, Docker Hub, GitHub, etc. The `neilotoole/xcgo` images are \npublished to [Docker Hub](https://hub.docker.com/r/neilotoole/xcgo).\n\n\u003e Note: No effort has yet been made to provide support for other\n\u003e archs such as `386` (or for an OS beyond the typical three),\n\u003e but pull requests are welcome. Note also that no effort has been\n\u003e made to make this image slim. `xcgo` by mission is\n\u003e maximalist (it's a 3GB+ image), but I'm sure the `Dockerfile` \n\u003e can be slimmed down. Again, pull requests are welcome.\n\n## Usage\n\nYou can test `xcgo` with:\n\n```shell script\n$ docker run -it neilotoole/xcgo:latest go version\ngo version go1.17.2 linux/amd64\n```\n\nTo play around in the container, launch into a shell:\n\n```shell script\n$ docker run -it neilotoole/xcgo:latest zsh\n```\n\n`xcgo` doesn't prescribe a particular usage approach. Some possibilities:\n\n- Launch a container shell session, clone your repo, and build (or even edit and do all your work) within the container. \n- Mount your local repo into the container, shell in, and build from within the container.\n- With local repo mounted, invoke `xcgo` with `goreleaser`: this is pretty typical.\n\n### Example: `go build` inside container\n\nFrom inside the docker container, we'll build (`amd64`) binaries for macOS, Linux, and Windows.\n\nShell into the `xcgo` container if you haven't already done so:\n\n```shell script\n$ docker run -it neilotoole/xcgo:latest zsh\n```\n\nFrom inside the container:\n\n```shell script\n$ git clone https://github.com/neilotoole/sqlitr.git \u0026\u0026 cd sqlitr\n$ GOOS=darwin GOARCH=amd64 CC=o64-clang CXX=o64-clang++ go build -o dist/darwin_amd64/sqlitr\n$ GOOS=linux GOARCH=amd64 go build -o dist/linux_amd64/sqlitr\n$ GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -o dist/windows_amd64/sqlitr.exe\n```\nYou should end up with something like this:\n\n```shell script\n$ tree ./dist\n./dist\n├── darwin_amd64\n│   └── sqlitr\n├── linux_amd64\n│   └── sqlitr\n└── windows_amd64\n    └── sqlitr.exe\n```\n\n### Example: `goreleaser`\n\nQuite possibly you'll want to use `xcgo` in conjunction \nwith [goreleaser](http://goreleaser.com). \n\nAgain, we'll use `sqlitr` to demonstrate. On your local machine, clone the `sqlitr` repo, mount it into the `xcgo` container and run `goreleaser`.\n\n```shell script\n$ git clone https://github.com/neilotoole/sqlitr.git \u0026\u0026 cd sqlitr\n$ docker run --rm --privileged \\\n-v $(pwd):/go/src/github.com/neilotoole/sqlitr \\\n-v /var/run/docker.sock:/var/run/docker.sock \\\n-w /go/src/github.com/neilotoole/sqlitr \\\nneilotoole/xcgo:latest goreleaser --snapshot --rm-dist\n```\n\nThe above will build that CGo project via `goreleaser` with binaries for macOS, Linux, and Windows.\n\n```shell script\n$ tree ./dist\n./dist\n├── build_linux_linux_amd64\n│   └── sqlitr\n├── build_macos_darwin_amd64\n│   └── sqlitr\n├── build_windows_windows_amd64\n│   └── sqlitr.exe\n├── checksums.txt\n├── config.yaml\n├── goreleaserdocker393975300\n│   ├── Dockerfile\n│   ├── LICENSE\n│   ├── README.md\n│   ├── sqlitr\n│   └── testdata\n│       └── example.sqlite\n├── sqlitr_v0.1.23-snapshot_darwin_amd64.tar.gz\n├── sqlitr_v0.1.23-snapshot_linux_amd64\n│   └── prime\n│       ├── meta\n│       │   └── snap.yaml\n│       └── sqlitr\n├── sqlitr_v0.1.23-snapshot_linux_amd64.deb\n├── sqlitr_v0.1.23-snapshot_linux_amd64.rpm\n├── sqlitr_v0.1.23-snapshot_linux_amd64.snap\n├── sqlitr_v0.1.23-snapshot_linux_amd64.tar.gz\n└── sqlitr_v0.1.23-snapshot_windows_amd64.zip\n```\n\nAgain, see the [wiki](https://github.com/neilotoole/xcgo/wiki) for more.\n\n\n## Parameterization\nSome params that can be passed to `xcgo` (as args to `docker run`):\n\n- **Docker:** `-e DOCKER_USERNAME=X -e DOCKER_PASSWORD=X`\n\t\n\tWhen present, `xcgo`'s `entrypoint.sh` performs a `docker login`.\n\tSupply `-e DOCKER_REGISTRY=X` to use a registry other than Docker Hub.\n\t\n- **GitHub:** `-e GITHUB_TOKEN=X` or `-e GORELEASER_GITHUB_TOKEN=X`\n\n\tUsed to publish artifacts to GitHub (e.g. by `goreleaser`).\n\n- **Snapcraft:** `-v \"${HOME}/.snapcraft.login\":/.snapcraft.login`\n\n\tWhen `/.snapcraft.login` is present in the `xcgo` container, `entrypoint.sh`\n\tperforms a `snapcraft` login. This enables use of `snapcraft`, e.g. by `goreleaser`\n\tto publish a `snap`.\n\t\n\tSupply `-e SNAPCRAFT_LOGIN_FILE=/other/place/.snapcraft.login` to specify an\n\talternative mount location for the login file. See the [wiki](https://github.com/neilotoole/xcgo/wiki/Snapcraft) for more.\n\n## Issues\n\nFirst, consult the [wiki](https://github.com/neilotoole/xcgo/wiki) and\nthe [neilotoole/sqlitr](https://github.com/neilotoole/sqlitr) example project.\nThen open an [issue](https://github.com/neilotoole/xcgo/issues).\n\n\n## FAQ\n\nSee FAQ on [wiki](https://github.com/neilotoole/xcgo/wiki/FAQ).\n\n## Related Projects\n\nComments for related projects are as of `2020-03-14`:\n\n- [Official golang image](https://hub.docker.com/_/golang): doesn't support CGo.\n- [mailchain/goreleaser-xcgo](https://github.com/mailchain/goreleaser-xcgo): doesn't support `go1.14` or `snapcraft`.\n- [docker/golang-cross](https://github.com/docker/golang-cross): doesn't support `go1.14` or `snapcraft`.\n\n## Acknowledgments\n\n- [mailchain/goreleaser-xcgo](https://github.com/mailchain/goreleaser-xcgo): this was the original fork point for `xcgo`. \n- [tpoechtrager/osxcross](https://github.com/tpoechtrager/osxcross): fundamental to macOS capabilities.\n- [mingw](http://www.mingw.org/): fundamental to Windows capabilities.\n- [goreleaser](https://goreleaser.com): core to `xcgo`'s mission. \n- [docker/golang-cross](https://github.com/docker/golang-cross): much gleaned from here.\n- [SQLite](https://www.sqlite.org/) and [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3): the perfect use case, as seen in `xcgo`'s companion example project [neilotoole/sqlitr](https://github.com/neilotoole/sqlitr).\n- And many others, see [sqlitr/go.mod](https://github.com/neilotoole/sqlitr/blob/master/go.mod) at a minimum. If anybody has been overlooked, please open an [issue](https://github.com/neilotoole/xcgo/issues/new).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneilotoole%2Fxcgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneilotoole%2Fxcgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneilotoole%2Fxcgo/lists"}