{"id":25118061,"url":"https://github.com/jupiterrider/ffi","last_synced_at":"2026-02-11T22:57:27.679Z","repository":{"id":237055759,"uuid":"793714564","full_name":"JupiterRider/ffi","owner":"JupiterRider","description":"A purego binding for libffi.","archived":false,"fork":false,"pushed_at":"2026-02-06T15:56:05.000Z","size":358,"stargazers_count":200,"open_issues_count":1,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-02-06T23:54:18.126Z","etag":null,"topics":["freebsd","go","golang","libffi","linux","macos","windows"],"latest_commit_sha":null,"homepage":"","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/JupiterRider.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":"COPYRIGHT.txt","agents":null,"dco":null,"cla":null}},"created_at":"2024-04-29T18:24:05.000Z","updated_at":"2026-02-06T17:44:30.000Z","dependencies_parsed_at":"2024-06-19T11:23:05.340Z","dependency_job_id":"0ce1045a-e300-4e5a-a5b5-cdd582d95fef","html_url":"https://github.com/JupiterRider/ffi","commit_stats":null,"previous_names":["jupiterrider/ffi"],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/JupiterRider/ffi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JupiterRider%2Fffi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JupiterRider%2Fffi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JupiterRider%2Fffi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JupiterRider%2Fffi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JupiterRider","download_url":"https://codeload.github.com/JupiterRider/ffi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JupiterRider%2Fffi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29349259,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T20:11:40.865Z","status":"ssl_error","status_checked_at":"2026-02-11T20:10:41.637Z","response_time":97,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["freebsd","go","golang","libffi","linux","macos","windows"],"created_at":"2025-02-08T03:39:14.077Z","updated_at":"2026-02-11T22:57:27.674Z","avatar_url":"https://github.com/JupiterRider.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ffi\n[![Go Reference](https://pkg.go.dev/badge/github.com/jupiterrider/ffi.svg)](https://pkg.go.dev/github.com/jupiterrider/ffi)\n\nA purego binding for libffi.\n\n## Purpose\nYou can use [purego](https://github.com/ebitengine/purego) to call C code without cgo. ffi provides extra functionality (e.g. passing and returning structs by value).\n\n## Supported OS/Architecture\n- darwin/amd64\n- darwin/arm64\n- freebsd/amd64\n- freebsd/arm64\n- linux/amd64\n- linux/arm64\n- linux/riscv64\n- windows/amd64\n- windows/arm64\n\n## Software Requirements\n[libffi](https://github.com/libffi/libffi) is preinstalled on most distributions, because it also is a dependency of Python and Ruby. If not, you can install it explicitly:\n\n### Arch Linux\n```sh\nsudo pacman -S libffi\n```\n\n### Debian, Ubuntu\n```sh\nsudo apt install libffi8\n```\n\n### Fedora\n```sh\nsudo dnf install libffi\n```\n\n### FreeBSD\n```sh\npkg install libffi\n```\nNote: Use this `-gcflags=\"github.com/ebitengine/purego/internal/fakecgo=-std\"` build flag when cross compiling or having CGO_ENABLED set to 0 (FreeBSD only).\n\n### Windows\nThe AMD64 version of libffi is already embedded into this library and gets extracted and loaded at runtime. This feature can be disabled by using the build tag `ffi_no_embed` or the environment variable `FFI_NO_EMBED=1`.\n\n### macOS\nNo further requirements. The libffi binaries are embedded as well.\n\n## Examples\nIn this example we create our own library, which consists of two type definitions and one function:\n\n```c\n#include \u003cstdbool.h\u003e\n#include \u003cstring.h\u003e\n\ntypedef enum {\n    GROCERIES,\n    HOUSEHOLD,\n    BEAUTY\n} Category;\n\ntypedef struct {\n    const char *name;\n    double price;\n    Category category;\n} Item;\n\nbool IsItemValid(Item item)\n{\n    if (!item.name || strlen(item.name) == 0)\n    {\n        return false;\n    }\n\n    if (item.price \u003c 0)\n    {\n        return false;\n    }\n\n    if (item.category \u003e BEAUTY)\n    {\n        return false;\n    }\n\n    return true;\n}\n```\n\nCompile the code into a shared library:\n\n```sh\ngcc -shared -o libitem.so -fPIC item.c\n```\n\nThe consuming Go code:\n\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/jupiterrider/ffi\"\n)\n\ntype Category uint32\n\nconst (\n\tGroceries Category = iota\n\tHousehold\n\tBeauty\n)\n\ntype Item struct {\n\tName     *byte\n\tPrice    float64\n\tCategory Category\n}\n\nfunc main() {\n\t// load the library\n\tlib, err := ffi.Load(\"./libitem.so\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// create a new ffi.Type which defines the fields of the Item struct\n\ttypeItem := ffi.NewType(\u0026ffi.TypePointer, \u0026ffi.TypeDouble, \u0026ffi.TypeUint32)\n\n\t// get the IsItemValid function and describe its signature\n\t// (for bool we use ffi.TypeUint8)\n\tisItemValid, err := lib.Prep(\"IsItemValid\", \u0026ffi.TypeUint8, \u0026typeItem)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tvar item Item\n\t// strings are null-terminated and converted into a byte pointer\n\titem.Name = \u0026[]byte(\"Apple\\x00\")[0]\n\titem.Price = 0.22\n\titem.Category = Groceries\n\n\t// the return value is stored in a 64-bit integer type, because libffi\n\t// cannot handle smaller integer types as return value\n\tvar result ffi.Arg\n\n\t// call the C function\n\t// (keep in mind that you have to pass pointers and not the values themselves)\n\tisItemValid.Call(\u0026result, \u0026item)\n\n\tif result.Bool() {\n\t\tfmt.Println(\"Item is valid!\")\n\t} else {\n\t\tfmt.Println(\"Item is not valid!\")\n\t}\n}\n```\n\nYou can find more examples inside the [examples](examples) folder of this repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjupiterrider%2Fffi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjupiterrider%2Fffi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjupiterrider%2Fffi/lists"}