Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/huonw/header
Create a .h from a Rust file
https://github.com/huonw/header
Last synced: about 1 month ago
JSON representation
Create a .h from a Rust file
- Host: GitHub
- URL: https://github.com/huonw/header
- Owner: huonw
- License: other
- Created: 2014-01-25T13:02:14.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-01-25T13:03:21.000Z (almost 11 years ago)
- Last Synced: 2023-04-10T09:39:25.743Z (over 1 year ago)
- Language: Rust
- Size: 102 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# Semi-complete .h generator
Reads in a crate and creates a header out of the exported structs and
`extern "C"` function definitions in it. It currently only supports
primitive (non-vector or string) types in struct fields and function
definitions, and makes no effort to emit enums.This is highly unlikely to see further work in the near future, and is
meant as somewhat of an example of interfacing with the `syntax` and
`rustc` libraries, although
[#11792](https://github.com/mozilla/rust/issues/11792) means it's not
so great (see `#[no_std]` hack below).## Example
To run the example in `example`:
- compile `bin.rs` and `example/rust.rs` normally
- uncomment the `#[no_std];` lines & comment the `println!` ones in
`rust.rs`
- run `header` on `rust.rs`
- compile `c.c` passing the appropriate flags to make it look for the
Rust crate (`gcc c.c -L. -l$(rustc --crate-file-name rust.rs | sed
's/^lib\(.*\)so$/\1/')` works for me)
- run the resulting binary to see the exciting Rust <-> C calls (may
require pointing the dynamic libary loader to the current directory,
e.g. `LD_LIBRARY_PATH=. ./a.out` on Linux)