Skip to content
This repository has been archived by the owner on Sep 18, 2020. It is now read-only.

Compile contracts using solcjs or solc #174

Closed
wants to merge 19 commits into from

Conversation

AyushyaChitransh
Copy link
Contributor

@AyushyaChitransh AyushyaChitransh commented May 7, 2018

This PR closes #168 and closes #169 and it also improves #170

  • First of all, try compiling with solc
  • If solc is not found, try using solcjs.
  • Panic when neither of compilation tools are available

@AyushyaChitransh
Copy link
Contributor Author

@snd or @debris Can you please review this PR. It is ready from my side.

@snd
Copy link
Contributor

snd commented May 14, 2018

i did not work last week. will look at it soon

Copy link
Contributor

@snd snd left a comment

Choose a reason for hiding this comment

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

thanks for the contribution!

it would be great if you could try simplifying the deeply nested matches and if's. since most branches end with a panic! this could be written in an early-return (or in this case "early-panic") style which would make it more readable

bridge/build.rs Outdated
} else {
panic!("an error occurred when trying to spawn `solc`: {}", err);
}
}
}
}
fn get_file_name(path: DirEntry) -> String {
Copy link
Contributor

Choose a reason for hiding this comment

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

i think it would be cleaner to inline this above

@AyushyaChitransh
Copy link
Contributor Author

@snd early panic cannot be possible. We are panicking only if solc and solcjs both are not available. Or if any process fails unexpectedly, example:

  • panic if !exit_status.success for solcjs. This means solcjs could not compile successfully on line 30

For any confusion regarding any panics, feel free to raise doubts. I'll be happy to update them with comments or try resolving those doubts.

Copy link
Contributor

@debris debris left a comment

Choose a reason for hiding this comment

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

This function is still very complex. Can you simplify it further by separating functions compile_using_solc and compile_using_solcjs. Also removing those nested matches and if/else statements would help a lot with code readibility. It's difficult to find the and of the block now :)

bridge/build.rs Outdated
path.unwrap().file_name().into_string().expect(
"error: the first argument is not a file\
system path representable in UTF-8.",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

please use Path instead. e.g. Path::new(prepend).join(path.unwrap().file_name()) or maybe even path.unwrap().path()

bridge/build.rs Outdated
println!("Removed old files");
}
Err(err) => {
println!("Files not removed: {}", err);
Copy link
Contributor

Choose a reason for hiding this comment

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

using println! for debugging is usually a bad pattern. Especially in build.rs

@AyushyaChitransh
Copy link
Contributor Author

Tests are failing now due to timeout. Is this because we are using party version 1.10? Because previously, similar tests were working on using parity version 1.9.7

@snd
Copy link
Contributor

snd commented May 22, 2018

seems like tests are failing because the code is not formatted with rustfmt. could you run cargo fmt, add, commit and try again? we've setup CI to enforce the codebase is always formatted with cargo fmt

@AyushyaChitransh
Copy link
Contributor Author

I resolved the formatting of this file, but the build is still failing.

@snd
Copy link
Contributor

snd commented Jun 6, 2018

i think it makes sense to move this into a separate crate since the same functionality is also present in https://github.com/paritytech/sol-rs.

@snd
Copy link
Contributor

snd commented Jun 6, 2018

i'm going to create a small crate that makes it easy for any project to interact with / compile sol files with solc and/or solcjs so the bridge, sol-rs and other projects don't have to reimplement it over and over

@snd
Copy link
Contributor

snd commented Jun 7, 2018

started working on said crate over here https://github.com/snd/rust_solc/.
it will use the JSON I/O format that's common to solc/solcjs.
this will enable compiling solidity from rust using solc/solcjs without touching the filesystem.
i think this is overall a cleaner and more reusable solution.
it also opens up things like openethereum/sol-rs#13 without touching the filesystem

@snd
Copy link
Contributor

snd commented Jun 12, 2018

wasn't able to get the JSON I/O to work just yet because it's broken on solcjs ethereum/solc-js#126.

i got https://github.com/snd/rust_solc to work with file I/O though.

we should now be able to replace the solc compilation code in this PR by a simple

solc::compile_dir("../contracts", "../compiled_contracts").unwrap();

@AyushyaChitransh do you want to modify this PR accordingly or open another PR? let me know. otherwise i'll do it in another PR

@AyushyaChitransh
Copy link
Contributor Author

AyushyaChitransh commented Jun 13, 2018

Let me rephrase what I understood:

You are suggesting we use rust_solc. And on using that, we would not require to use solc or solcjs.

If this is the case, lets have another PR from you and close this one.

@snd
Copy link
Contributor

snd commented Jun 18, 2018

You are suggesting we use rust_solc. And on using that, we would not require to use solc or solcjs.

rust_solc is just a crate that shells out to solc or solcjs

If this is the case, lets have another PR from you and close this one.

sounds good

@AyushyaChitransh
Copy link
Contributor Author

Am still unable to compile. Facing solc errors.

thread 'main' panicked at 'solc --version failed to run. run it yourself to verify. file an issue if this persists: Os { code: 2, kind: NotFound, message: "No such file or directory" }', bridge/build.rs:36:69

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.

Using solcjs instead of solc improve error message when solc is not installed
3 participants