-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(blockifier): compile cairo native runtime (#1242)
* feat: add cairo native runtime installation to dependencies.sh * chore: update .gitignore * chore: preemptevely install Cargo * fix: add sudo to git clone * fix: add WORKDIR to ci dockerfile * fix: runtime is .a and not .so * feat: rework native runtime dependency CI Instead of custom script, swapped for the addition of Cairo Native as a git submodule. The runtime will be compiled once the compilation is succesful. A known caveat of this approach (using build.rs) is that if there is nothing new to compile and the native_runtime.a library won't be recompiled, even if it was deleted or updated. Another caveat is that both the git submodule and Cairo Native dependency need be updated at the same time. We cannot directly set the submodule as a dependency because cairo native is also a workspace (such as this repo) and there cannot be two workspace roots. Co-Authored-By: Pearson White <pearson.white@nethermind.io>
- Loading branch information
1 parent
b20329c
commit fcc6b10
Showing
9 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "crates/blockifier/cairo_native"] | ||
path = crates/blockifier/cairo_native | ||
url = https://github.com/lambdaclass/cairo_native |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::path::PathBuf; | ||
use std::process::Command; | ||
|
||
fn compile_cairo_native_aot_runtime() { | ||
let cairo_native_dir = std::env::current_dir() | ||
.expect("Failed to get current directory") | ||
.join(PathBuf::from("cairo_native")); | ||
|
||
if !cairo_native_dir.exists() || !cairo_native_dir.join(".git").exists() { | ||
panic!( | ||
"It seems git submodule at {} doesn't exist or it is not initialized, please \ | ||
run:\n\ngit submodule update --init --recursive\n", | ||
cairo_native_dir.to_str().unwrap() | ||
); | ||
} | ||
|
||
let runtime_target_dir = cairo_native_dir.join(PathBuf::from("target")); | ||
let status = Command::new("cargo") | ||
.args([ | ||
"build", | ||
"--release", | ||
"-p", | ||
"cairo-native-runtime", | ||
"--message-format=json", | ||
"--target-dir", | ||
runtime_target_dir.to_str().unwrap(), | ||
]) | ||
.current_dir(cairo_native_dir) | ||
.status() | ||
.expect("Failed to execute cargo"); | ||
if !status.success() { | ||
panic!("Building cairo native runtime failed: {status}") | ||
} | ||
|
||
let runtime_target_path = | ||
runtime_target_dir.join(PathBuf::from("release/libcairo_native_runtime.a")); | ||
|
||
const RUNTIME_LIBRARY: &str = "CAIRO_NATIVE_RUNTIME_LIBRARY"; | ||
let runtime_expected_path = { | ||
let expected_path_env = | ||
std::env::var(RUNTIME_LIBRARY).expect("Cairo Native rutime path variable is not set"); | ||
let expected_path = PathBuf::from(&expected_path_env); | ||
|
||
if expected_path.is_absolute() { | ||
expected_path | ||
} else { | ||
std::env::current_dir().expect("Failed to get current directory").join(expected_path) | ||
} | ||
}; | ||
|
||
std::fs::copy(&runtime_target_path, &runtime_expected_path) | ||
.expect("Failed to copy native runtime"); | ||
|
||
println!("cargo::rerun-if-changed=./cairo_native/runtime/"); | ||
// todo(rodrigo): this directive seems to cause the build script to trigger everytime on | ||
// Linux based machines. Investigate the issue further. | ||
println!("cargo::rerun-if-changed={}", runtime_expected_path.to_str().unwrap()); | ||
println!("cargo::rerun-if-env-changed={RUNTIME_LIBRARY}"); | ||
} | ||
|
||
fn main() { | ||
// `CARGO_FEATURE_CAIRO_NATIVE` env var is set by Cargo when compiling with the `cairo_native` | ||
// feature flag. Build instructions are defined behind this condition since they are only | ||
// relevant when using Cairo Native. | ||
if std::env::var("CARGO_FEATURE_CAIRO_NATIVE").is_ok() { | ||
compile_cairo_native_aot_runtime(); | ||
} | ||
} |
Submodule cairo_native
added at
b5769e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters