Crates.io | c_rs |
lib.rs | c_rs |
version | 0.1.9 |
source | src |
created_at | 2022-05-14 14:47:55.919452 |
updated_at | 2022-05-14 14:47:55.919452 |
description | Embed C code inside your Rust code. GCC and rustc nightly required. |
homepage | |
repository | https://github.com/mrMiiao/c_rs |
max_upload_size | |
id | 586689 |
size | 31,932 |
Meet c_rs
. It is a fork of no longer maintained project.
This crate lets you write C code directly inside Rust.
GCC and rustc nightly are required!
Specify your Cargo.toml with
[build-dependencies.c_rs]
git = "https://github.com/mrMiiao/c_rs"
version = "*"
features = ["build"]
[dependencies.c_rs]
git = "https://github.com/mrMiiao/c_rs"
version = "*"
features = ["macro"]
And put this to Build.rs
extern crate c_rs;
fn main()
{
c_rs::build("src/main.rs", "crate_name", |cfg|
{
// cfg is a gcc::Config object. You can use it to add additional
// configuration options to the invocation of the C compiler.
});
}
Example of main.rs
extern crate c_rs;
use c_rs::c;
use c_rs::ctypes::_void;
c!{
#include <stdio.h>
raw{
void hello_world() {
puts("Hello, World!");
}
}
}
extern "C" {
fn hello_world() -> _void;
}
fn main() {
unsafe{
hello_world();
}
}
You can find more examples here