-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
29453b0
commit ced58fb
Showing
10 changed files
with
80 additions
and
36 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
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,63 @@ | ||
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/"); | ||
println!("cargo::rerun-if-changed={}", runtime_expected_path.to_str().unwrap()); | ||
println!("cargo::rerun-if-env-changed={RUNTIME_LIBRARY}"); | ||
} | ||
|
||
fn main() { | ||
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
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