Rust crate gr¶
Installation¶
In your Rust project, issue the command
cargo add gr
Set the
GRLIB
environment variable to the path of GR’slib
directory / folderIt should contain
.lib
,.dylib
or.so
filesOn Windows (and also MinGW) you should use an absolute path
On Linux and Mac some paths will be searched when
GRLIB
doesn’t refer to a usable installation:~/gr
(ie. implicitGRLIB=~/gr/lib
)/usr/gr
(ie. implicitGRLIB=/usr/gr/lib
)/usr/local/gr
(ie. implicitGRLIB=/usr/local/gr/lib
)
This variable is only needed at compile-time
Your Rust program will need to dynamically load GR libraries! Make them accessible!
Ensure GR’s library files are found by your OS’s dynamic loader. If that’s already the case, you don’t have to do anything.
You may need to edit your
PATH
(Windows),LD_LIBRARY_PATH
(Linux),DYLD_LIBRARY_PATH
(Mac) or your binaries’ rpaths.On Windows, the required path is not the same as
GRLIB
! It should point to thebin
folder, which contains the.dll
files. Alternatively, you can just copy the.dll
files next to your.exe
.On Linux and Mac, you can set the rpath when building an executable from a Rust crate like this:
RUSTFLAGS="-C link-arg=-Wl,-rpath,/my/path/to/gr/lib" cargo build ./target/debug/mybinaryname # or run it using `cargo run` above
This is useful if GR isn’t found normally, but the resulting binary shouldn’t be distributed.
Getting Started¶
To test your setup, try compiling and running this simple application:
use ::gr::gr;
use std::io::{stdin, Read};
fn main() {
gr::polyline(2, &[0.0, 1.0], &[0.0, 1.0]).unwrap();
gr::updatews();
stdin().bytes().next();
}
Examples¶
The crate includes a collection of Rust scripts using GR in its examples/
directory.
Run them using cargo:
cargo run --example
API Reference¶
The Rust API for GR consists of: