#!/usr/bin/env bash # README: # # The `ffi` module has a sub module for each supported O/S (curently only Mac) # and each of these contains the same four bindings; `langinfo`, `localcharset`, # `locale`, and `xlocale`. In this way the interface to the library above # is always the same and bindings have not yet needed to be edited in any # way. case $(uname) in Darwin) if [[ $(command -v llvm-config) ]] ; then MAC_PLATFORM=MacOSX INCLUDE="$(xcode-select -p)/Platforms/$MAC_PLATFORM.platform/Developer/SDKs/$MAC_PLATFORM.sdk/usr/include" BIND_HEADERS=langinfo,locale,xlocale MODULE=macos else echo "llvm not installed, or not on the path, try:" echo "$ brew install llvm" echo "$ PATH=\$PATH:/usr/local/opt/llvm/bin" exit 2 fi ;; Linux) if [[ $(command -v llvm-config) ]] ; then INCLUDE="/usr/include" BIND_HEADERS=langinfo,locale MODULE=linux else echo "llvm not installed, or not on the path, try:" echo "sudo apt-get install llvm" echo "sudo apt-get install clang" exit 2 fi ;; *) echo "Unsupported O/S" exit 1 ;; esac mkdir -p src/ffi/$MODULE if [[ ! $(command -v bindgen) ]] ; then cargo install bindgen cargo install rustfmt fi MODULES="" for HEADER in ${BIND_HEADERS//,/ } do if [[ -f "$INCLUDE/$HEADER.h" ]] ; then echo "generating bindings for $INCLUDE/$HEADER.h into src/ffi/$MODULE/$HEADER.rs" bindgen --verbose $INCLUDE/$HEADER.h --output src/ffi/$MODULE/$HEADER.rs git add src/ffi/$MODULE/$HEADER.rs MODULES=$(printf "%s\n#[allow(non_snake_case, non_camel_case_types, dead_code, unused_variables)]\npub mod %s;\n" "$MODULES" $HEADER) else echo "header file $HEADER.h does not exist in $INCLUDE" fi done VERSION_FILE="src/ffi/$MODULE/mod.rs" echo "writing module file in $VERSION_FILE" cat < "$VERSION_FILE" /* automatically generated by create-bindings */ /* generated on $(date), */ /* for $(uname -s), release $(uname -r) */ $MODULES EOF git add $VERSION_FILE