savvy-bindgen 0.10.2

Parse Rust functions, and generate C and R code
Documentation
# Even when `cargo` is on `PATH`, `rustc` might not in some cases. This adds
# ~/.cargo/bin to PATH to address such cases. Note that is not always available
# (e.g. or on Ubuntu with Rust installed via APT).
if [ -d "${HOME}/.cargo/bin" ]; then
  export PATH="${PATH}:${HOME}/.cargo/bin"
fi

CARGO_VERSION="$(cargo --version)"

if [ $? -ne 0 ]; then
  echo "-------------- ERROR: CONFIGURATION FAILED --------------------"
  echo ""
  echo "The cargo command is not available. To install Rust, please refer"
  echo "to the official instruction:"
  echo ""
  echo "https://www.rust-lang.org/tools/install"
  echo ""
  echo "---------------------------------------------------------------"

  exit 1
fi

# There's a little chance that rustc is not available on PATH while cargo is.
# So, just ignore the error case.
RUSTC_VERSION="$(rustc --version || true)"

# Report the version of Rustc to comply with the CRAN policy
echo "using Rust package manager: '${CARGO_VERSION}'"
echo "using Rust compiler: '${RUSTC_VERSION}'"

if [ "$(uname)" = "Emscripten" ]; then
  TARGET="wasm32-unknown-emscripten"
fi

# allow overriding profile externally (e.g. on CI)
if [ -n "${SAVVY_PROFILE}" ]; then
  PROFILE="${SAVVY_PROFILE}"
# catch DEBUG envvar, which is passed from pkgbuild::compile_dll()
elif [ "${DEBUG}" = "true" ]; then
  PROFILE=dev
else
  PROFILE=release
fi

# e.g. SAVVY_FEATURES="a b"  -->  "--features 'a b'"
if [ -n "${SAVVY_FEATURES}" ]; then
  FEATURE_FLAGS="--features '${SAVVY_FEATURES}'"
fi

# Set macOS deployment target for the Rust cc crate.
#
# The cc crate (used by savvy's build.rs to compile unwind_protect_wrapper.c)
# does not derive the deployment target from CC/CFLAGS. Instead, it looks up
# MACOSX_DEPLOYMENT_TARGET, falling back to `xcrun --show-sdk-version`, and
# passes the result as -mmacosx-version-min=<value>. When the env var is unset,
# the fallback SDK version (e.g. 26.2) can be newer than the version R's
# compiler targets, producing an ld warning about version mismatch.
#
# We default to 11.0, the minimum deployment target for arm64 macOS. This
# should be safe because unwind_protect_wrapper.c is a fairly simple C code
# and uses no version-specific APIs.
if [ "$(uname)" = "Darwin" ]; then
  MACOSX_DEPLOYMENT_TARGET="${MACOSX_DEPLOYMENT_TARGET:-11.0}"
  echo "using macOS deployment target: ${MACOSX_DEPLOYMENT_TARGET}"
  BEFORE_CARGO_BUILD="${BEFORE_CARGO_BUILD}"' export MACOSX_DEPLOYMENT_TARGET="'"${MACOSX_DEPLOYMENT_TARGET}"'" \&\&'
fi

sed \
  -e "s/@TARGET@/${TARGET}/" \
  -e "s/@PROFILE@/${PROFILE}/" \
  -e "s/@FEATURE_FLAGS@/${FEATURE_FLAGS}/" \
  -e "s|@BEFORE_CARGO_BUILD@|${BEFORE_CARGO_BUILD}|" \
  src/Makevars.in > src/Makevars