#!/bin/bash

# Put our vendored version of cargo on the path. Can be helpful if you need
# quick access to cargo on a machine that does not have Rust installed
# separately, or want to run a quick check. Eg:

# $ . tools/cargo-env
# $ (cd rslib && cargo check)

BAZEL_EXTERNAL=$(bazel info output_base --ui_event_filters=-INFO)/external

if [[ "$OSTYPE" == "darwin"* ]]; then
   if [ "$(uname -m)" == "x86_64" ]; then
      export PATH="$BAZEL_EXTERNAL/rust_darwin_x86_64/bin:$PATH"
   else
      export PATH="$BAZEL_EXTERNAL/rust_darwin_aarch64/bin:$PATH"
   fi
else
   if [ "$(uname -m)" == "aarch64" ]; then
      export PATH="$BAZEL_EXTERNAL/rust_linux_aarch64/bin:$PATH"
   else
      export PATH="$BAZEL_EXTERNAL/rust_linux_x86_64/bin:$PATH"
   fi
fi
