{"id":13609875,"url":"https://github.com/ebitengine/purego","last_synced_at":"2025-05-12T15:21:35.330Z","repository":{"id":37019234,"uuid":"492200379","full_name":"ebitengine/purego","owner":"ebitengine","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-15T11:37:52.000Z","size":354,"stargazers_count":2635,"open_issues_count":12,"forks_count":81,"subscribers_count":25,"default_branch":"main","last_synced_at":"2025-04-23T17:13:32.625Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ebitengine.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":"2022-05-14T11:46:28.000Z","updated_at":"2025-04-22T16:14:48.000Z","dependencies_parsed_at":"2024-02-29T18:54:50.562Z","dependency_job_id":"5371c7cb-173f-4269-8d5f-13b91ab0cd63","html_url":"https://github.com/ebitengine/purego","commit_stats":null,"previous_names":["ebiten/purego"],"tags_count":55,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ebitengine%2Fpurego","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ebitengine%2Fpurego/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ebitengine%2Fpurego/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ebitengine%2Fpurego/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ebitengine","download_url":"https://codeload.github.com/ebitengine/purego/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250477810,"owners_count":21437049,"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-01T19:01:38.870Z","updated_at":"2025-04-23T17:13:36.969Z","avatar_url":"https://github.com/ebitengine.png","language":"Go","readme":"# purego\n[![Go Reference](https://pkg.go.dev/badge/github.com/ebitengine/purego?GOOS=darwin.svg)](https://pkg.go.dev/github.com/ebitengine/purego?GOOS=darwin)\n\nA library for calling C functions from Go without Cgo.\n\n\u003e This is beta software so expect bugs and potentially API breaking changes\n\u003e but each release will be tagged to avoid breaking people's code.\n\u003e Bug reports are encouraged.\n\n## Motivation\n\nThe [Ebitengine](https://github.com/hajimehoshi/ebiten) game engine was ported to use only Go on Windows. This enabled\ncross-compiling to Windows from any other operating system simply by setting `GOOS=windows`. The purego project was\nborn to bring that same vision to the other platforms supported by Ebitengine.\n\n## Benefits\n\n- **Simple Cross-Compilation**: No C means you can build for other platforms easily without a C compiler.\n- **Faster Compilation**: Efficiently cache your entirely Go builds.\n- **Smaller Binaries**: Using Cgo generates a C wrapper function for each C function called. Purego doesn't!\n- **Dynamic Linking**: Load symbols at runtime and use it as a plugin system.\n- **Foreign Function Interface**: Call into other languages that are compiled into shared objects.\n- **Cgo Fallback**: Works even with CGO_ENABLED=1 so incremental porting is possible. \nThis also means unsupported GOARCHs (freebsd/riscv64, linux/mips, etc.) will still work\nexcept for float arguments and return values.\n\n## Supported Platforms\n\n- **FreeBSD**: amd64, arm64\n- **Linux**: amd64, arm64\n- **macOS / iOS**: amd64, arm64\n- **Windows**: 386*, amd64, arm*, arm64\n\n`*` These architectures only support SyscallN and NewCallback\n\n## Example\n\nThe example below only showcases purego use for macOS and Linux. The other platforms require special handling which can\nbe seen in the complete example at [examples/libc](https://github.com/ebitengine/purego/tree/main/examples/libc) which supports FreeBSD and Windows.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"runtime\"\n\n\t\"github.com/ebitengine/purego\"\n)\n\nfunc getSystemLibrary() string {\n\tswitch runtime.GOOS {\n\tcase \"darwin\":\n\t\treturn \"/usr/lib/libSystem.B.dylib\"\n\tcase \"linux\":\n\t\treturn \"libc.so.6\"\n\tdefault:\n\t\tpanic(fmt.Errorf(\"GOOS=%s is not supported\", runtime.GOOS))\n\t}\n}\n\nfunc main() {\n\tlibc, err := purego.Dlopen(getSystemLibrary(), purego.RTLD_NOW|purego.RTLD_GLOBAL)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tvar puts func(string)\n\tpurego.RegisterLibFunc(\u0026puts, libc, \"puts\")\n\tputs(\"Calling C from Go without Cgo!\")\n}\n```\n\nThen to run: `CGO_ENABLED=0 go run main.go`\n\n## Questions\n\nIf you have questions about how to incorporate purego in your project or want to discuss\nhow it works join the [Discord](https://discord.gg/HzGZVD6BkY)!\n\n### External Code\n\nPurego uses code that originates from the Go runtime. These files are under the BSD-3\nLicense that can be found [in the Go Source](https://github.com/golang/go/blob/master/LICENSE).\nThis is a list of the copied files:\n\n* `abi_*.h` from package `runtime/cgo`\n* `zcallback_darwin_*.s` from package `runtime`\n* `internal/fakecgo/abi_*.h` from package `runtime/cgo`\n* `internal/fakecgo/asm_GOARCH.s` from package `runtime/cgo`\n* `internal/fakecgo/callbacks.go` from package `runtime/cgo`\n* `internal/fakecgo/go_GOOS_GOARCH.go` from package `runtime/cgo`\n* `internal/fakecgo/iscgo.go` from package `runtime/cgo`\n* `internal/fakecgo/setenv.go` from package `runtime/cgo`\n* `internal/fakecgo/freebsd.go` from package `runtime/cgo`\n* `internal/fakecgo/netbsd.go` from package `runtime/cgo`\n\nThe files `abi_*.h` and `internal/fakecgo/abi_*.h` are the same because Bazel does not support cross-package use of\n`#include` so we need each one once per package. (cf. [issue](https://github.com/bazelbuild/rules_go/issues/3636))\n","funding_links":[],"categories":["杂项","Miscellaneous","Assembly","Microsoft Office"],"sub_categories":["未分类的","Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Febitengine%2Fpurego","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Febitengine%2Fpurego","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Febitengine%2Fpurego/lists"}