Build Universal Libraries with Rust

  Рет қаралды 58,708

Code to the Moon

Code to the Moon

Жыл бұрын

An explanation and tutorial of how to write libraries in Rust and submit them to the WebAssembly Package Manager such that they can be consumed by projects written in most major programming languages.
WAI Definition language documentation: github.com/wasmerio/wai/blob/...
A SHA2 package in WAPM that I mention in the video: wapm.io/wasmer/sha2
An overview of Wasmer and WAPM: • WebAssembly On The Ser...
-
Stuff I use to make these videos - I absolutely love all of these products. Using these links is an easy way to support the channel, thank you so much if you do so!!!
Camera: Canon EOS R5 amzn.to/3CCrxzl
Monitor: Dell U4914DW 49in amzn.to/3MJV1jx
SSD for Video Editing: VectoTech Rapid 8TB amzn.to/3hXz9TM
Microphone 1: Rode NT1-A amzn.to/3vWM4gL
Microphone 2: Seinheiser 416 amzn.to/3Fkti60
Microphone Interface: Focusrite Clarett+ 2Pre amzn.to/3J5dy7S
Tripod: JOBY GorillaPod 5K amzn.to/3JaPxMA
Mouse: Razer DeathAdder amzn.to/3J9fYCf
Computer: 2021 Macbook Pro amzn.to/3J7FXtW
Lens: Canon RF24mm F1.8 Macro is STM Lens amzn.to/3UUs1bB
Caffeine: High Brew Cold Brew Coffee amzn.to/3hXyx0q
More Caffeine: Monster Energy Juice, Pipeline Punch amzn.to/3Czmfox
Building A Second Brain book: amzn.to/3cIShWf

Пікірлер: 115
@workflowinmind
@workflowinmind Жыл бұрын
I had no idea wasmer could do that! That's awesome
@codetothemoon
@codetothemoon Жыл бұрын
it's a fairly recently introduced capability, so it's understandable. I'm pretty excited about it too
@anush8
@anush8 Жыл бұрын
So cool. Wanted to build something using WASM for like forever. Always hesitated because I felt the setup and build-processes aren't streamlined at all. Wasmer seems promising. Can't wait to try it. The WASM book and the MDN docs didn't give me the push to go on with WASM. This video did. Thanks a lot.
@codetothemoon
@codetothemoon Жыл бұрын
nice, really glad you got something out of the video! if you're willing, definitely let us know what you wind up building with it
@anush8
@anush8 Жыл бұрын
Sure.
@gomi-hako
@gomi-hako Жыл бұрын
That's exactly what I needed for the library project I'm currently building
@TheJohndward01
@TheJohndward01 Жыл бұрын
Wow this is really cool. Also I need to learn more about web assembly, definitely checking out that video!
@codetothemoon
@codetothemoon Жыл бұрын
I agree it's pretty exciting!
@PaulSebastianM
@PaulSebastianM Жыл бұрын
It's not enough that they are really talented developers, it's the fact that they work together as a team or just helpful contributors, most of the time! We often underestimate that kind of human relationship: working together towards a better future. We have a lot to learn from these kinds of interactions and their results in the real world, be it software related, NGO related, or just people in a local community building a better community for everyone.
@xucongzhan9151
@xucongzhan9151 Жыл бұрын
Most NGOs are sponsored by some government with a clear but hidden agenda, so that should probably be excluded.
@dmitriidemenev5258
@dmitriidemenev5258 Жыл бұрын
I'm the contributor of cross-lang-and-cross-platform project and I'm excited to see more people tackling the problem of cross-language interoperability!
@dynamite-bud
@dynamite-bud Жыл бұрын
got your mail, Thanks Dimitrii If you would like to connect dm me in community slack
@cinamonroll2701
@cinamonroll2701 Жыл бұрын
Very good product. Congratulations guys. Kisses from Romania looking forward to implement your awesome product.
@codetothemoon
@codetothemoon Жыл бұрын
I agree it shows great promise!
@vsuryabhargava
@vsuryabhargava Жыл бұрын
Great content as always.
@apinanyogaratnam
@apinanyogaratnam Жыл бұрын
moving your face to show the code which otherwise woulda blocked the code surprised me and is much appreciated!
@kajacx
@kajacx Жыл бұрын
You get a reference to self when using a resource automatically? That is *so good*! Can't wait to try it out.
@codetothemoon
@codetothemoon Жыл бұрын
😎
@slava_in3757
@slava_in3757 Жыл бұрын
Great video! Wonder how it treats the types for TypeScript, does it emit `.d.ts` files as well?
@sergioromano116
@sergioromano116 Жыл бұрын
This is so cool, I need to try it
@codetothemoon
@codetothemoon Жыл бұрын
it's worth giving a try!
@harikrishnanb7273
@harikrishnanb7273 Жыл бұрын
i always dreamt of such things, using webassembly as common between language given every language is trying to integrate with webassembly in some way.
@codetothemoon
@codetothemoon Жыл бұрын
yeah it seems perfectly positioned to fill that need!
@trumpetpunk42
@trumpetpunk42 Жыл бұрын
I'd be curious what the common known pitfalls of that are, and how to avoid them. Like the xkcd "one standard to rule them all" becoming "now we have yet another standard." As someone else said, we don't need yet another JVM or DCOM or CORBA. But if there's a way to make bi-directional FFI convenient and architecture independent, I'm all for it.
@ariasalehi5665
@ariasalehi5665 Жыл бұрын
This is amazing, thanks for sharing
@codetothemoon
@codetothemoon Жыл бұрын
thanks for watching!
@NathanHedglin
@NathanHedglin Жыл бұрын
Great! Rust + WASM = super powers
@codetothemoon
@codetothemoon Жыл бұрын
agree 💯
@wfzyx
@wfzyx Жыл бұрын
I really like the idea, and believe that this can be used in the future by smaller/newer languages to have strong ecosystems, given they implement wasm integration. The only problem that I see right now, is that you don't have LSP for the WAI bindings on Rust for e.g, so this makes developing anything more complex kinda annoying.
@yokebabjr3866
@yokebabjr3866 Жыл бұрын
Great video! It seems to have plenty of use cases for this. Do you know if we could also use the webassembly sandbox mecanisim with this approach? I could imagine a plugin system with restricted rights.
@ayushdedhia25
@ayushdedhia25 Жыл бұрын
Informative 👏🏻 btw what font are you using it looks pretty cool 🙂
@codetothemoon
@codetothemoon Жыл бұрын
Monaco!
@ayushdedhia25
@ayushdedhia25 Жыл бұрын
@@codetothemoon thank you!!
@alexIVMKD
@alexIVMKD Жыл бұрын
Very cool!
@codetothemoon
@codetothemoon Жыл бұрын
thanks!
@jeffg4686
@jeffg4686 11 ай бұрын
is this an implementation of the new "Component Model" in WASI? Great video, btw - thanks for sharing - packed with good info. When a language with a runtime publishes to WA, will that include a WA coded runtime for that language (like C#)? thx IE, will it perform like a WA module coded in Rust, or more like a garbage collected language.
@ha5anmukhlis
@ha5anmukhlis Жыл бұрын
Are wai files standard format or is it something by wasmer? with how webassembly is, I'm scared it might turn into a mess of an ecosystem like javascript
@-indeed8285
@-indeed8285 Жыл бұрын
The font he is using is 'Monaco'
@codetothemoon
@codetothemoon Жыл бұрын
yep!
@Erhannis
@Erhannis 9 ай бұрын
I've searched their main site, their docs site, and glanced at their github, and I still can't figure out what languages they support, which is MINDBOGGLING. D:
@codetothemoon
@codetothemoon 9 ай бұрын
There used to be such a list, I think they recently did a major revamp of the website (and merged wapm.io into wasmer.io). It seems like there is a list of the major languages here wasmer.io/products/runtime but I'm also not sure if the comprehensive list exists somewhere. Is there a particular language you're curious about?
@jfk1337
@jfk1337 Жыл бұрын
Does autocompletion work for these libraries? Does the lsp know that the uc object has the method hash with it?
@guilherme5094
@guilherme5094 Жыл бұрын
👍Really nice👍!
@kajacx
@kajacx Жыл бұрын
Damn, the "WASM Interface Types" dream is true. I will have to see if I can use this instead of fp-bindgen.
@codetothemoon
@codetothemoon Жыл бұрын
its worth a try!
@timkilian7140
@timkilian7140 Жыл бұрын
This will be the future
@moeruishi
@moeruishi Жыл бұрын
I have a question. I’m currently working on a personal project and I’m wondering if there’s a way to define 2 functions with same name but different argument types and return types in the wai file? Similar to what we can do with traits (think function overloading)
@leviathan7477
@leviathan7477 Жыл бұрын
When using records, how do you instantiate an instance of the record type in the language using the library?
@apinanyogaratnam
@apinanyogaratnam Жыл бұрын
so is it running rust code or is it generating code in the language you use it?
@ordinarygg
@ordinarygg Жыл бұрын
Awesome, more malware libraries))
@codetothemoon
@codetothemoon Жыл бұрын
why limit yourself and make your malware consumable from only one language? 😉
@ordinarygg
@ordinarygg Жыл бұрын
@@codetothemoon you dirty boy!!!!!)) Love your humour and channel, subscribed already!)))
@michael-rommel
@michael-rommel 10 ай бұрын
"enough brainpower to center a or quit vim" - good one 😂
@codetothemoon
@codetothemoon 7 ай бұрын
thanks 😎
@Im_Ninooo
@Im_Ninooo Ай бұрын
this is awesome!! I wonder if it's possible to generate a Node package locally/without publishing it.
@Im_Ninooo
@Im_Ninooo Ай бұрын
I found out it is, by using the wasmer-pack crate
@DevvOscar
@DevvOscar Жыл бұрын
Random off topic question. How does he have that shell command input on the bottom in emacs? I want to get the same in Neovim. I don't want to type :! every time.
@codetothemoon
@codetothemoon Жыл бұрын
you get that "out of the box" with DOOM - I press M-! to get it. One fewer keystroke than nvim I guess. I'm also curious about a quicker alternative in neovim.
@dungeon4971
@dungeon4971 Жыл бұрын
which font are you using ? looks good to be honest
@BrazenNL
@BrazenNL Жыл бұрын
If you look at the lowercase 'i', they are different in the terminal and in the editor.
@codetothemoon
@codetothemoon Жыл бұрын
In emacs it is Monaco, in VSCode i *think* it is Menlo
@sadramohh
@sadramohh 7 ай бұрын
For anyone trying to recreate this on their own: *WAPM is deprecated*, and so `cargo wapm` has been replaced by `cargo wasmer`. This is how the metadata configuration looks like in `Cargo.toml`: [package.metadata.wasmer] namespace = "" # same as your wasmerio account handle abi = "wasi" # choose "wasi" for both javascript and python bindings bindings = { wai-version = "0.1.0", exports = "" } # should not contain `_` underscores
@Nintron
@Nintron Жыл бұрын
6:09 scared the heck out of me lol
@eliasp.2759
@eliasp.2759 Жыл бұрын
Great video! Do the wasmer functions only allow primitive types as parameters?
@codetothemoon
@codetothemoon Жыл бұрын
nope you can have what are essentially "classes" as parameters as well - or "records" in WAI terms. I go a bit more in depth into WAI and its capabilities toward the end of the video.
@omofolarinajibade
@omofolarinajibade Жыл бұрын
Is it possible to develop universal client and does it work with reqwest?
@dulanjala
@dulanjala Жыл бұрын
rust compile is so slow even for this kind of project. anyway to speed up, caching or just direct linking binaries?
@roughedge-machineworks
@roughedge-machineworks Жыл бұрын
How do i use wasmer as a dependency and include a wasm file to execute a function off that? Ive tried several ways and just get a wasi error .. :|
@AK-vx4dy
@AK-vx4dy 10 ай бұрын
Oh man! I undestimated WASM, now i realized that you can send "binary" module but not have to compile it for my arch.... devastating. Is any standalone executor/sandbox for wasm exist excluding browsers and node/deno etc. ?
@OldKing11100
@OldKing11100 Жыл бұрын
This could be amazing. I love using Rust built items, but I'm not a big fan of coding in it, yet. Right now I'm still heavily coding in Go and their dataframe handling package is unmaintained. I've been eyeing polars (and a lot of other crates) and have been wishing to use those in Go. I know the real solution is to just use Rust, but that's not always an option to rewrite everything. Maybe this will be the start for utilizing more Rust under the hood of other languages?
@d-o-n-u-t
@d-o-n-u-t Жыл бұрын
You don't necessarily have to write everything if you use the web services architecture; I know it's kind of a buzzword, but part of why it's great is that you can implement your backend in multiple languages. You can keep all of your non-performance-critical code in Go and fallback to Rust when you really need it.
@sebastiangudino9377
@sebastiangudino9377 Жыл бұрын
Your entire app does NOT need to use one language of the other. "Interprocess Comunicaition" and "Foreign Function Interface" might be good search terms as general ideas to interoperate Rust and Go (Other than just using wasm, of course)
@frittex
@frittex Жыл бұрын
wow
@codetothemoon
@codetothemoon Жыл бұрын
I was pretty impressed when I first learned about this!
@ChetanBhasin
@ChetanBhasin Жыл бұрын
What would be cool if you could use the generated WAPM package without publishing it to the registry. That's going to be particularly useful for Monorepos and private code base for people who do not want to publish everything to public WAPM registry.
@shaunhamilton
@shaunhamilton Жыл бұрын
I am quite surprised the .wai file is not automatically generated based on the Rust code. I realise this might be a problem for a library written in a dynamically typed language, but it would be much easier if the file were generated where possible.
@kajacx
@kajacx Жыл бұрын
The Rust code is generated from the wit file, which is better IMO, because you define the protocol first, and then the implementation. But it would be cool if it would be possible the other way too.
@hck1bloodday
@hck1bloodday Жыл бұрын
also the client code need to specify the funtion to call as a string, that seems weird, specially in strong typed languages like Java or C#. if they solve that, I'll take a look at this product, meanwhile i will evade it.
@Stopinvadingmyhardware
@Stopinvadingmyhardware Жыл бұрын
this means we can stable host COBOL applications remotely now We can replace old iron now.
@harikrishnanb7273
@harikrishnanb7273 Жыл бұрын
okay, i completed watching the video. now i want know about the drawbacks or limitations of this.
@codetothemoon
@codetothemoon Жыл бұрын
I think the only drawback would be that WASM may be slightly less performant than the equivalent logic running on bare metal (machine code). This will be a non-issue for some use cases, and a complete deal breaker for others.
@dingus4138
@dingus4138 Жыл бұрын
This is legit
@codetothemoon
@codetothemoon Жыл бұрын
I agree!
@hikionori
@hikionori Жыл бұрын
Ok, I like the idea of ​​webassemblies but there is some problem because I can't write libraries specifically for webassemblies, this problem is a problem with rust collections. If anyone knows how to solve this problem for example HashMap answer me
@kc3vv
@kc3vv Жыл бұрын
I wonder how the performance stacks up.
@codetothemoon
@codetothemoon Жыл бұрын
as compared to native machine code? I'd be interested to see that as well, I'd be surprised if somebody hasn't done it yet
@myronkipa2530
@myronkipa2530 Жыл бұрын
In my experience wasm is considerably slower than native rust
@codetothemoon
@codetothemoon Жыл бұрын
interesting - how much slower?
@techlifejournal
@techlifejournal 7 ай бұрын
Zig vs rust Can you please make a video ?
@JosephCatrambone
@JosephCatrambone Жыл бұрын
In the interest of assuaging my anxiety, you cycled all those credentials and tokens before publishing this video, right?
@codetothemoon
@codetothemoon Жыл бұрын
I did. Thanks for checking haha 😎
@JosephCatrambone
@JosephCatrambone Жыл бұрын
@@codetothemoon Whew. Thank you.
@recklessroges
@recklessroges Жыл бұрын
I'm still waiting for WASM's obfuscation to be used maliciously. It feels like WASM has trouble ahead.
@turolretar
@turolretar Жыл бұрын
As soon as you opened vscode I died inside
@sumansaha295
@sumansaha295 Жыл бұрын
I'll never understand the hate for vscode, no other general purpose editor even comes close to the features and extensibility of vscode.
@cbbcbb6803
@cbbcbb6803 Жыл бұрын
Someone should re-write all of the Python libraries into Rust. That way, a collection of universal libraries, written in Rust, could be called from any other language that a programmer may prefer to use. Is there any software that will assist in converting C/C++ source code into Rust source code?
@savire.ergheiz
@savire.ergheiz Жыл бұрын
If only life also so simple 😂
@arjix8738
@arjix8738 Жыл бұрын
I don't like that the wai file has lowercase everywhere, but the code generated has camel case. Like, why is the "crab" record generated as "Crab" in rust?
@Nan0MK_Old
@Nan0MK_Old Жыл бұрын
"Enoom"
@avi7278
@avi7278 Жыл бұрын
It's pretty much expected that any library these days is in Typescript.
@codetothemoon
@codetothemoon Жыл бұрын
I think there are many use cases for which TS is not a good fit 😎
@phredlane9081
@phredlane9081 11 ай бұрын
You are mistaken.
@user-mg6yz6pp7u
@user-mg6yz6pp7u Жыл бұрын
Actually, the WAI interface is not supported by the Bytecode Alliance, which is defining the officiel WASI protocols. WAI is a fork of wit-bindgen, because wasmer tried to integrate bindings to wasmer into wit, and got rejected, because those 3rd party bindings do not belong in the source project. But the Wasmer CEO got butthurt, and make his own fork from WIT, which he named WAI. You all should rely on the Compoment Model and WIT, worked on by the original WebAssembly designers : The Bytecode Alliance.
@codetothemoon
@codetothemoon Жыл бұрын
I'm aware of the WAI origin story, though I'm not sure anybody got "butthurt". I don't think it makes sense to stick with something solely because it's maintained by the original creators, if that was the case we'd all be using vi or ed instead of Neovim. If you can enumerate the advantages one would get by sticking with WIT, that might be more constructive - for example do they have an equivalent of WAPM?
@biomorphic
@biomorphic Жыл бұрын
This is basically CORBA 2.0. It failed once, I wonder if it will fail again.
@lbirkert
@lbirkert Жыл бұрын
Postgres on the thumbnail tho
@babayaga4329
@babayaga4329 Жыл бұрын
sure, let's reinvent x86 platform, as a universal platform so we can run it on x86 platform. Now that's out of the box thinking
@skyline00069
@skyline00069 Жыл бұрын
FIRST
@codetothemoon
@codetothemoon Жыл бұрын
🥇
@skyline00069
@skyline00069 Жыл бұрын
@@codetothemoon mom i finally did it
@skyline00069
@skyline00069 Жыл бұрын
i'm up now.
@thecoolnewsguy
@thecoolnewsguy Жыл бұрын
​@@skyline00069 🌄🥇
@developerdeveloper67
@developerdeveloper67 Жыл бұрын
No bro, we don't want to use rust, C++ is fine.
@0xngmi
@0xngmi 11 ай бұрын
getting this error on cargo wapm: Error: 'AnonymousUser' object has no attribute 'is_email_validated' Error: Unable to publish "universal_crypto" my email in wasmer is verified...
@juan-lukeklopper3922
@juan-lukeklopper3922 9 ай бұрын
Did you run the wasmer login command?
Rust-Powered Log Observability at Scale
22:02
Code to the Moon
Рет қаралды 10 М.
СНЕЖКИ ЛЕТОМ?? #shorts
00:30
Паша Осадчий
Рет қаралды 8 МЛН
МАМА И STANDOFF 2 😳 !FAKE GUN! #shorts
00:34
INNA SERG
Рет қаралды 3,4 МЛН
3 wheeler new bike fitting
00:19
Ruhul Shorts
Рет қаралды 50 МЛН
World’s Deadliest Obstacle Course!
28:25
MrBeast
Рет қаралды 131 МЛН
Will Rust Beat JavaScript in 2023?
23:48
ThePrimeTime
Рет қаралды 109 М.
I spent six months rewriting everything in Rust
15:11
chris biscardi
Рет қаралды 408 М.
Why is the JavaScript ecosystem switching to Rust?
48:08
chris biscardi
Рет қаралды 128 М.
why rust libraries may never exist.
7:26
Low Level Learning
Рет қаралды 225 М.
Safe Rust AIN'T SAFE!? (cve-rs)
20:42
Residual Entropy
Рет қаралды 48 М.
Why JavaScript Devs are Switching to Rust in 2024
10:35
warpdotdev
Рет қаралды 248 М.
Rust Powered Database SurrealDB (It's Pretty Ambitious)
11:28
Code to the Moon
Рет қаралды 107 М.
All Rust string types explained
22:13
Let's Get Rusty
Рет қаралды 150 М.
I coded one project EVERY WEEK for a YEAR
13:13
Carter Semrad
Рет қаралды 523 М.
Hisense Official Flagship Store Hisense is the champion What is going on?
0:11
Special Effects Funny 44
Рет қаралды 2 МЛН
Asus  VivoBook Винда за 8 часов!
1:00
Sergey Delaisy
Рет қаралды 1,1 МЛН
Игровой Комп с Авито за 4500р
1:00
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 373 М.