{"id":14992010,"url":"https://github.com/emilHof/zigc","last_synced_at":"2025-09-25T14:30:39.225Z","repository":{"id":65592251,"uuid":"595334750","full_name":"emilHof/zigc","owner":"emilHof","description":"A tool for compiling and linking Zig libraries to Rust projects.","archived":false,"fork":false,"pushed_at":"2023-02-02T18:42:10.000Z","size":24,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-10T06:08:53.484Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/emilHof.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":"2023-01-30T21:44:50.000Z","updated_at":"2024-11-04T11:17:35.000Z","dependencies_parsed_at":"2023-02-17T23:16:00.947Z","dependency_job_id":null,"html_url":"https://github.com/emilHof/zigc","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/emilHof%2Fzigc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emilHof%2Fzigc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emilHof%2Fzigc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emilHof%2Fzigc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emilHof","download_url":"https://codeload.github.com/emilHof/zigc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234200156,"owners_count":18795139,"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-09-24T15:00:39.182Z","updated_at":"2025-09-25T14:30:38.860Z","avatar_url":"https://github.com/emilHof.png","language":"Rust","funding_links":[],"categories":["FFI Bindings"],"sub_categories":[],"readme":"Zigc aims to provide the basic functionality for compiling and linking [Zig](https://ziglang.org/)\nlibraries into your [Rust](https://www.rust-lang.org/) projects.\n\n### Disclaimer\n\n[zig](https://ziglang.org/download/) is a requirement to compile `.zig` files with this crate.\n\n### Usage\n\nGiven the following function definition as an example:\n\n```zig\n// main.zig\nconst std = @import(\"std\");\n\nexport fn add(a: c_int, b: c_int) callconv(.C) c_int {\n    return a + b;\n}\n```\n\n1. Import the `zigc` and `libc` crates:\n\n```toml\n[dependencies]\nlibc = \"*\"\n\n[build-dependencies]\nzigc = \"*\"\n```\n\n2. Specify the `.zig` source file in your build script and zigc automatically compiles it into the right\n   directory and links the artifacts into your rust binary.\n\n```rust\n/* build.rs */\nfn main() {\n    zigc::Build::new()\n        .file(\"./src/main.zig\")\n        .finish();\n}\n```\n\n3. Import the functions in your Rust source code.\n\n```rust\n/* main.rs */\nextern crate libc;\nuse libc::c_int;\n\n#[link(name = \"main\", kind = \"dylib\")]\nextern \"C\" {\n    fn add(a: c_int, b: c_int) -\u003e c_int;\n}\n\nfn main() {\n    let res = unsafe { add(2, 2) };\n    println!(\"{res}\");\n}\n```\n\n4. Build/run your crate.\n\n```\n$ cargo run\n4\n```\n\n### Roadmap\n\n- [x] Basic `.zig` compilation\n- [x] MVP linking of `.so` files to cargo projects.\n- [x] Add logging.\n- [x] Automatic target specification using cargo's `TARGET` flag.\n- [x] Allow compilation and linking of `static` Zig libraries.\n- [ ] Add more options to `Build`\n  - [ ] Additional flags (`-cflags`, `-target`, `-mcpu`, etc)\n  - [x] Name output library file.\n  - [ ] Specify additional `include` libraries\n- [ ] Ability to compile and link multiple `.zig` files.\n\n### Contribute\n\nAny discovered issues, feature requests, and pull request are highly encouraged and appreciated! :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FemilHof%2Fzigc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FemilHof%2Fzigc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FemilHof%2Fzigc/lists"}