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

Suggest adding no_main for error[E0601] #1113

Merged
merged 16 commits into from
May 17, 2023
Merged

Conversation

ascjones
Copy link
Collaborator

@ascjones ascjones commented May 15, 2023

Since #1076, no_main is now required. This PR adds a suggestion in case of the error error[E0601]: main` function not found in crate...

This is the result:
image

Note that the suggestion must appear before the compiler error because we can't know for sure how many lines the error message will encompass, so we just print it first.

Introduces duct which allows for easily building command expressions and working with capturing the stdout and stderr.

Maintaing the progress bar

An earlier iteration was using BufReader::lines to read the captured stderr and check for the error code for the missing main function. However this came with the downside of the familiar progress bar (see below) not being displayed.

image

I have been able to get that to work again with some hacking. The result involves reading the reader one byte at a time and redirecting that straight to stderr, while maintaining a small buffer to check for the known error. I am aware that this is not the most efficient way, but it was the only way to get the progress bar displaying as it does when not capturing stderr.

crates/build/src/lib.rs Outdated Show resolved Hide resolved
Co-authored-by: Michael Müller <[email protected]>
@cmichi
Copy link
Collaborator

cmichi commented May 16, 2023

As discussed via dm, let's omit the tail end of the error output and exit like this:

$ cargo contract build
 [1/*] Building cargo project
   Compiling flipper v4.2.0 (/private/var/folders/s5/5gcp8ck95k39z006fj059_0c0000gn/T/cargo-contract_zJEp2z)

Exited with error: [E0601]
Your contract must be annotated with the `no_main` attribute.

Examples how to do this:
  - #![cfg_attr(not(feature = "std"), no_std, no_main)]
  - #[no_main]

(with the last part in red)

@ascjones
Copy link
Collaborator Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants