{"id":13837330,"url":"https://github.com/hexops/zgo","last_synced_at":"2025-07-10T18:32:58.304Z","repository":{"id":65875808,"uuid":"601689302","full_name":"hexops/zgo","owner":"hexops","description":"Go + Zig = 💕 | Zig and Go are best friends","archived":false,"fork":false,"pushed_at":"2023-07-13T04:51:23.000Z","size":33,"stargazers_count":37,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-30T00:14:05.594Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hexops.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"slimsag"}},"created_at":"2023-02-14T15:55:56.000Z","updated_at":"2024-05-30T03:15:27.836Z","dependencies_parsed_at":null,"dependency_job_id":"608c9582-fba6-41a6-956d-e4ab18bff3c0","html_url":"https://github.com/hexops/zgo","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"51e18e676c874ffdab452d2b60d4e03bcc1ff561"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexops%2Fzgo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexops%2Fzgo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexops%2Fzgo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexops%2Fzgo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hexops","download_url":"https://codeload.github.com/hexops/zgo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225653860,"owners_count":17502939,"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":[],"created_at":"2024-08-04T15:01:06.572Z","updated_at":"2024-11-21T00:30:31.444Z","avatar_url":"https://github.com/hexops.png","language":"Go","readme":"# zgo: Go + Zig = 💕 | Zig and Go are best friends\n\n[Zig](https://ziglang.org) is an up-and-coming language that shares many similar qualities with Go. Many Go developers who encounter Zig find that Zig and Go appear to be best friends, and companies like Uber [use Zig](https://www.youtube.com/watch?v=SCj2J3HcEfc) as part of their Go build toolchain to ensure all of their developers have a seamless CGO/cross-compilation experience.\n\n## Early stages\n\nThis is an early-stages MVP version. You can use it for cross-compilation, but may find issues. If you do, please open an issue and I'll be happy to look into it for you. :)\n\n## CGO cross-compilation that Just Works™\n\nCross-compilation with CGO is usually pretty tough. Various projects try to solve this, (such as [purego](https://github.com/ebitengine/purego), which loads dynamic libraries at runtime but means you don't get a static library in the end, or [xgo](https://github.com/techknowlogick/xgo) which packages multiple gigabytes of C/C++ toolchains into a Docker image for you.)\n\nSince Zig is not only a new language, but also a full C/C++ toolchain with cross-compilation that just works out of the box (similar to Go), in just \u003c100 MB you can target any OS/architecture while building C/C++ code!\n\n`zgo` makes using Zig for cross-compilation in your Go projects easy, by offerring a drop-in replacement for `go build` called `zgo build`, and by managing the Zig installation for you (in a `.zgo/zig` directory) so your developers don't need to think about installing Zig or having the right version.\n\n### Usage\n\nNormally in Go you cross compile using e.g.:\n\n```\nGOOS=linux GOARCH=amd64 go build\n```\n\nWith zgo, you simply replace `go build` with `zgo build` and it'll cross-compile using Zig with full CGO support!\n\n## Use Zig code from Go\n\nZig is a lower-level language than Go (a better C, so to speak.) Unlike Go, it doesn't feature a garbage collector, and has a much stronger emphasis on performance where every bit counts. Zig also has excellent C/C++ integration, and can build static and dynamic libraries callable from CGO. If you have particularly performance-sensitive code, consider writing it in Zig and calling it through CGO.\n\n`zgo` aims to make integrating Zig codebases into Go codebases simpler. When you run `zgo build` it detects if a `build.zig` file is found in the working directory, and if so it will invoke `zig build -Dtarget=...` for you, so that your Zig code will have a chance to build. This means your Zig project can emit libraries to `zig-out/...` and then your Go code can simply use those via CGO!\n\n## No magic\n\nThere is no magic here. One can just as easily run `zig build -Dtarget=...` first, followed by `go build` with the right Go linker flags, etc. `zgo build` doesn't replace your build system, it's just a minimal, opinionated, helpful wrapper. If you want to see what zgo does, simply set `ZGO_VERBOSE=true` to see the flags it passes to `go build` etc.\n\n## Including your own CGO system dependencies\n\nWe're still working out best practices here with respect to zgo itself. Zig and CGO can obviously reference libraries/dependencies on your host system if you like, but as you are cross-compiling you will want them to be built for the target.\n\nThe general plan/guidance is to:\n\n1. Write a `build.zig` for your dependency, so that Zig can build it as the C/C++ compiler and dump the resulting library and headers into `zig-out/...`\n2. Use those from CGO.\n\nThen, since `zgo` will invoke `zig build` for you it would \"just work\".\n\n## Configuration\n\nzgo can be configured in two ways: (1) via `zgo.toml` ([example](zgo.toml)) (2) via environment variables:\n\n| `zgo.toml`                            | env                        | description                                                                                                                                                                                                               |\n| ------------------------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `acceptXCodeLicense=false`            | `ZGO_ACCEPT_XCODE_LICENSE` | Whether you accept the [XCode license agreement](https://www.apple.com/legal/sla/docs/xcode.pdf), which must be accepted in order to target macOS.                                                                        |\n| `version=\"0.11.0-dev.1615+f62e3b8c0\"` | `ZGO_VERSION`              | The [Zig version](https://ziglang.org/download/) to use. If set to `system` the system Zig installation is used instead. If not set, the latest nightly is downloaded to the `.zgo/zig` directory and used in the future. |\n| `verbose=false`                       | `ZGO_VERBOSE`              | enable verbose logging of what zgo does                                                                                                                                                                                   |\n| `dir=\".zgo\"`                          | `ZGO_DIR`                  | The directory zgo should install Zig and fetch a ~160MB copy of the Xcode SDK into                                                                                                                                        |\n","funding_links":["https://github.com/sponsors/slimsag"],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhexops%2Fzgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhexops%2Fzgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhexops%2Fzgo/lists"}