Skip to content

Commit

Permalink
fix: Change path for mv libcairo_native
Browse files Browse the repository at this point in the history
Commit cfe157b in
rdr/add-native-runtime added a WORKDIR /app for the ci dockerfile, so
the path where libcairo_native_runtime.a is moved to had to be updated

- Adds argument to scripts/dependencies.sh to choose where to mv
  libcairo_native_runtime.a

- Updated scripts/install_build_tools.sh and build_native_in_docker.sh
  to handle new argument and pass it on in subsequent scripts/commands.

- Adds scripts/boostrap.sh for scripts/sequencer-ci.Dockerfile to run at
  its entrypoint to copy the library to sequencer/crates/blockifier/
  • Loading branch information
PearsonWhite committed Oct 15, 2024
1 parent fc9b733 commit abdd72e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
1 change: 0 additions & 1 deletion .github/workflows/committer_cli_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jobs:
runs-on: starkware-ubuntu-20-04-medium
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/bootstrap

# Commit hash on pull request event would be the head commit of the branch.
- name: Get commit hash prefix for PR update
Expand Down
3 changes: 2 additions & 1 deletion build_native_in_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ set -e

docker_image_name=sequencer-ci

SEQUENCER_DIR=${PWD}
(
cd scripts
docker build . -t ${docker_image_name} --file ${docker_image_name}.Dockerfile
docker build . -t ${docker_image_name} --file ${docker_image_name}.Dockerfile --build-arg SEQUENCER_DIR=${SEQUENCER_DIR}
)

docker run \
Expand Down
29 changes: 29 additions & 0 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/env bash

# Script for the entry point of sequencer-ci.Dockerfile.

# Set SEQUENCER_DIR as first argument.
[ "$#" -gt 0 ] || (echo "Path to sequencer repo required as an argument, $# arguments provided" ; exit 1)
SEQUENCER_DIR="$1"
remaining_args=${@:2}

# Building the docker image builds libcairo_native_runtime.a, but the sequencer repo may not exist (on the docker image).
# When running the github actions CI, `build_native_in_docker.sh` is called and mounts home.
# `-v "${HOME}:${HOME}"` mounts `/home/runner/work/sequencer`
# In `.github/workflows/committer_cli_push.yml`, `actions/checkout@v4` pulls the repo under home.
# Thus, when running docker, we need to grab the lib from the build step and move it under our new mounted directory.
# Final destination for `libcairo_native_runtime.a` committer_cli_push is `/home/runner/work/sequencer/sequencer/crates/blockifier/libcairo_native_runtime.a`.
function copy_cairo_native_lib() {
SEQUENCER_DIR="$1"
# Set TARGET_LIB_DIR as first argument, or by default the pwd.
echo "Copying cairo native runtime library to blockifier crate"
echo "SEQUENCER_DIR: ${SEQUENCER_DIR}"
set -x
cp /cairo_native/libcairo_native_runtime.a "${SEQUENCER_DIR}/crates/blockifier/libcairo_native_runtime.a"
{ set +x; } 2>/dev/null
}

copy_cairo_native_lib "${SEQUENCER_DIR}"

# Run the passed in command using remaining arguments
$remaining_args
13 changes: 11 additions & 2 deletions scripts/dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function setup_llvm_deps() {
}

function compile_cairo_native_runtime() {
TARGET_LIB_DIR="$1"
# First we need to make sure Cargo exists
if command -v cargo >/dev/null 2>&1; then
echo "Rust is already installed with cargo available in PATH."
Expand All @@ -70,16 +71,24 @@ function compile_cairo_native_runtime() {
cargo build -p cairo-native-runtime --release --all-features --quiet
popd || exit 1

mv ./cairo_native/target/release/libcairo_native_runtime.a ./crates/blockifier/libcairo_native_runtime.a
mv ./cairo_native/target/release/libcairo_native_runtime.a ${LIBCAIRO_NATIVE_DIR}/libcairo_native_runtime.a
rm -rf ./cairo_native
}

function main() {
# Set LIBCAIRO_NATIVE_DIR as first argument.
# Assumes this script is in `sequencer/scripts/`
# By default, copy to `sequencer/scripts/../crates/blockifier`
# Used in `.github/actions/bootstrap/action.yml` and when calling manually.
THIS_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
DEFAULT_DIR="$THIS_DIR/../crates/blockifier"
LIBCAIRO_NATIVE_DIR=${1:-"$DEFAULT_DIR"}

[ "$(uname)" = "Linux" ] && install_essential_deps_linux
setup_llvm_deps
echo "LLVM dependencies installed successfully."

compile_cairo_native_runtime
compile_cairo_native_runtime "$LIBCAIRO_NATIVE_DIR"
echo "Cairo Native runtime compiled successfully."
}

Expand Down
4 changes: 3 additions & 1 deletion scripts/install_build_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
set -e

[[ ${UID} == "0" ]] || SUDO="sudo"
# Set LIBCAIRO_NATIVE_DIR as first argument, or by default the pwd.
LIBCAIRO_NATIVE_DIR=${1:-$(pwd)}

function install_common_packages() {
$SUDO bash -c '
Expand Down Expand Up @@ -52,4 +54,4 @@ install_common_packages
install_pypy &
install_rust &
wait
./dependencies.sh
./dependencies.sh "$LIBCAIRO_NATIVE_DIR"
9 changes: 7 additions & 2 deletions scripts/sequencer-ci.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ FROM ubuntu:20.04
ARG USERNAME=sequencer
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG SEQUENCER_DIR=local
ENV SEQUENCER_DIR=${SEQUENCER_DIR}

RUN apt update && apt install -y sudo

Expand All @@ -12,13 +14,16 @@ RUN echo "%${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/d

USER ${USERNAME}

WORKDIR /app
WORKDIR /cairo_native

ENV RUSTUP_HOME=/var/tmp/rust
ENV CARGO_HOME=${RUSTUP_HOME}
ENV PATH=$PATH:${RUSTUP_HOME}/bin

COPY install_build_tools.sh .
COPY dependencies.sh .
COPY bootstrap.sh .

RUN ./install_build_tools.sh
RUN ./install_build_tools.sh /cairo_native

ENTRYPOINT [ "sh", "-c", "/cairo_native/bootstrap.sh ${SEQUENCER_DIR} $0 $@" ]

0 comments on commit abdd72e

Please sign in to comment.