-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Resource Embedding #2164
Comments
Syntax like But there's also the issue that I read
Or could just go for this as an expression:
NOTE: I heavily edited this comment after reading better. Also to make more readable lists of options to consider. |
An example of importing an asset in js with vite: import imgUrl from './img.png' Note that is might or might not embed the asset in the js bundle, depending on the size and whatnot. Although I agree that a basic "please make sure to embed" makes extra sense in wasm or native binaries, since despite wasi, there are fewer expectations around runtime access to external files than what you get in js. |
And raw string import is also a thing in vite: import shaderString from './shader.glsl?raw' Again, maybe don't need the same level of fancy if the primary use case is just embedding a byte array. |
It would be nice if we could import files in grain as just raw bytes at compile time.
Zig seems todo this with
comptime
and it is just a function@embedFile
https://ziglang.org/documentation/master/#embedFileRust seems to use a macro for this:
https://doc.rust-lang.org/std/macro.include_bytes.html
One idea would be to use syntax like
from "filepath" embed x
, this complements ourinclude
syntax really nicely. alternatively maybe we just doembed "file" as x
though this raises questions in relation to theas
keyword given its usually used for aliasing.This feature is useful in a lot of places especially game development where you would be including resources such as images or music.
for now this feature can just be implemented as syntax sugar that generates a byte string bassically:
would get converted to:
probably somewhere in our middle end phase before typechecking.
in the future once we have datasections it might look into implementing this directly using those.
The text was updated successfully, but these errors were encountered: