@ 260802.2
current
#!/usr/bin/env zsh

checkout="$HOME/rust/ripgrep/master"
if ! [ -d "$checkout" ]; then
  checkout="$HOME/rust/ripgrep"
fi
custom=
suffix=
debug=
features=''
target=''
target_flag=''
cargo=cargo

while [ $# -gt 0 ]; do
    case "$1" in
    --debug)
        debug=1
        shift
        ;;
    --pcre2)
        features+=' pcre2'
        shift
        ;;
    --musl)
        target='x86_64-unknown-linux-musl'
        target_flag=("--target" $target)
        cargo=cross
        shift
        ;;
    --help)
        echo "Usage: $(basename "$0") [--debug --pcre2 --musl] [<checkout> [<suffix>]]"
        exit
        ;;
    -*)
        break
        ;;
    *)
        if [ -z "$custom" ]; then
          checkout="$1"
          custom=1
        elif [ -z "$suffix" ]; then
          suffix="$1"
        else
          echo "Usage: $(basename "$0") [--debug --pcre2 --musl] [<checkout> [<suffix>]]" >&2
          exit 1
        fi
        shift
        ;;
    esac
done

# export RUSTFLAGS="-C target-cpu=native"
# export RUSTFLAGS="-C target-cpu=native -C link-arg=-fuse-ld=lld"
# export RUSTFLAGS="--cfg regex_disable_auto_optimizations --cfg regex_runtime_teddy_ssse3"
if [ -n "$debug" ]; then
  $cargo build "$@" \
    --manifest-path "$checkout/Cargo.toml" \
    --features "$features" \
    $target_flag
  if [ -z "$target" ]; then
    bin="$checkout/target/debug/rg"
  else
    bin="$checkout/target/$target/debug/rg"
  fi
else
  $cargo build "$@" \
    --manifest-path "$checkout/Cargo.toml" \
    --features "$features" \
    --release \
    $target_flag
  if [ -z "$target" ]; then
    bin="$checkout/target/release/rg"
  else
    bin="$checkout/target/$target/release/rg"
  fi
fi
if [ -z "$custom" ]; then
  if [ -d "$HOME/man" ]; then
    mkdir -p "$HOME/man/man1"
    "$bin" --generate man > "$HOME/man/man1/rg.1"
  fi
  if [ -d "$HOME/.zsh-complete" ]; then
    "$bin" --generate complete-zsh > "$HOME/.zsh-complete/_rg"
  fi
  if [ -n "$target" ]; then
      if [ -n "$debug" ]; then
          cp "$bin" "$checkout/target/debug/rg"
      else
          cp "$bin" "$checkout/target/release/rg"
      fi
  fi
fi

rev="$(git -C "$checkout" rev-parse HEAD | head -c8)"
if is-mac; then
  dir="$HOME/bin/aarch64"
else
  dir="$HOME/bin/x86_64"
fi
for dest in "$dir/rg" "$dir/rg-$rev"; do
  cp "$bin" "$dest"
  echo "available at: $dest"
done
if [ -n "$suffix" ]; then
  dest="$dir/rg-$suffix"
  cp "$bin" "$dest"
  echo "available at: $dest"
fi