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

Write user documentation for Rust contracts #129

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Write user documentation for Rust contracts #129

wants to merge 4 commits into from

Conversation

jakelang
Copy link
Member

@jakelang jakelang commented Dec 4, 2018

Closes #131.

@axic
Copy link
Member

axic commented Dec 5, 2018

Rebased.

Lane Rettig added 3 commits December 11, 2018 21:33
It doesn't need its own header
Add links to some other Ewasm docs
Copy link
Member

@lrettig lrettig left a comment

Choose a reason for hiding this comment

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

Made a few tweaks, added some links, and added a couple of comments. Overall looks great!


### Minimize the use of the standard library

Many constructs in Rust's standard library are not optimized for usage in Ewasm, or are outright unavailable due to dependence on a native syscall interface.
Copy link
Member

Choose a reason for hiding this comment

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

Could you give a specific example of something that is unavailable or not optimized for use?

Copy link
Member Author

Choose a reason for hiding this comment

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

Examples are below. As for something that is unavailable due to syscalls, most collections can simply use a custom allocator. So I might drop this line since nobody actually needs to read about that for this purpose.

Copy link
Member

Choose a reason for hiding this comment

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

I might drop this line since nobody actually needs to read about that for this purpose

Agree--where in doubt, keep it simple


The Rust compiler, at the moment, does not have fine-grained control over the imports and exports generated other than by their identifiers in the source. As a result, unnecessary exports must be removed and malformed imports corrected.

This can be done using an automated tool such as [wasm-chisel](https://github.com/wasmx/wasm-chisel), or by hand in the `.wast` file produced by disassembling the Wasm binary.
Copy link
Member

Choose a reason for hiding this comment

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

Could you demonstrate how to run wasm-chisel here so these instructions are complete?

The simplest way to slim down Rust-generated binaries is by enabling certain compiler optimizations:

* Enabling `lto`, or link-time optimizations, allows the compiler to prune or inline parts of the code at link-time.
* Setting `opt-level` to `'s'` tells the compiler to optimize for binary size rather than speed. `opt-level = 'z'` will optimize more aggressively for size, although at the cost of performance.
Copy link
Member

Choose a reason for hiding this comment

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

Note:

error: the optimizations s or z are only accepted on the nightly compiler

@jakelang
Copy link
Member Author

jakelang commented Dec 11, 2018 via email

#### Using [wasm-snip](https://github.com/rustwasm/wasm-snip)

The Rust compiler, by default, includes panicking and formatting code in generated binaries. For the purpose of Ewasm contracts, this is useless.
Using the `wasm-snip` tool, it is possible to replace the function bodies of such code with a single `unreachable` opcode, further shrinking the binary size.
Copy link
Member

Choose a reason for hiding this comment

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

wasm-snip requires a run of wasm-gc afterwards, iirc.

@jakelang
Copy link
Member Author

jakelang commented Dec 11, 2018 via email

@lrettig
Copy link
Member

lrettig commented Dec 27, 2018

Just took another look, still some pending requested changes here

@jakelang
Copy link
Member Author

I don't feel like i have the bandwidth to finish this right now. Does anyone want to help out on this? cc @lrettig @ewasm/rust

@axic
Copy link
Member

axic commented May 25, 2019

The longer we wait, the less readme will be needed as chisel will incorporate a lot 😆

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.

Add documentation on Rust
3 participants