-
Notifications
You must be signed in to change notification settings - Fork 60
Expanding the Rust wasm Book #41
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
Comments
There is a handbook to teach how to programming with wasm. Real World WebAssembly |
@3442853561 I can make a section for resources like this and split it by language :) |
@mgattozzi May I help you to finish this book? What should I do? |
@3442853561 Yeah! You'll need to do a few things:
If english isn't your first language don't worry. I'll help you make edits :) At some point I'd like to just make multiple different versions of this natively translated. |
@mgattozzi You had posted a comment here but I'm replying to it in this thread, so as to keep the threads on-topic. I would love to contribute some examples, however my harddrive had recently gotten corrupted, so I lost all of my Rust code. When I finish another Rust project I can contribute it. I can also give some explanations right now about what I did, how I did it, what problems I encountered, how I fixed those problems, etc. |
@Pauan would be awesome to hear those 👍 @mgattozzi & @Pauan If there is anything, that I can help with the documentation and experimenting would be more than happy to do so. |
@Pauan no rush. If you can great! In general we're trying to centralize resources for people, even blog posts. Let me know if there's something you want to take a crack at or if you have another idea I might have missed in the list above! More than happy to then review your PR or help you with getting the docs in! :D |
Heads up to issue subscribers: I just edited the original comment to add this under the tutorials item:
|
Can we also tell users about the plugins that are available for rust ?
This seems to be interesting, can you let me know about the places where we have these details. interesting use case to have yet another arewereadysite 👍 |
@sendilkumarn so the issue tracker here is the current state. Unfortunately that means having to read and understand it all. Since we're the source we need to curate it for others who don't want to wade through the issue tracker (most people won't and shouldn't need too). We keep track of things going on in rustc here as well like llvm6 being merged as well as lld support for wasm. I don't see why we can't include plugins with their own section in the tooling area as well. Just need to add the caveat that it's an unstable feature, but then again they're using nightly for wasm so it's really not as big a deal. |
So, to explain about my experience using Rust + WebAssembly. There is a website called SaltyBet, where you can bet fake money on virtual fighting matches. My goal was to create a robot that would automatically bet, hopefully making more money than it loses. Rather than trying to create the robot directly, I decided to write a genetic evolutionary algorithm, and the evolutionary algorithm would then create the robot for me. Then I can run that robot on SaltyBet. There are two parts to the Rust program:
For the most part But there's a catch. When you use a callback, that callback is marked with element.add_event_listener(|event: ClickEvent| {
// ...
}); In this case we're passing in a Or to put it another way, if you want to use something which is outside of the callback, then you either have to move it (transfer ownership) into the callback, or you have to use If a variable is only used inside the callback, then I recommend using let mut foo: u32 = 5;
element.add_event_listener(move |event: ClickEvent| {
// use foo
}); But if you want to use some variable both inside and outside the callback, then you must use let foo: Rc<u32> = Rc::new(5);
{
let foo = foo.clone();
element.add_event_listener(move |event: ClickEvent| {
// use foo
});
}
// use foo If you want to mutate a variable from inside and outside the callback, then you must use let foo: Rc<RefCell<u32>> = Rc::new(RefCell::new(5));
{
let foo = foo.clone();
element.add_event_listener(move |event: ClickEvent| {
let foo = foo.borrow_mut();
// use foo
});
}
// use foo When using callbacks, be prepared to use This is necessary because JavaScript might call the callback at any time, and Rust cannot guarantee that the references will still be alive when JavaScript calls the callback. Using This isn't really stdweb's fault, it's just a fundamental problem with JavaScript interop, so you'll have this problem even if you're not using stdweb. Also, if you want to use a JavaScript API which isn't already provided by stdweb, then things get a lot trickier. You have to use the fn foo(input: u32) {
js! {
var array = [1, null, "foo", @{input}];
console.log("Look, it's JavaScript code!", array[2]);
}
} But there's a lot of subtleties involved, especially with callbacks. And when converting a JavaScript API into Rust, it's sometimes hard to figure out how to do it (in large part because JavaScript is dynamically typed). But overall I've been very happy with stdweb, it's done an excellent job of not only making it possible to use JavaScript APIs, but also fairly pain-free too. |
@koute Your work on stdweb is kind of becoming a defacto standard when working with wasm. I was wondering if you'd like to have a tutorial or introduction of some sort featured in the book if you wanted I was thinking having it be apart of the tutorials and guides section. Especially since you just released 0.4 :) |
#70 reminds me that we should also have a section for how to debug and profile when targeting WebAssembly. |
@mgattozzi Of course I would! Having more documentation is always a good thing. What kind of a tutorial do you have in mind? I'm totally willing to help write something up. |
@koute I was thinking a getting started, exporting stuff for JS to work with wasm, as well as maybe integrating with parcel now that you added it. Even if you didn't have time if you list some things you want or think would be useful to document I could get a separate issue open and organize it so we can track working on it. I was thinking we could have sections for the bigger tools in the eco-system and document them and stdweb would be one of the first for that :) |
Does anyone have a good idea for the thing that the tutorial builds?
Ideas? |
I would suggest this This might look simple, but when we can do this seamlessly then we can package them as a separate package and give that as a web component and I bet people will love to use that. probably add an async loading and showcase the capabilities of fullstack with rust. |
@fitzgen How about something involving WebGL: very compute-heavy, very interesting for web developers, and very cool in general. I always love seeing fancy 3D renderings. |
I'm not sure exactly what might be the best, but having a site they can also open to see a non wasm version to see the difference would be good as well. Visibly seeing the speed difference rather than saying there is one provides better impact and makes it more memorable. Basically we need a "Wow. Holy crap this is really cool" kind of moment. |
@mgattozzi That's a great idea! We need something similar to this, in other words a site that shows you the speed difference. |
My concern with webgl is that it involves a lot of boundary crossing to invoke each api call, and that a lot of the interesting bits are just the shader code rather than rust compiled to wasm. |
It would be really awesome to either use the title or labels to segregate the issues. We can write a crawler to munch on these data to showcase a SPA that showcases the high level details that we need people to know about the current WASM process. (It might require few rewriting but I am sure that it helps on the longer run) |
exactly that was my concern too OTOH I need to have a simpler looking example that solves what developers struggle daily in their applications. This should be a My worry is that, people always think that From what I really believe, developers who are doing normal web apps should see back this capability and then try to use it in their applications and that is where the aim should be (IMO) |
This issue has been moved here |
In #12 we added the book to act as a central part of documenting and working with wasm and Rust.
We should continue to expand it as we hash things out and continue to work on wasm. I've compiled a list of tasks below to help grow and maintain the book. This can be a starting point for those wishing to help out but aren't really sure what to do.
Tasks
wasm32
target does, or passing data into and out of JS for instance. The book tells people how to setup the environment and run hello world. Now we need to go beyond that.Update: In Add Tools page (#41) #42 we added the page but this can be expanded as it is a living document! Finding more tools to add and removing old or unused ones overtime will be important.
There's likely more we can do to increase our documentation efforts but this seems like a good few steps we can take to really get our documentation efforts underway.
The text was updated successfully, but these errors were encountered: