Skip to content

Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.

1.4 KB
Raw Blame
#!/bin/sh
set -eu

[ $# -eq 2 ] || { echo "usage: $0 <version> <SHA256SUMS>" >&2; exit 2; }

version=$1
sums=$2
base="https://github.com/erkamyaman/rust-anything/releases/download/v$version"

sha() {
  file="rust-anything-v$version-$1.tar.gz"
  hash=$(awk -v f="$file" '$2 == f || $2 == "*" f { print $1 }' "$sums")
  [ -n "$hash" ] || { echo "no sha256 for $file in $sums" >&2; exit 1; }
  echo "$hash"
}

mac_arm=$(sha aarch64-apple-darwin)
mac_x64=$(sha x86_64-apple-darwin)
linux_arm=$(sha aarch64-unknown-linux-gnu)
linux_x64=$(sha x86_64-unknown-linux-gnu)

cat <<EOF
class RustAnything < Formula
  desc "Migrate apps to Rust one piece at a time, checked against recorded behavior"
  homepage "https://rustanything.ai"
  license "MIT"

  on_macos do
    on_arm do
      url "$base/rust-anything-v$version-aarch64-apple-darwin.tar.gz"
      sha256 "$mac_arm"
    end
    on_intel do
      url "$base/rust-anything-v$version-x86_64-apple-darwin.tar.gz"
      sha256 "$mac_x64"
    end
  end

  on_linux do
    on_arm do
      url "$base/rust-anything-v$version-aarch64-unknown-linux-gnu.tar.gz"
      sha256 "$linux_arm"
    end
    on_intel do
      url "$base/rust-anything-v$version-x86_64-unknown-linux-gnu.tar.gz"
      sha256 "$linux_x64"
    end
  end

  def install
    bin.install "rust-anything"
  end

  test do
    assert_match version.to_s, shell_output("#{bin}/rust-anything --version")
  end
end
EOF