-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(starknet_sierra_compile): resolve out_dir usage #2616
Conversation
2a1334c
to
d0f08ba
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2616 +/- ##
==========================================
- Coverage 40.10% 0.48% -39.62%
==========================================
Files 26 98 +72
Lines 1895 13365 +11470
Branches 1895 13365 +11470
==========================================
- Hits 760 65 -695
- Misses 1100 13293 +12193
+ Partials 35 7 -28 ☔ View full report in Codecov by Sentry. |
d0f08ba
to
9d3144e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 5 files reviewed, 3 unresolved discussions (waiting on @ArniStarkware and @avi-starkware)
crates/starknet_sierra_compile/build.rs
line 51 at r1 (raw file):
// Create a directory to store the compiled outputs. let compiled_output_dir = compilation_output_dir(out_dir()); std::fs::create_dir_all(&compiled_output_dir).expect("Failed to create the output directory.");
Please see comment below 🙏
Code quote:
std::fs::create_dir_all(&compiled_output_dir).expect("Failed to create the output directory.");
crates/starknet_sierra_compile/src/paths.rs
line 28 at r1 (raw file):
#[cfg(feature = "cairo_native")] pub fn compilation_output_file_path(out_dir: std::path::PathBuf) -> String { compilation_output_dir(out_dir).join("output.so").to_str().unwrap().into()
I'm slightly confused:
I thought that out_dir()
points to the outputs of the build script, namely the native compiler executable.
out_dir()
example: target/debug/build/starknet_sierra_compile-e679b05b01eef89a
I also thought that during the build process, the binaries are moved from out_dir()
to target/debug/shared_executables
Why does the code require out_dir()
to invoke the executables and to access their results? I would have expected it to rely on target/debug/shared_executables
for that.
Am I missing something?
Code quote:
compilation_output_dir(out_dir).join("output.so").to_str().unwrap().into()
crates/starknet_sierra_compile/src/command_line_compiler.rs
line 71 at r1 (raw file):
let output_directory = compilation_output_dir(out_dir()); std::fs::create_dir_all(&output_directory) .expect("Failed to create native compilation output directory");
WDYT about moving this into compilation_output_dir(...)
?
Code quote:
std::fs::create_dir_all(&output_directory)
.expect("Failed to create native compilation output directory");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 5 files reviewed, 4 unresolved discussions (waiting on @ArniStarkware and @avi-starkware)
crates/starknet_sierra_compile/build.rs
line 109 at r1 (raw file):
.args([post_install_file_path.as_os_str(), binary_path.as_os_str()]) .status() .expect("Failed to perform mv command.");
Using this pr to point at another issue:
I think that this mv
command is the culprit that re-triggers the build process -- the executable is removed from the out_dir()
, triggering the println!("cargo:rerun-if-changed={:?}", binary_path);
invocation condition.
Could we please change this to cp
for the meanwhile, and add a todo to further investigate / design a more suited mechanim?
@noaov1 @giladchase @dan-starkware @dorimedini-starkware FYI
Code quote:
let move_command_status = Command::new("mv")
.args([post_install_file_path.as_os_str(), binary_path.as_os_str()])
.status()
.expect("Failed to perform mv command.");
9d3144e
to
b5a5c93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 5 files reviewed, 4 unresolved discussions (waiting on @ArniStarkware, @dan-starkware, @dorimedini-starkware, @giladchase, @Itay-Tsabary-Starkware, and @noaov1)
crates/starknet_sierra_compile/build.rs
line 51 at r1 (raw file):
Previously, Itay-Tsabary-Starkware wrote…
Please see comment below 🙏
Done.
crates/starknet_sierra_compile/build.rs
line 109 at r1 (raw file):
Previously, Itay-Tsabary-Starkware wrote…
Using this pr to point at another issue:
I think that thismv
command is the culprit that re-triggers the build process -- the executable is removed from theout_dir()
, triggering theprintln!("cargo:rerun-if-changed={:?}", binary_path);
invocation condition.Could we please change this to
cp
for the meanwhile, and add a todo to further investigate / design a more suited mechanim?@noaov1 @giladchase @dan-starkware @dorimedini-starkware FYI
I don't think that is the issue. I think I resolved the re-triggering of the build process. The culprit was REQUIRED_CAIRO_NATIVE_VERSION
. It held the wrong version, so re-installation was always required. Now, rebuilding the crate after a successful build takes less than 1 second.
crates/starknet_sierra_compile/src/command_line_compiler.rs
line 71 at r1 (raw file):
Previously, Itay-Tsabary-Starkware wrote…
WDYT about moving this into
compilation_output_dir(...)
?
Done.
crates/starknet_sierra_compile/src/paths.rs
line 28 at r1 (raw file):
Previously, Itay-Tsabary-Starkware wrote…
I'm slightly confused:
I thought that
out_dir()
points to the outputs of the build script, namely the native compiler executable.
out_dir()
example:target/debug/build/starknet_sierra_compile-e679b05b01eef89a
I also thought that during the build process, the binaries are moved from
out_dir()
totarget/debug/shared_executables
Why does the code require
out_dir()
to invoke the executables and to access their results? I would have expected it to rely ontarget/debug/shared_executables
for that.Am I missing something?
This is just a path to put the output of sierra -> native compilation in. Not the path to the binary of the compiler itself.
Should I change this path to /tmp
?
b5a5c93
to
822895c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 5 files reviewed, 1 unresolved discussion (waiting on @ArniStarkware and @avi-starkware)
crates/starknet_sierra_compile/build.rs
line 109 at r1 (raw file):
Previously, avi-starkware wrote…
I don't think that is the issue. I think I resolved the re-triggering of the build process. The culprit was
REQUIRED_CAIRO_NATIVE_VERSION
. It held the wrong version, so re-installation was always required. Now, rebuilding the crate after a successful build takes less than 1 second.
👑
crates/starknet_sierra_compile/src/paths.rs
line 28 at r1 (raw file):
Previously, avi-starkware wrote…
This is just a path to put the output of sierra -> native compilation in. Not the path to the binary of the compiler itself.
Should I change this path to/tmp
?
Yes, please do 🫡
822895c
to
62961e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 5 files reviewed, 1 unresolved discussion (waiting on @ArniStarkware and @Itay-Tsabary-Starkware)
crates/starknet_sierra_compile/src/paths.rs
line 28 at r1 (raw file):
Previously, Itay-Tsabary-Starkware wrote…
Yes, please do 🫡
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 5 files reviewed, 2 unresolved discussions (waiting on @ArniStarkware and @avi-starkware)
crates/starknet_sierra_compile/src/paths.rs
line 28 at r1 (raw file):
Previously, avi-starkware wrote…
Done.
Please see the suggestion above. If you find it appealing, then you can delete both of these functions.
If not, regardless of other changes, I suggest unifying them into a single function, as compilation_output_dir()
is used only once, by compilation_output_file_path()
.
crates/starknet_sierra_compile/src/command_line_compiler.rs
line 69 at r3 (raw file):
) -> Result<AotContractExecutor, CompilationUtilError> { let compiler_binary_path = &self.path_to_starknet_native_compile_binary; let output_file_path = compilation_output_file_path();
Suggestion:
- create a rust temp dir here (
tempdir()
) - create the output path with
.join("output.so")
This has the added benefits of:
- It maintains the temp dir handle exactly for as needed: the scope of this function.
- Multiple / concurrent invocations should not interfere with each other
- Resistent to the OS cleaning
/tmp
in the background - Removes the need for other functions.
WDYT?
Code quote:
let output_file_path = compilation_output_file_path();
62961e6
to
a901bae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 5 files reviewed, 2 unresolved discussions (waiting on @ArniStarkware and @Itay-Tsabary-Starkware)
crates/starknet_sierra_compile/src/command_line_compiler.rs
line 69 at r3 (raw file):
Previously, Itay-Tsabary-Starkware wrote…
Suggestion:
- create a rust temp dir here (
tempdir()
)- create the output path with
.join("output.so")
This has the added benefits of:
- It maintains the temp dir handle exactly for as needed: the scope of this function.
- Multiple / concurrent invocations should not interfere with each other
- Resistent to the OS cleaning
/tmp
in the background- Removes the need for other functions.
WDYT?
Done.
crates/starknet_sierra_compile/src/paths.rs
line 28 at r1 (raw file):
Previously, Itay-Tsabary-Starkware wrote…
Please see the suggestion above. If you find it appealing, then you can delete both of these functions.
If not, regardless of other changes, I suggest unifying them into a single function, ascompilation_output_dir()
is used only once, bycompilation_output_file_path()
.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 5 files at r1, 1 of 3 files at r2, 2 of 2 files at r4, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @ArniStarkware)
a901bae
to
a6259bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 5 files at r1, 2 of 2 files at r4, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @avi-starkware)
a6259bb
to
f12b98a
Compare
No description provided.