1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
rust-bindgen
============
[![][crates-version-shield]](https://crates.io/crates/bindgen)
[![][crates-downloads-shield]](https://crates.io/crates/bindgen)
[![][crates-license-shield]](https://github.com/crabtw/rust-bindgen/blob/master/LICENSE)
[![][travis-status-shield]](https://travis-ci.org/crabtw/rust-bindgen/)
A binding generator for the rust language.
This is a fork designed to work on Spidermonkey headers.
It is ported from [clay's bindgen][].
Requirements
------------
* clang 3.7 with patches https://github.com/michaelwu/clang/tree/release_37_smhacks or clang 3.8+
This bindgen fork requires a patched clang or clang 3.8+ to work properly. This is one way to build a patched clang:
```
git clone https://github.com/llvm-mirror/llvm
cd llvm
git checkout release_37
cd tools
git clone https://github.com/llvm-mirror/clang
cd clang
git remote add mwu https://github.com/michaelwu/clang
git fetch mwu
git checkout release_37_smhacks
cd ../.. # llvm root dir
mkdir build
cd build
../configure --enable-optimized
make
```
Then before building, make sure to export the path to this copy of clang:
export LIBCLANG_PATH=~/llvm/build/Release+Asserts/lib
This path also needs to be set in LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (OSX) when running bindgen.
Building
--------
$ cargo build
Note: This links with Apple's version of libclang on OS X by default. This can be changed by setting the LIBCLANG_PATH environment variable.
If you are running the command line tool you will also need to append this
path to your DYLD_LIBRARY_PATH environment variable, which you might already have set if you have installed the Rust compiler outside of standard /usr/local path.
The default path on OS X is:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/
Or if you only have Xcode Command Line Tools installed:
export DYLD_LIBRARY_PATH=/Library/Developer/CommandLineTools/usr/lib
Command Line Usage
------------------
```
Usage: ./bindgen [options] input.h
Options:
-h or --help Display help message
-l <name> or -l<name> Link to a dynamic library, can be provided
multiple times
-static-link <name> Link to a static library
-framework-link <name> Link to a framework
-o <output.rs> Write bindings to <output.rs> (default stdout)
-match <name> Only output bindings for definitions from files
whose name contains <name>
If multiple -match options are provided, files
matching any rule are bound to
-builtins Output bindings for builtin definitions
(for example __builtin_va_list)
-allow-unknown-types Don't fail if we encounter types we do not support,
instead treat them as void
-emit-clang-ast Output the ast (for debugging purposes)
-override-enum-type <type> Override enum type, type name could be
uchar
schar
ushort
sshort
uint
sint
ulong
slong
ulonglong
slonglong
Options other than stated above are passed to clang
```
C++ Usage
---------
This fork of rust-bindgen can handle a number of C++ features. Because it currently uses a fork of clang though, it may require adding extra arguments to find certain headers. On OpenSUSE 13.2, these additional include pathes can be used:
-isystem /usr/lib64/gcc/x86_64-suse-linux/4.8/include -isystem /usr/lib64/gcc/x86_64-suse-linux/4.8/include-fixed
On OSX, this include path seems to work:
-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
When passing in header files, the file will automatically be treated as C++ if it ends in ``.hpp``. If it doesn't, ``-x c++`` can be used to force C++ mode.
Annotations
-----------
The translation of classes, structs, enums, and typedefs can be adjusted using annotations. Annotations are specifically formatted html tags inside doxygen style comments. The opaque annotation instructs bindgen to ignore all fields defined in a struct/class.
/// <div rust-bindgen opaque></div>
The hide annotation instructs bindgen to ignore the struct/class/field/enum completely.
/// <div rust-bindgen hide></div>
Macro Usage
-----------
```
Usage: bindgen!([headers], [named options])
Options:
Option Name Type Default
----------------------------------------------
link multiple strings
link_static multiple strings
link_framework multiple strings
match multiple strings
emit_builtins bool true
allow_unknown_types bool false
clang_args string
```
See "Command Line Usage" section for option descriptions
Examples
--------
###Generate MySQL client bindings
bindgen -l mysql -match mysql.h -o mysql.rs /usr/include/mysql/mysql.h
*or*
echo '#include <mysql.h>' > gen.h
bindgen `mysql_config --cflags` -l mysql -match mysql.h -o mysql.rs gen.h
*or*
Cargo.toml
[dependencies.bindgen]
git = "https://github.com/crabtw/rust-bindgen.git"
main.rs
#![feature(phase)]
#[phase(plugin)] extern crate bindgen;
#[allow(dead_code, uppercase_variables, non_camel_case_types)]
mod mysql_bindings {
bindgen!("/usr/include/mysql/mysql.h", match="mysql.h", link="mysql")
}
|