{"id":13993093,"url":"https://github.com/tydeu/lean4-alloy","last_synced_at":"2025-10-31T17:30:28.305Z","repository":{"id":39971967,"uuid":"429637569","full_name":"tydeu/lean4-alloy","owner":"tydeu","description":"Write C shims from within Lean code.","archived":false,"fork":false,"pushed_at":"2024-07-22T17:10:15.000Z","size":230,"stargazers_count":47,"open_issues_count":1,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-10T14:12:29.163Z","etag":null,"topics":["lean4"],"latest_commit_sha":null,"homepage":"","language":"Lean","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/tydeu.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":"2021-11-19T01:54:10.000Z","updated_at":"2024-07-22T17:10:18.000Z","dependencies_parsed_at":"2023-02-09T05:33:17.987Z","dependency_job_id":"28546758-1b8a-421d-bd83-6c14d150b294","html_url":"https://github.com/tydeu/lean4-alloy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tydeu%2Flean4-alloy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tydeu%2Flean4-alloy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tydeu%2Flean4-alloy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tydeu%2Flean4-alloy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tydeu","download_url":"https://codeload.github.com/tydeu/lean4-alloy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239218568,"owners_count":19601887,"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":["lean4"],"created_at":"2024-08-09T14:02:13.766Z","updated_at":"2025-10-31T17:30:28.269Z","avatar_url":"https://github.com/tydeu.png","language":"Lean","funding_links":[],"categories":["Lean"],"sub_categories":[],"readme":"# Alloy\n\nAlloy is a Lean 4 library that allows one to embed external FFI code (currently just C) directly within Lean. For example, we can define an external C add function like so:\n\n```lean\nalloy c extern def myAdd (x y : UInt32) : UInt32 := {\n  return x + y;\n}\n```\n\nAnd Alloy will generate the corresponding C function:\n\n```c\nLEAN_EXPORT uint32_t _alloy_c_l_myAdd ( uint32_t x , uint32_t y ) {\n  return x + y;\n}\n```\n\n## Building Shims\n\nAlloy exploits Lake's [module facets feature](https://github.com/leanprover/lake/tree/master#defining-new-facets) to automagically build the shim it produces when compiling the module. Combined with the new `precompileModules` feature, this allows the shim code to be directly used by importers in a interpreted context (e.g., for `#eval` or when editing).\n\nTo use Alloy with your project and build shims for a library, add the following to your Lakefile:\n\n```lean\nrequire alloy from git \"https://github.com/tydeu/lean4-alloy.git\"\n\nmodule_data alloy.c.o.export : BuildJob FilePath\nmodule_data alloy.c.o.noexport : BuildJob FilePath\nlean_lib \u003cyour-lib\u003e where\n  precompileModules := true\n  nativeFacets := fun shouldExport =\u003e\n    if shouldExport then\n      #[Module.oExportFacet, `alloy.c.o.export]\n    else\n      #[Module.oNoExportFacet, `alloy.c.o.noexport]\n  -- and whatever other configuration options you wish to add\n```\n\nTake a look at the [examples](examples) to see how all of this works. The [my_add](examples/my_add) example provides a minimal setup whereas the [S](examples/S) example provides a more complete demonstration of Alloy's power.\n\n## Disclaimer\n\nAlloy is still a **work-in-progress**. However, it is now at the point where it can be feasible used to build FFIs. Its biggest TODOs are LSP support for the embedded C code and adding more utilities to help with common code patterns (e.g., defining wrapped C structures).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftydeu%2Flean4-alloy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftydeu%2Flean4-alloy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftydeu%2Flean4-alloy/lists"}