Skip to content

Commit bdc338d

Browse files
MegaRedHandkariy
authored andcommitted
feat: improve dependency installation experience (lambdaclass#1298)
* Add installation instructions to README * Add compilation step to installation testing * Add script for universal dependency installation * Update changelog * Enable test_install workflow only on main * Update optional dependencies Just having PyEnv and make installed suffices for running `make deps`. I don't think we need to list cairo-lang as a dependency. * Don't compile, only check * Push again * Use swatinem cache * Cache all crates even on failure * Fix debian rust cache * Use manual cache * Test cache * Cache cairo compiler * Add pyenv dependency caching * Cache pip instead of pyenv * Try fixing cache * Use setup-python action * Use ~ instead of ${HOME} * Use manual cache in Debian container * Add some comments * Make cache owned by current user and add logs * Remove python install from script
1 parent a48ee62 commit bdc338d

File tree

8 files changed

+169
-63
lines changed

8 files changed

+169
-63
lines changed

.github/workflows/test_install.yml

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,70 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v3
1919

20-
- if: matrix.os == 'ubuntu-22.04'
21-
name: "Install on ubuntu-22.04"
22-
run: install-scripts/install-ubuntu.sh
20+
- name: Set up Cargo cache
21+
uses: Swatinem/rust-cache@v2
22+
with:
23+
cache-all-crates: 'true'
24+
cache-on-failure: 'true'
25+
cache-directories: ./cairo/target/
2326

24-
- if: matrix.os == 'macos-12'
25-
name: "Install on macos-12"
26-
run: install-scripts/install-macos.sh
27+
# just to cache dependencies
28+
- name: Install python
29+
uses: actions/setup-python@v4
30+
with:
31+
python-version: '3.9'
32+
cache: 'pip'
33+
34+
- name: Install dependencies
35+
run: bash install.sh
36+
37+
- name: Compile project
38+
run: cargo check
2739

2840
install_debian:
2941
name: "Install on debian-11"
3042
runs-on: ubuntu-22.04
3143
container:
3244
image: debian:11
45+
defaults:
46+
run:
47+
shell: bash {0}
3348

3449
steps:
3550
- uses: actions/checkout@v3
3651

37-
- name: "Install on debian-11"
38-
run: install-scripts/install-debian.sh
52+
# we don't use swatinem because rustc isn't installed yet
53+
- name: Cache Rust dependencies
54+
uses: actions/cache@v3
55+
with:
56+
path: |
57+
~/.cargo/
58+
./target/
59+
./cairo/target/
60+
key: ${{ runner.os }}-install-${{ github.sha }}
61+
restore-keys: ${{ runner.os }}-install-
62+
63+
- name: Enable pip cache
64+
run: |
65+
mkdir -p ~/.cache/pip
66+
chown -v -R $USER ~/.cache
67+
chmod -v -R 770 ~/.cache
68+
ls -al ~/
69+
ls -al ~/.cache
70+
71+
# NOTE: we don't use install-python because lsb_release isn't installed
72+
- name: Cache Python dependencies
73+
uses: actions/cache@v3
74+
with:
75+
path: |
76+
~/.cache/pip/wheels
77+
key: ${{ runner.os }}-python-install-${{ github.sha }}
78+
restore-keys: ${{ runner.os }}-python-install-
79+
80+
- name: Install dependencies
81+
run: bash install.sh
82+
83+
- name: Compile project
84+
run: |
85+
. "$HOME/.cargo/env"
86+
cargo check

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
#### Upcoming Changes
44

5+
* feat: add dependency installation script `install.sh` [#1298](https://github.com/lambdaclass/cairo-vm/pull/1298)
6+
57
* fix: specify resolver version 2 in the virtual workspace's manifest [#1311](https://github.com/lambdaclass/cairo-vm/pull/1311)
68

79
* feat: add `lambdaworks-felt` feature to `cairo-vm-cli` [#1308](https://github.com/lambdaclass/cairo-vm/pull/1308)
810

911
* chore: update dependencies, particularly clap 3.2 -> 4.3 [#1309](https://github.com/lambdaclass/cairo-vm/pull/1309)
10-
1112
* this removes dependency on _atty_, that's no longer mantained
1213

1314
* chore: remove unused dependencies [#1307](https://github.com/lambdaclass/cairo-vm/pull/1307)
@@ -23,7 +24,7 @@
2324

2425
* rename github repo from https://github.com/lambdaclass/cairo-rs to https://github.com/lambdaclass/cairo-vm [#1289](https://github.com/lambdaclass/cairo-vm/pull/1289)
2526

26-
* fix(security): avoid OOM crashes when programs jump to very high invalid addresses.
27+
* fix(security): avoid OOM crashes when programs jump to very high invalid addresses [#1285](https://github.com/lambdaclass/cairo-vm/pull/1285)
2728

2829
* fix: add `to_bytes_be` to the felt when `lambdaworks-felt` feature is active [#1290](https://github.com/lambdaclass/cairo-vm/pull/1290)
2930

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,16 @@ cargo-deps:
124124
cargo install --version 0.11.0 wasm-pack
125125

126126
deps: cargo-deps build-cairo-1-compiler
127-
pyenv install -s pypy3.9-7.3.9
127+
pyenv install -s pypy3.9-7.3.9
128128
PYENV_VERSION=pypy3.9-7.3.9 python -m venv cairo-vm-pypy-env
129129
. cairo-vm-pypy-env/bin/activate ; \
130130
pip install -r requirements.txt ; \
131-
pyenv install -s 3.9.15
131+
pyenv install -s 3.9.15
132132
PYENV_VERSION=3.9.15 python -m venv cairo-vm-env
133133
. cairo-vm-env/bin/activate ; \
134134
pip install -r requirements.txt ; \
135135

136136
deps-macos: cargo-deps build-cairo-1-compiler
137-
brew install gmp
138137
arch -x86_64 pyenv install -s pypy3.9-7.3.9
139138
PYENV_VERSION=pypy3.9-7.3.9 python -m venv cairo-vm-pypy-env
140139
. cairo-vm-pypy-env/bin/activate ; \

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ A faster and safer implementation of the Cairo VM in Rust
2727
- [Getting Started](#-getting-started)
2828
- [Dependencies](#dependencies)
2929
- [Usage](#-usage)
30-
- [Running cairo-vm](#running-cairo-vm)
30+
- [Adding cairo-vm as a dependency](#adding-cairo-vm-as-a-dependency)
31+
- [Running cairo-vm from the CLI](#running-cairo-vm-from-cli)
3132
- [Using hints](#using-hints)
3233
- [Running a function in a Cairo program with arguments](#running-a-function-in-a-cairo-program-with-arguments)
3334
- [WebAssembly Demo](#webassembly-demo)
@@ -67,17 +68,23 @@ It's Turing-complete and it was created by [Starkware](https://starkware.co/) as
6768

6869
### Dependencies
6970

70-
**Required**
71+
#### Required
7172

72-
- [Rust 1.66.1](https://www.rust-lang.org/tools/install)
73+
These are needed in order to compile and use the project.
74+
75+
- [Rust 1.69.0 or newer](https://www.rust-lang.org/tools/install)
7376
- Cargo
7477

75-
**Optional**
78+
#### Optional
7679

7780
These dependencies are only necessary in order to run the original VM, compile Cairo programs, and run tests.
7881

79-
- PyEnv with Python 3.9
80-
- cairo-lang
82+
- make
83+
- PyEnv
84+
85+
#### Installation script
86+
87+
You can install all of the required and optional dependencies by running the script `install.sh` while in the repository root.
8188

8289
## 🚀 Usage
8390

install-scripts/install-debian.sh

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ source "$HOME/.cargo/env"
1717
rustc --version
1818

1919
# Install pyenv dependencies
20-
apt-get install -y git make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev
20+
apt-get install -y git make build-essential libssl-dev zlib1g-dev libbz2-dev \
21+
libreadline-dev libsqlite3-dev wget llvm libncurses5-dev libncursesw5-dev \
22+
xz-utils tk-dev libffi-dev liblzma-dev libgmp3-dev
2123

2224
# Install pyenv
2325
curl https://pyenv.run | bash
@@ -28,17 +30,4 @@ eval "$(pyenv init -)"
2830
# Make sure pyenv has been installed correctly
2931
pyenv -v
3032

31-
# Installing python 3.9 with pyenv
32-
pyenv install 3.9
33-
34-
# Setting python 3.9 as the default local version
35-
pyenv local 3.9
36-
37-
# Create and enter a virtual environment
38-
python3.9 -m venv ~/cairo_venv
39-
source ~/cairo_venv/bin/activate
40-
41-
# Install cairo & its dependencies
42-
apt install -y libgmp3-dev
43-
pip3 install -r requirements.txt
44-
33+
make deps

install-scripts/install-macos.sh

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,9 @@ source "$HOME/.cargo/env"
99
rustc --version
1010

1111
# Install pyenv
12-
brew install pyenv
12+
brew install pyenv gmp
1313

1414
# Make sure pyenv has been installed correctly
1515
pyenv -v
1616

17-
# Installing python 3.9 with pyenv
18-
pyenv install 3.9
19-
20-
# Setting python 3.9 as the default local version
21-
pyenv local 3
22-
23-
# Create and enter a virtual environment
24-
python3 -m venv ~/cairo_venv
25-
source ~/cairo_venv/bin/activate
26-
27-
# Install cairo & its dependencies
28-
pip3 install -r requirements.txt
29-
17+
make deps-macos

install-scripts/install-ubuntu.sh

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env bash
22
set -ex
33

4+
PYTHON_VERSION=3.9.15
5+
PYTHON_MINOR_VERSION=${PYTHON_VERSION%.*}
6+
47
sudo apt update -y
58

69
# Install Rust and Cargo
@@ -11,7 +14,9 @@ source "$HOME/.cargo/env"
1114
rustc --version
1215

1316
# Install pyenv dependencies
14-
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev
17+
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
18+
libreadline-dev libsqlite3-dev wget llvm libncurses5-dev libncursesw5-dev \
19+
xz-utils tk-dev libffi-dev liblzma-dev libgmp3-dev
1520

1621
# Install pyenv
1722
curl https://pyenv.run | bash
@@ -23,17 +28,4 @@ eval "$(pyenv init -)"
2328
# Make sure pyenv has been installed correctly
2429
pyenv -v
2530

26-
# Installing python 3.9 with pyenv
27-
pyenv install 3.9.16
28-
29-
# Setting python 3.9 as the default local version
30-
pyenv local 3.9.16
31-
32-
# Create and enter a virtual environment
33-
34-
python3.9 -m venv ~/cairo_venv
35-
source ~/cairo_venv/bin/activate
36-
37-
# Install cairo & its dependencies
38-
sudo apt install -y libgmp3-dev
39-
pip3 install -r requirements.txt
31+
make deps

install.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
3+
# Print an error message and exit with 1
4+
unsupported_os () {
5+
echo "Detected OS ($1) is unsupported."
6+
echo "Please open an issue (PRs welcome ❤️) on:"
7+
echo " https://github.com/lambdaclass/cairo-vm/issues"
8+
echo ""
9+
echo "NOTE: you can still try installing dependencies manually"
10+
echo "If your OS differs from the detected one, you can look \
11+
for the installation script for your OS in the install-scripts folder."
12+
exit 1
13+
}
14+
15+
# Print the detected OS
16+
print_os() {
17+
echo "Detected OS: $1"
18+
}
19+
20+
# Print a message and run the script
21+
run_script() {
22+
echo "Running $1..."
23+
. $1
24+
}
25+
26+
# Detect Linux distro
27+
install_linux() {
28+
# taken from: https://unix.stackexchange.com/a/6348
29+
# tries different methods to detect the Linux distro
30+
if [ -f /etc/os-release ]; then
31+
# freedesktop.org and systemd
32+
. /etc/os-release
33+
OS=$NAME
34+
VER=$VERSION_ID
35+
elif type lsb_release >/dev/null 2>&1; then
36+
# linuxbase.org
37+
OS=$(lsb_release -si)
38+
VER=$(lsb_release -sr)
39+
elif [ -f /etc/lsb-release ]; then
40+
# For some versions of Debian/Ubuntu without lsb_release command
41+
. /etc/lsb-release
42+
OS=$DISTRIB_ID
43+
VER=$DISTRIB_RELEASE
44+
elif [ -f /etc/debian_version ]; then
45+
# Older Debian/Ubuntu/etc.
46+
OS=Debian
47+
VER=$(cat /etc/debian_version)
48+
elif [ -f /etc/SuSe-release ]; then
49+
# Older SuSE/etc.
50+
OS="Old SuSE"
51+
elif [ -f /etc/redhat-release ]; then
52+
# Older Red Hat, CentOS, etc.
53+
OS="Old RedHat"
54+
else
55+
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
56+
OS=$(uname -s)
57+
VER=$(uname -r)
58+
fi
59+
60+
print_os $OS
61+
62+
# NOTE: we don't use $VER for now, but this might change
63+
case "$OS" in
64+
Ubuntu*) run_script "install-scripts/install-ubuntu.sh" ;;
65+
Debian*) run_script "install-scripts/install-debian.sh" ;;
66+
*) unsupported_os "linux: $OS" ;;
67+
esac
68+
}
69+
70+
install_macos() {
71+
print_os "MacOS"
72+
run_script install-scripts/install-macos.sh
73+
}
74+
75+
case "$OSTYPE" in
76+
linux*) install_linux ;;
77+
darwin*) install_macos ;;
78+
msys*|cygwin*) unsupported_os "Windows" ;;
79+
solaris*) unsupported_os "Solaris" ;;
80+
bsd*) unsupported_os "BSD" ;;
81+
*) unsupported_os "unknown: ${OSTYPE}" ;;
82+
esac

0 commit comments

Comments
 (0)