-
Notifications
You must be signed in to change notification settings - Fork 45
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
feat: build command to build optimized wasm binaries #226
Conversation
While this PR is ready to be tested, as mentioned relies on an unreleased branch of Furthermore, wanted to add profiles to |
This is really interesting and definitely something I've been wanting explore. A couple things for us to consider:
We should definitely keep exploring this though. (Related stellar/soroban-docs#205) |
It deploys and invokes a contract against the RPC server
Added `ctor` as a dependency so that a function to build is triggered before any tests. This doesn't seem to slow things down if the the test contracts aren't updated. Also made binaryen a feature since the C++ building slowed things down and seemed to break rust analyzer. Reorganized the tests so that a singe test binary is built instead of individual ones.
Also overwrite options in release profile back to defaults for soroban-cli
ef51950
to
3ecfc20
Compare
Also aptly, it just failed CI since nightly wasn't installed, so just made it a feature and make a separate test for it. |
I think if we can use the Before we commit to adding a The reason I'm concerned about our use of nightly:
For those reasons we have motivation to get off nightly, or to find another way to provide the same optimizations without needing nightly. Getting developers to use That all said, if we can't get rid of nightly, a Definitely interested in everyones thoughts on this. (cc @graydon I would be very interested in picking your brain about alternative ways we can achieve the same panic_immediate_abort optimizations without nightly, and/or if you think my concerns about nightly are unwarranted.) |
@leighmcculloch I'm not super worried about users using nightly for their production wasm builds. It's obviously not ideal, and I think we should make it clear what users are trading off (size vs. stability) but:
In summary: I don't think it's something we need to lose sleep over users using, and they're probably going to do so by choice whether or not we pave the path for them / make it simple / build it into a command. I would recommend we make it an option they have to choose, and maybe even default to stable, because there is a tradeoff here and users might wish to play it super safe. Same with a variety of codegen options! You can get smaller contracts if you turn off overflow checks. Some users will. Should we make it the default? Probably not. But we can't stop them, or even really make it especially hard. In terms of whether we can achieve the same panic-shrinking without building std with
Personally I can .. also maybe live with these, especially if the nightly concern is strongly felt. Maybe with the recent SDK-side changes to using |
This is my concern.
This is exactly my concern. When using nightly a developer might be using the release from yesterday that hasn't had time to "simmer" where bugs are found quickly and patched before the release makes it to beta/stable.
I don't want to avoid the panic macro. As you said we went there, and it wasn't great. What I'm curious about is if we can find another way to reduce the code generated by panic without requiring nightly. I agree whatever we do, we probably shouldn't require nightly, and also, we shouldn't prevent people from using it. I'll think about this some more on how we can present these options well in docs, etc, and if we can do anything differently. |
Closing this, because we now have |
What
This PR adds a
build
subcommand that aims to hide the complexity from new users. It usesclap-cargo-extra
which provides most of the cargo args that users are familiar with. Currently this PR relies on an unreleased version of the crate (I'm the author).Added to the usual features is an optimize flag, which will aim to run the nightly version of cargo if it is installed. It also applies wasm-opt for size on the generated cargo binaries adding
_opt.wasm
suffix.wasm-opt
is provided from a dependencybinaryen
, which is added as optional, since the C++ building slowed things down and seemed to break rust-analyzer. Furthermore it seems to be an old version of binaryen and so the optimized binary generated differed from the most recent release. The crate looks unmaintained, however, a fork and a solution like https://www.riff.sh/, might help solve the issues above.ctor
is added as a new dependency so that a function to build is triggered before any tests. This doesn't seem to slow things down if the the test contracts aren't updated.Lastly, the tests are reorganized so that a singe test binary is built instead of individual ones. As mentioned here.
Why
Currently the build step for optimized contract binaries is awkward for new devs and most examples use a Makefile to simplify this. It also requires that you have external binaries installed.
Known limitations
Currently depends on #222 to be merged.
Currently
clap-cargo-extra
doesn't handle profiles, however, this could be addressed in a future PR.