Crates.io | zigc |
lib.rs | zigc |
version | 0.0.3 |
source | src |
created_at | 2023-01-30 22:49:33.674632 |
updated_at | 2023-02-02 18:41:22.732912 |
description | A tool for compiling and linking Zig libraries to Rust projects. |
homepage | https://docs.rs/zigc |
repository | https://github.com/emilHof/zigc |
max_upload_size | |
id | 772224 |
size | 12,964 |
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:
// main.zig
const std = @import("std");
export fn add(a: c_int, b: c_int) callconv(.C) c_int {
return a + b;
}
zigc
and libc
crates:[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./* build.rs */
fn main() {
zigc::Build::new()
.file("./src/main.zig")
.finish();
}
/* main.rs */
extern crate libc;
use libc::c_int;
#[link(name = "main", kind = "dylib")]
extern "C" {
fn add(a: c_int, b: c_int) -> 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! :)