c_rs

Crates.ioc_rs
lib.rsc_rs
version0.1.9
sourcesrc
created_at2022-05-14 14:47:55.919452
updated_at2022-05-14 14:47:55.919452
descriptionEmbed C code inside your Rust code. GCC and rustc nightly required.
homepage
repositoryhttps://github.com/mrMiiao/c_rs
max_upload_size
id586689
size31,932
(mrMiiao)

documentation

README

Status: works, v0.1.9

What's this?

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!

So how do I use it?

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

Goals:

  • Fix header linkage error
  • Add local header support using "crate"
  • Add ctypes
Commit count: 158

cargo fmt