#gmsh #ffi #api-bindings

bin+lib rgmsh

Unofficial, opinionated Rust bindings to the Gmsh API

3 releases

0.1.2 Nov 19, 2019
0.1.1 Nov 19, 2019
0.1.0 Sep 19, 2019

#747 in Science

Custom license

66KB
869 lines

High-level bindings to the Gmsh API.

You'll need a copy of the Gmsh library, libgmsh, to use this crate.

Setting up libgmsh

This crate uses an environment variable GMSH_LIB_DIR. Set GMSH_LIB_DIR to the location of your Gmsh SDK /lib folder. You'll also need to adjust your LD_LIBRARY_PATH to be able to find the library at runtime.

libgmsh installation (Linux)

Download the Gmsh SDK (v4.4.1) to the current folder and set your library variables accordingly.

$ wget http://gmsh.info/bin/Linux/gmsh-4.4.1-Linux64-sdk.tgz -O /tmp/gmsh-sdk.tar.gz
$ tar -xvf /tmp/gmsh-sdk.tar.gz
$ export GMSH_LIB_DIR=$PWD/gmsh-4.4.1-Linux64-sdk/lib/
$ export LD_LIBRARY_PATH=$GMSH_LIB_DIR:$LD_LIBRARY_PATH
$ cargo test -- --test-threads=1

Add the variables to your shell configuration file to avoid having to set them each time.

# in your .bashrc or similar 
GMSH_LIB_DIR="/path/to/your/gmsh-sdk/lib"
export GMSH_LIB_DIR

LD_LIBRARY_PATH=$GMSH_LIB_DIR:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH

Getting started

Run the examples using cargo run --example <example>

Gmsh is a shared resource, and Rust tests run in parallel by default, so cargo test alone will crash.

Run the tests using cargo test -- --test-threads=1

You can make an alias for this command in your ~/.cargo/config file:

[alias]
tt = "test -- --test-threads=1"

Linking to the Gmsh library

Gmsh ships prebuilt binary SDK libraries for Linux, MacOS, and Windows.

The download server is: http://gmsh.info/bin/

Download a recent version and make sure the filename ends with sdk.

Linux

Place all dynamic library libgmsh.so* files where the linker can find them.

Windows

Gmsh is built by MinGW on Windows, not the Visual Studio toolchain.

Because of ABI differences, the easiest way to link your Rust programs to Gmsh is to use the x86_64-pc-windows-gnu target and stable-gnu toolchain.

rustup default stable-gnu

Then, download the Windows SDK zip file and ensure the linker can find the library.

If it can't, you'll get large scary errors when you run cargo test -- --test-threads=1

One way to make sure the linker can find Gmsh is copying the .lib and .dll files to your rustup directory, e.g.:

~\.rustup\toolchains\stable-x86_64-pc-windows-gnu\lib\rustlib\x86_64-pc-windows-gnu\lib

Dependencies

~145KB