Zigc aims to provide the basic functionality for compiling and linking Zig libraries into your Rust projects.
zig is a requirement to compile .zig
files with this crate.
Given the following function definition as an example:
```zig // main.zig const std = @import("std");
export fn add(a: cint, b: cint) callconv(.C) c_int { return a + b; } ```
zigc
and libc
crates:```toml [dependencies] libc = "*"
[build-dependencies] zigc = "*" ```
.zig
source file in your build script and zigc automatically compiles it into the right
directory and links the artifacts into your rust binary.rust
/* build.rs */
fn main() {
zigc::Build::new()
.file("./src/main.zig")
.finish();
}
```rust /* main.rs */ extern crate libc; use libc::c_int;
extern "C" { fn add(a: cint, b: cint) -> c_int; }
fn main() { let res = unsafe { add(2, 2) }; println!("{res}"); } ```
$ cargo run
4
.zig
compilation.so
files to cargo projects.TARGET
flag.Build
-cflags
, -target
, -mcpu
, etc)include
librariesstatic
Zig libraries..zig
files.Any discovered issues, feature requests, and pull request are highly encouraged and appreciated! :)