summarylogtreecommitdiffstats
path: root/update-version.sh
blob: 163abf3cf4a34dca06c71562a352400debaa4611 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash

# Get the releases using GitHub API
RELEASES=$(curl -s "https://api.github.com/repos/starkware-libs/cairo/releases/latest")
VERSION=$(echo $RELEASES | jq .tag_name | sed 's/"//g')
DOWNLOAD_DIR="https://github.com/starkware-libs/cairo/archive/refs/tags/$VERSION.tar.gz"

curl -sLOJ $DOWNLOAD_DIR

SHA256_HASH=$(sha256sum "cairo-${VERSION#v}.tar.gz" | awk '{print $1}')
rm cairo-${VERSION#v}.tar.gz

VERSION=($(echo $VERSION | grep -oE '^[^-]+|-.*'))

cat >"PKGBUILD" <<EOL
pkgname="cairo-lang"
pkgver=${VERSION[0]#v}
release="${VERSION[1]}"
pkgdesc="Cairo language installation"
pkgrel="1"
arch=("x86_64")
url="https://cairo-by-example.com/"
license=('APACHE')
depends=("git" "rustup")
source=("$DOWNLOAD_DIR")
sha256sums=("$SHA256_HASH")

prepare() {
	rustup override set stable
	rustup update
}

build() {
	cd "cairo-\$pkgver\$release"
	cargo build --all --release --manifest-path ./Cargo.toml
}

package() {
	mkdir -p \$pkgdir/usr/bin/ \$pkgdir/usr/lib/

	mv cairo-\$pkgver\$release/corelib/ \$pkgdir/usr/lib/
	
	pkgs=("cairo-run" "cairo-compile" "cairo-format" "cairo-language-server" "cairo-test" "sierra-compile" "starknet-compile" "starknet-sierra-compile")
	
	for pkg in \${pkgs[@]}; do
		mv cairo-\$pkgver\$release/target/release/\$pkg \$pkgdir/usr/bin/
	done
	
	add_to_config
}

add_to_config() {
	declare -A shells=( ["bash"]=".bashrc" ["fish"]=".config/fish/config.fish" ["zsh"]=".zshrc")

	echo "export CARGO_MANIFEST_DIR=\"/usr/bin/corelib/\"" >> /home/\$USER/\${shells[\$(basename \$(echo \$SHELL))]}
}
EOL

cat >".SRCINFO" <<EOL
pkgbase = cairo-lang
  pkgdesc = Cairo language installation
  pkgver = ${VERSION[0]#v}
  pkgrel = 1
  url = https://cairo-by-example.com/
  arch = x86_64
  license = APACHE
  depends = git
  depends = rustup
  source = $DOWNLOAD_DIR
  sha256sums = $SHA256_HASH
pkgname = cairo-lang
EOL