Skip to content
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

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

avi-starkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.48%. Comparing base (e3165c4) to head (f12b98a).
Report is 816 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@avi-starkware avi-starkware force-pushed the avi/fix-compilation-output-tempdir branch from d0f08ba to 9d3144e Compare December 10, 2024 09:33
@avi-starkware avi-starkware changed the title fix(infra): resolve out_dir usage in starknet_sierra_compile fix(starknet_sierra_compile): resolve out_dir usage Dec 10, 2024
Copy link
Contributor

@Itay-Tsabary-Starkware Itay-Tsabary-Starkware left a 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");

Copy link
Contributor

@Itay-Tsabary-Starkware Itay-Tsabary-Starkware left a 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.");

@avi-starkware avi-starkware force-pushed the avi/fix-compilation-output-tempdir branch from 9d3144e to b5a5c93 Compare December 10, 2024 10:18
Copy link
Contributor Author

@avi-starkware avi-starkware left a 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 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

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() 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?

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?

@avi-starkware avi-starkware force-pushed the avi/fix-compilation-output-tempdir branch from b5a5c93 to 822895c Compare December 10, 2024 10:21
Copy link
Contributor

@Itay-Tsabary-Starkware Itay-Tsabary-Starkware left a 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 🫡

@avi-starkware avi-starkware force-pushed the avi/fix-compilation-output-tempdir branch from 822895c to 62961e6 Compare December 10, 2024 11:02
Copy link
Contributor Author

@avi-starkware avi-starkware left a 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.

Copy link
Contributor

@Itay-Tsabary-Starkware Itay-Tsabary-Starkware left a 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:

  1. create a rust temp dir here (tempdir())
  2. create the output path with .join("output.so")

This has the added benefits of:

  1. It maintains the temp dir handle exactly for as needed: the scope of this function.
  2. Multiple / concurrent invocations should not interfere with each other
  3. Resistent to the OS cleaning /tmp in the background
  4. Removes the need for other functions.

WDYT?

Code quote:

let output_file_path = compilation_output_file_path();

@avi-starkware avi-starkware force-pushed the avi/fix-compilation-output-tempdir branch from 62961e6 to a901bae Compare December 10, 2024 11:42
Copy link
Contributor Author

@avi-starkware avi-starkware left a 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:

  1. create a rust temp dir here (tempdir())
  2. create the output path with .join("output.so")

This has the added benefits of:

  1. It maintains the temp dir handle exactly for as needed: the scope of this function.
  2. Multiple / concurrent invocations should not interfere with each other
  3. Resistent to the OS cleaning /tmp in the background
  4. 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, as compilation_output_dir() is used only once, by compilation_output_file_path().

Done.

Copy link
Contributor

@Itay-Tsabary-Starkware Itay-Tsabary-Starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 2 of 5 files at r1, 1 of 3 files at r2, 2 of 2 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ArniStarkware)

@avi-starkware avi-starkware force-pushed the avi/fix-compilation-output-tempdir branch from a901bae to a6259bb Compare December 10, 2024 13:31
Copy link
Contributor

@ArniStarkware ArniStarkware left a 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: :shipit: complete! all files reviewed, all discussions resolved (waiting on @avi-starkware)

@avi-starkware avi-starkware force-pushed the avi/fix-compilation-output-tempdir branch from a6259bb to f12b98a Compare December 11, 2024 12:03
@avi-starkware avi-starkware merged commit f72a998 into main Dec 11, 2024
11 checks passed
@avi-starkware avi-starkware deleted the avi/fix-compilation-output-tempdir branch December 11, 2024 12:32
@github-actions github-actions bot locked and limited conversation to collaborators Dec 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants