-
Notifications
You must be signed in to change notification settings - Fork 193
Add initial wasm build #55
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#[cfg(target_arch = "wasm32")] | ||
use wasm_bindgen::prelude::*; | ||
|
||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global | ||
// allocator. | ||
#[cfg(feature = "wee_alloc")] | ||
#[global_allocator] | ||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; | ||
|
||
pub fn set_panic_hook() { | ||
// When the `console_error_panic_hook` feature is enabled, we can call the | ||
// `set_panic_hook` function at least once during initialization, and then | ||
// we will get better error messages if our code ever panics. | ||
// | ||
// For more details see | ||
// https://github.com/rustwasm/console_error_panic_hook#readme | ||
#[cfg(feature = "console_error_panic_hook")] | ||
console_error_panic_hook::set_once(); | ||
} | ||
|
||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen)] | ||
pub fn wgsl2msl(input: &str) -> String { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens when we add any functions to this module? If I understand correctly, these are public extern functions, so nothing is going to strip unused logic parts. If we add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this isn't really the best solution, just something to get started. The wasm interface should also be split in front-end returning AST and backend taking AST and returning text(or bin) output. But that requires someway to pass the AST efficiently. Maybe could use features to flag individual front/back-ends? |
||
let module = super::front::wgsl::parse_str(&input).unwrap(); | ||
|
||
println!("Compiled, header {:?}", module.header); | ||
|
||
use super::back::msl; | ||
let mut binding_map = msl::BindingMap::default(); | ||
binding_map.insert( | ||
msl::BindSource { set: 0, binding: 0 }, | ||
msl::BindTarget { buffer: None, texture: Some(1), sampler: None, mutable: false }, | ||
); | ||
binding_map.insert( | ||
msl::BindSource { set: 0, binding: 1 }, | ||
msl::BindTarget { buffer: None, texture: None, sampler: Some(1), mutable: false }, | ||
); | ||
let options = msl::Options { | ||
binding_map: &binding_map, | ||
}; | ||
msl::write_string(&module, options).unwrap() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately that would make the
cdylib
target to be generated for every build of naga as a dependency, even of other Rust code. See rust-lang/cargo#4280 .There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, not sure how to solve that, wasm-pack told me this is needed for being able to compile to wasm 😟