rsass icon indicating copy to clipboard operation
rsass copied to clipboard

Compile to WASM

Open chpio opened this issue 5 years ago • 5 comments

https://github.com/sass/node-sass/issues/2011

I've mentioned in that issue, that there could be a self contained "core" library without any external bindings, it would request all the needed data by some kind of abstract async api. That way we could port it more easily to other platforms like WASM (nodejs file io or even the browser).

chpio avatar Jan 16 '19 11:01 chpio

Cool! I havn't really looked into wasm yet. What would be required to compile rsass into wasm? Does it have to be no-std? In that case, I guess some kind of callback-based handling would be needed for supporting @import? Maybe converting FileContext to a trait that a caller can provide it's own implementation of?

The one dependency that could probably not be removed from such a "rsass core" would be nom. Is that possible to use in wasm?

kaj avatar Jan 20 '19 15:01 kaj

Does it have to be no-std?

No, but some of the std APIs are stubbed out (like threading and atomics) or panic (filesystem).

In that case, I guess some kind of callback-based handling would be needed for supporting @import? Maybe converting FileContext to a trait that a caller can provide it's own implementation of?

yeap, but it need to be async, as the browser/node context is 100% async.

The one dependency that could probably not be removed from such a "rsass core" would be nom. Is that possible to use in wasm?

I think it should work in wasm. Wasm is a normal ISA (like x64/x86), but there are just basic bindings to the host system (like memory allocation), no filesystem and so forth (there are efforts to make an OS that can execute WASM binaries just like normal executables and also add bindings to fs, but that's offtopic). So as long as it is just using self contained rust code (and allocations) it should work.

chpio avatar Jan 22 '19 11:01 chpio

Hello, i'd like to up this Issue cause Im very interested in the feature Rsass has compared to Grass, I've been looking around in order to make a WASM version for Deno, and I believe Rsass supports way more stuff compared to Grass.

There is something that can allow support for the Files (import etc..) Wasm-bindgen adds a way to load javascript function, you can basically use the Fs module on Node to load files and pass it as a Vec to Rust, that's what Grass does currently.

I tried to change Rsass way of loading file but it's way different and my Rust is not that great, do you think it would be possible to make such changes to allow any WASM compatibility ?

I made a wasm version for browsers and Deno using Grass, but it lacks many features that are present here. https://github.com/hironichu/denosass

ref : https://rustwasm.github.io/wasm-bindgen/

hironichu avatar Feb 13 '22 10:02 hironichu

@chpio If you do not need runtime modified sass, i made the PR #163 for compile time macros. you can try it by adding rsass-macro = {git = "https://github.com/Wicpar/rsass.git"} to dependencies and

use rsass_macro::scss;
const STR: &'static str = scss!(r#"
  .some-scss {
     // blabla
  }
"#);

It works in my wasm dioxus web project.

Wicpar avatar Jan 02 '23 16:01 Wicpar