Automatically build ImageMagick bindings

Leave the generated bindings out of the source repository and instead
have Cargo automatically build them if they are missing. This allows the
version of MagickWand to be incorporated into the bindings
automatically. For instance, in Homebrew the version is 6.Q16, while on
FreeBSD 10.2 it is 6.9, and only be generating the bindings for each
system can we ensure a smooth compilation process.
This commit is contained in:
Nathan Fiedler
2016-01-24 21:56:11 -08:00
parent 34c4fec9fe
commit 04e1052266
5 changed files with 99 additions and 8721 deletions

View File

@ -2,6 +2,12 @@
A somewhat safe Rust interface to the [ImageMagick](http://www.imagemagick.org/) system, in particular, the MagickWand library. Many of the functions in the MagickWand API are still missing, and those that are needed will be gradually added.
## Dependenices
* Rust
* Cargo
* ImageMagick
## Build and Test
Pretty simple for now.
@ -33,25 +39,3 @@ fn resize() -> Result<Vec<u8>, &'static str> {
wand.write_image_blob("jpeg")
}
```
## Generating Bindings
To generate the ImageMagick bindings, we use [rust-bindgen](https://github.com/crabtw/rust-bindgen), which reads the C header files and produces a suitable wrapper in Rust.
This example is using the [Homebrew](http://brew.sh) installed version of ImageMagick, and the LLVM compiler suite provided in the Command Line Tools from Apple. The only real difference for Mac OS X is the `DYLD_LIBRARY_PATH` that is needed to work around [issue #89](https://github.com/crabtw/rust-bindgen/issues/89) in rust-bindgen. Otherwise, the same basic steps should work on any Rust-supported system.
```
$ git clone https://github.com/crabtw/rust-bindgen.git
$ cd rust-bindgen
$ cargo build
$ echo '#include <wand/MagickWand.h>' > ~/gen.h
$ DYLD_LIBRARY_PATH=/Library/Developer/CommandLineTools/usr/lib \
./target/debug/bindgen \
`MagickWand-config --cflags` \
-builtins \
-o ~/bindings.rs \
`MagickWand-config --ldflags` \
~/gen.h
```
Then copy the `~/bindings.rs` file into the `src` directory of this project, and rebuild everything (`cargo clean` and `cargo test`). Hopefully it still works.