Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
dev: use native in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Sep 28, 2024
1 parent 935c223 commit fc2eb52
Show file tree
Hide file tree
Showing 4 changed files with 271 additions and 12 deletions.
53 changes: 42 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@1.81.0
- uses: Swatinem/rust-cache@v2

- name: Set up Scarb
uses: software-mansion/setup-scarb@v1

- name: Build contracts
run: scarb build -p contracts

upload-artifacts:
runs-on: ubuntu-latest
needs: build
steps:
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
Expand All @@ -47,15 +54,44 @@ jobs:
- run: scarb build
- run: scarb test

ef-tests:
ef-tests:

Check failure on line 57 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

yamllint(empty-values)

[new] empty value in block mapping

Check failure on line 57 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

actionlint(syntax-check)

[new] unexpected key "ef-tests" for "job" section. expected one of "concurrency", "container", "continue-on-error", "defaults", "env", "environment", "if", "name", "needs", "outputs", "permissions", "runs-on", "secrets", "services", "steps", "strategy", "timeout-minutes", "uses", "with"
# trunk-ignore(actionlint/runner-label)

Check warning on line 58 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

trunk(ignore-does-nothing)

[new] trunk-ignore(actionlint/runner-label) is not suppressing a lint issue
runs-on: ubuntu-latest-32-cores
needs: build
runs-on: ubuntu-latest-16-cores

Check failure on line 59 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

yamllint(key-duplicates)

[new] duplication of key "runs-on" in mapping

Check failure on line 59 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

actionlint(syntax-check)

[new] key "runs-on" is duplicated in "tests-unit" job. previously defined at line:48,col:5
needs: [build]
steps:

Check failure on line 61 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

yamllint(key-duplicates)

[new] duplication of key "steps" in mapping

Check failure on line 61 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

actionlint(syntax-check)

[new] key "steps" is duplicated in "tests-unit" job. previously defined at line:49,col:5
- name: Checkout code
uses: actions/checkout@v4

- name: Cache cairo-native setup
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
./libcairo_native_runtime.a
key: ${{ runner.os }}-cairo-native-${{ hashFiles('**/Cargo.lock', 'scripts/setup_cairo_native.sh') }}

- name: Make setup script executable
run: chmod +x ./scripts/setup_cairo_native.sh

- name: Setup Cairo Native
run: sudo ./scripts/setup_cairo_native.sh

- name: Set Environment Variables
run: |
echo "MLIR_SYS_190_PREFIX=/usr/lib/llvm-19/" >> $GITHUB_ENV
echo "LLVM_SYS_191_PREFIX=/usr/lib/llvm-19/" >> $GITHUB_ENV
echo "TABLEGEN_190_PREFIX=/usr/lib/llvm-19/" >> $GITHUB_ENV
echo "CAIRO_NATIVE_RUNTIME_LIBRARY=$(pwd)/libcairo_native_runtime.a" >> $GITHUB_ENV
- name: Checkout ef-tests
uses: actions/checkout@v4
with:
repository: kkrt-labs/ef-tests
ref: feat/cairo-native

- name: Checkout local skip file
uses: actions/checkout@v4
Expand All @@ -68,11 +104,6 @@ jobs:
- name: Replace the skip files
run: mv skip-file/blockchain-tests-skip.yml blockchain-tests-skip.yml

- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: "true"

- name: Setup
run: |
mkdir -p build/common
Expand All @@ -88,8 +119,8 @@ jobs:
path: ./build/v1

- name: Move Cairo1Helpers
run:
mv build/v1/contracts_Cairo1Helpers.compiled_contract_class.json
run: |
mv build/v1/contracts_Cairo1Helpers.compiled_contract_class.json \
build/common/cairo1_helpers.json
- name: Set up Python
Expand All @@ -100,7 +131,7 @@ jobs:
- name: Run tests
run: |
set -o pipefail
make ef-test-v1 | tee data.txt
make ef-test-v1-native | tee data.txt
set +o pipefail
- name: Retrieve ef-tests execution resources
Expand Down
113 changes: 112 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ concurrency:
cancel-in-progress: true

jobs:

build:
# trunk-ignore(actionlint/runner-label)
runs-on: ubuntu-latest-16-cores
steps:
- uses: actions/checkout@v4
- uses: foundry-rs/setup-snfoundry@v3
- uses: software-mansion/setup-scarb@v1
- run: scarb build

tests:
# trunk-ignore(actionlint/runner-label)
runs-on: ubuntu-latest-16-cores
Expand All @@ -17,5 +27,106 @@ jobs:
- uses: foundry-rs/setup-snfoundry@v3
- uses: software-mansion/setup-scarb@v1
- run: scarb fmt --check
- run: scarb build
- run: scarb test

ef-tests:

Check failure on line 32 in .github/workflows/test.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

yamllint(empty-values)

[new] empty value in block mapping

Check failure on line 32 in .github/workflows/test.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

actionlint(syntax-check)

[new] unexpected key "ef-tests" for "job" section. expected one of "concurrency", "container", "continue-on-error", "defaults", "env", "environment", "if", "name", "needs", "outputs", "permissions", "runs-on", "secrets", "services", "steps", "strategy", "timeout-minutes", "uses", "with"
# trunk-ignore(actionlint/runner-label)

Check warning on line 33 in .github/workflows/test.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

trunk(ignore-does-nothing)

[new] trunk-ignore(actionlint/runner-label) is not suppressing a lint issue
runs-on: ubuntu-latest-16-cores

Check failure on line 34 in .github/workflows/test.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

yamllint(key-duplicates)

[new] duplication of key "runs-on" in mapping

Check failure on line 34 in .github/workflows/test.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

actionlint(syntax-check)

[new] key "runs-on" is duplicated in "tests" job. previously defined at line:24,col:5
needs: [build]
steps:

Check failure on line 36 in .github/workflows/test.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

yamllint(key-duplicates)

[new] duplication of key "steps" in mapping

Check failure on line 36 in .github/workflows/test.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

actionlint(syntax-check)

[new] key "steps" is duplicated in "tests" job. previously defined at line:25,col:5
- name: Checkout code
uses: actions/checkout@v4

- name: Cache cairo-native setup
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
./libcairo_native_runtime.a
key: ${{ runner.os }}-cairo-native-${{ hashFiles('**/Cargo.lock', 'scripts/setup_cairo_native.sh') }}

- name: Make setup script executable
run: chmod +x ./scripts/setup_cairo_native.sh

- name: Setup Cairo Native
run: sudo ./scripts/setup_cairo_native.sh

- name: Set Environment Variables
run: |
echo "MLIR_SYS_190_PREFIX=/usr/lib/llvm-19/" >> $GITHUB_ENV
echo "LLVM_SYS_191_PREFIX=/usr/lib/llvm-19/" >> $GITHUB_ENV
echo "TABLEGEN_190_PREFIX=/usr/lib/llvm-19/" >> $GITHUB_ENV
echo "CAIRO_NATIVE_RUNTIME_LIBRARY=$(pwd)/libcairo_native_runtime.a" >> $GITHUB_ENV
- name: Checkout ef-tests
uses: actions/checkout@v4
with:
repository: kkrt-labs/ef-tests
ref: feat/cairo-native

- name: Checkout local skip file
uses: actions/checkout@v4
with:
sparse-checkout: |
blockchain-tests-skip.yml
sparse-checkout-cone-mode: false
path: skip-file

- name: Replace the skip files
run: mv skip-file/blockchain-tests-skip.yml blockchain-tests-skip.yml

- name: Setup
run: |
mkdir -p build/common
make setup setup-kakarot-v0
- name: Install nextest
uses: taiki-e/install-action@nextest

- name: Download Kakarot-SSJ build artifacts in v1
uses: actions/download-artifact@v3
with:
name: kakarot-ssj-build
path: ./build/v1

- name: Move Cairo1Helpers
run: |
mv build/v1/contracts_Cairo1Helpers.compiled_contract_class.json \
build/common/cairo1_helpers.json
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.10.14

- name: Run tests
run: |
set -o pipefail
make ef-test-v1-native | tee data.txt
set +o pipefail
- name: Retrieve ef-tests execution resources
run: python scripts/compute_resources.py
env:
KAKAROT_VERSION: v1

- name: Upload resources
uses: actions/upload-artifact@v3
with:
path: resources
name: resources

- name: Generate blockchain-tests-skip.yml file
if: github.event_name == 'workflow_dispatch'
run: make generate-skip-file

- name: Upload skip file
if: github.event_name == 'workflow_dispatch'
uses: actions/upload-artifact@v3
with:
path: blockchain-tests-skip.yml
name: blockchain-tests-skip
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ target
node_modules/
*.snfoundry_cache
cache/

scripts/libcairo_native_runtime.a
115 changes: 115 additions & 0 deletions scripts/setup_cairo_native.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/bash

Check failure on line 1 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shfmt

Incorrect formatting, autoformat by running 'trunk fmt'

install_essential_deps_linux() {
apt-get update -y
apt-get install -y \
curl \
jq \
ripgrep \
wget \
ca-certificates \
gnupg \
git
}

setup_llvm_deps() {
case "$(uname)" in
Darwin)
brew update
brew install llvm@19

LIBRARY_PATH=/opt/homebrew/lib
MLIR_SYS_190_PREFIX="$(brew --prefix llvm@19)"
LLVM_SYS_191_PREFIX="$MLIR_SYS_190_PREFIX"

Check notice on line 23 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.
TABLEGEN_190_PREFIX="$MLIR_SYS_190_PREFIX"

Check notice on line 24 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.

export LIBRARY_PATH
export MLIR_SYS_190_PREFIX
export LLVM_SYS_191_PREFIX
export TABLEGEN_190_PREFIX
;;
Linux)
export DEBIAN_FRONTEND=noninteractive
export TZ=America/New_York

CODENAME=$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)

Check notice on line 35 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2312)

[new] Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
[ -z "$CODENAME" ] && { echo "Error: Unable to determine OS codename"; exit 1; }

Check notice on line 36 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2292)

[new] Prefer [[ ]] over [ ] for tests in Bash/Ksh.

Check notice on line 36 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.

echo "deb http://apt.llvm.org/$CODENAME/ llvm-toolchain-$CODENAME-19 main" > /etc/apt/sources.list.d/llvm-19.list

Check notice on line 38 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.

Check notice on line 38 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.
echo "deb-src http://apt.llvm.org/$CODENAME/ llvm-toolchain-$CODENAME-19 main" >> /etc/apt/sources.list.d/llvm-19.list

Check notice on line 39 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.

Check notice on line 39 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -

Check notice on line 40 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2312)

[new] Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).

apt-get update && apt-get upgrade -y
apt-get install -y llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools

MLIR_SYS_190_PREFIX=/usr/lib/llvm-19/
LLVM_SYS_191_PREFIX=/usr/lib/llvm-19/
TABLEGEN_190_PREFIX=/usr/lib/llvm-19/

export MLIR_SYS_190_PREFIX
export LLVM_SYS_191_PREFIX
export TABLEGEN_190_PREFIX
;;
*)
echo "Error: Unsupported operating system"
exit 1
;;
esac

# GitHub Actions specific
[ -n "$GITHUB_ACTIONS" ] && {

Check notice on line 60 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2292)

[new] Prefer [[ ]] over [ ] for tests in Bash/Ksh.

Check notice on line 60 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.
echo "MLIR_SYS_190_PREFIX=$MLIR_SYS_190_PREFIX" >> $GITHUB_ENV

Check notice on line 61 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2129)

[new] Consider using { cmd1; cmd2; } >> file instead of individual redirects.

Check notice on line 61 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.

Check notice on line 61 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2086)

[new] Double quote to prevent globbing and word splitting.

Check notice on line 61 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.
echo "LLVM_SYS_191_PREFIX=$LLVM_SYS_191_PREFIX" >> $GITHUB_ENV

Check notice on line 62 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.

Check notice on line 62 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2086)

[new] Double quote to prevent globbing and word splitting.

Check notice on line 62 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.
echo "TABLEGEN_190_PREFIX=$TABLEGEN_190_PREFIX" >> $GITHUB_ENV

Check notice on line 63 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.

Check notice on line 63 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2086)

[new] Double quote to prevent globbing and word splitting.

Check notice on line 63 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.
}
}

install_rust() {
if command -v cargo >/dev/null 2>&1; then
echo "Rust is already installed with cargo available in PATH."
return 0
fi

echo "cargo not found. Installing Rust..."
if ! curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.81.0 --no-modify-path; then

Check notice on line 74 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2312)

[new] Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
echo >&2 "Failed to install Rust. Aborting."
return 1
fi

# shellcheck disable=SC1090
source "$HOME/.cargo/env" || {

Check notice on line 80 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC1091)

[new] Not following: ./.cargo/env: openBinaryFile: does not exist (No such file or directory)

Check notice on line 80 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.
echo >&2 "Failed to source Rust environment. Aborting."
return 1
}

echo "Rust installed successfully."
}

install_cairo_native_runtime() {
install_rust || { echo "Error: Failed to install Rust"; exit 1; }

git clone https://github.com/lambdaclass/cairo_native.git
pushd ./cairo_native || exit 1
make deps
make runtime
popd || exit 1

rm -rf ./cairo_native

export CAIRO_NATIVE_RUNTIME_LIBRARY="$(pwd)/libcairo_native_runtime.a"

Check warning on line 99 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2155)

[new] Declare and assign separately to avoid masking return values.

echo "CAIRO_NATIVE_RUNTIME_LIBRARY=$CAIRO_NATIVE_RUNTIME_LIBRARY"

Check notice on line 101 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.

[ -n "$GITHUB_ACTIONS" ] && echo "CAIRO_NATIVE_RUNTIME_LIBRARY=$CAIRO_NATIVE_RUNTIME_LIBRARY" >> $GITHUB_ENV

Check notice on line 103 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2292)

[new] Prefer [[ ]] over [ ] for tests in Bash/Ksh.

Check notice on line 103 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.

Check notice on line 103 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.

Check notice on line 103 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2086)

[new] Double quote to prevent globbing and word splitting.

Check notice on line 103 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2250)

[new] Prefer putting braces around variable references even when not strictly required.
}

main() {
[ "$(uname)" = "Linux" ] && install_essential_deps_linux

Check notice on line 107 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2292)

[new] Prefer [[ ]] over [ ] for tests in Bash/Ksh.

Check notice on line 107 in scripts/setup_cairo_native.sh

View workflow job for this annotation

GitHub Actions / Trunk Check

shellcheck(SC2312)

[new] Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).

setup_llvm_deps
install_cairo_native_runtime

echo "LLVM and Cairo native runtime dependencies installed successfully."
}

main "$@"

0 comments on commit fc2eb52

Please sign in to comment.