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

Compile to WASM #33

Open
chpio opened this issue Jan 16, 2019 · 5 comments
Open

Compile to WASM #33

chpio opened this issue Jan 16, 2019 · 5 comments

Comments

@chpio
Copy link

chpio commented Jan 16, 2019

sass/node-sass#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).

@kaj
Copy link
Owner

kaj commented Jan 20, 2019

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?

@chpio
Copy link
Author

chpio commented Jan 22, 2019

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
Copy link
Author

chpio commented Apr 1, 2019

@hironichu
Copy link

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/

@kaj kaj added the help wanted label Mar 1, 2022
@Wicpar
Copy link
Contributor

Wicpar commented Jan 2, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants