koute / stdweb

A standard library for the client-side Web
Apache License 2.0
3.44k stars 177 forks source link

Write a procedural macro to replace the `js!` macro on nightly (without parsing the JavaScript) #6

Open koute opened 7 years ago

koute commented 7 years ago

The js! macro is truly a thing of terror, however we don't have much choice if we want to work on stable.

That said, it would we worthwhile to convert it to a nightly-only procedural macro to prepare for the future where procedural macros will be stabilized.

This will also help with the compile times, which are negatively impacted by the way the current js! macro is implemented.

LPGhatguy commented 6 years ago

Does the js! macro and the set of bindings to web APIs belong in the same crate?

I'm not very familiar with the architecture of stdweb, but it seems to me that generating JS from Rust and calling JS APIs from WASM/asm.js-compiled Rust are orthogonal. I'd imagine that applications would be written predominantly with one or the other!

koute commented 6 years ago

@LPGhatguy Well, they're not completely orthogonal, although, yes, the js! could be in its own crate on which the API bindings would depend on.

If you look at our src directory you can clearly see this split - basic JS interop is in the src/webcore, while API bindings are in src/webapi. It would be possible to split these two directories into two separate crates, however I don't want to do that yet as it would only increase friction without any real benefits. (The compiler is pretty good at eliminating dead code, so even if you only use the js! macro you're not paying for the rest of the stdweb you're not using.)

Kwarrtz commented 6 years ago

It looks like procedural macros are planned for stabilization in Rust 2018. Has there been any progress on this issue?

koute commented 6 years ago

@Kwarrtz Nope. But I do plan to do this once procedural macros are actually stabilized.