From 05dafa23e86165d4c0ce642c7c6f3d571722a114 Mon Sep 17 00:00:00 2001 From: Tyler van der Hoeven Date: Tue, 14 Feb 2023 12:59:17 -0500 Subject: [PATCH] Update optimize contracts section (#310) * Update hello-world.mdx * Update hello-world.mdx * don't need to manually install wasm-opt via binaryen * remove the -Z flags --- docs/getting-started/hello-world.mdx | 82 ++++------------------------ 1 file changed, 11 insertions(+), 71 deletions(-) diff --git a/docs/getting-started/hello-world.mdx b/docs/getting-started/hello-world.mdx index 27e76c12..58811252 100644 --- a/docs/getting-started/hello-world.mdx +++ b/docs/getting-started/hello-world.mdx @@ -344,84 +344,24 @@ The following output should appear. ["Hello", "friend"] ``` -[Write a Contract]: #write-a-contract -[Deploy to a Local Network]: deploy-to-a-local-network -[Build]: #build -[`soroban-cli`]: ../getting-started/setup#install-the-soroban-cli - ## Optimizing Builds -Building optimized contracts to be as small as possible requires some additional tools, and requires installing the `nightly` Rust toolchain and `wasm-opt`. - -:::tip - -Building optimized contracts is only necessary when deploying to a network with fees or when analyzing and profiling a contract to get it as small as possible. If you're just starting out writing a contract, these steps are not necessary. See [Build] for details on how to build for development. - -::: - -[Build]: #build - -### Install Rust `nightly` - -To install the nightly Rust toolchain use [`rustup`]. - -[`rustup`]: ../getting-started/setup#install-rust +Use `soroban contract optimize` to further minimize the size of the `.wasm`. ```sh -rustup install nightly -rustup target add --toolchain nightly wasm32-unknown-unknown -rustup component add --toolchain nightly rust-src +soroban contract optimize \ + --wasm target/wasm32-unknown-unknown/release/first_project.wasm ``` -### Install `wasm-opt` - -To install `wasm-opt`, install [`binaryen`]. Depending on your operating system there may be different ways to install it. - -[`binaryen`]: https://github.com/WebAssembly/binaryen +This will optimize and output a new `first_project.optimized.wasm` file in the same location as the input `.wasm`. - - - -```sh -brew install binaryen -``` - - - - -For distributions that use `apt`: - -```sh -sudo apt install binaryen -``` - -For other distributions see: -https://github.com/WebAssembly/binaryen/releases - - - - -For install options see: https://github.com/WebAssembly/binaryen/releases - - - - -### Build with `nightly` and `wasm-opt` - -Build your contract using nightly. The additional options instruct the compiler to remove unnecessary information from the contract. +:::tip -```sh -cargo +nightly build \ - --target wasm32-unknown-unknown \ - --release \ - -Z build-std=std,panic_abort \ - -Z build-std-features=panic_immediate_abort -``` +Building optimized contracts is only necessary when deploying to a network with fees or when analyzing and profiling a contract to get it as small as possible. If you're just starting out writing a contract, these steps are not necessary. See [Build] for details on how to build for development. -Use `wasm-opt` to further minimize the size of the `.wasm`. +::: -```sh -wasm-opt -Oz \ - target/wasm32-unknown-unknown/release/first_project.wasm \ - -o target/wasm32-unknown-unknown/release/first_project_optimized.wasm -``` +[Write a Contract]: #write-a-contract +[Deploy to a Local Network]: deploy-to-a-local-network +[Build]: #build +[`soroban-cli`]: ../getting-started/setup#install-the-soroban-cli \ No newline at end of file