Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5923760

Browse files
committed
Annotated potential wasm problems
1 parent 216b91b commit 5923760

File tree

8 files changed

+107
-2
lines changed

8 files changed

+107
-2
lines changed

Cargo.lock

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ eframe = { version = "0.22.0", default-features = false, features = [
1313
"glow", # Use the glow rendering backend. Alternative: "wgpu".
1414
"persistence", # Enable restoring app state when restarting the app.
1515
] }
16+
wasm-bindgen = "0.2"
1617
tracing = "0.1.37"
1718
tracing-subscriber = "0.3"
1819
log = "0.4.19"
@@ -35,4 +36,8 @@ prettyplease = "0.2.10"
3536
slotmap = "1.0.6"
3637
clap = { version = "4.3.19", features = ["derive"] }
3738
usvg = "0.35.0"
38-
cargo-generate = "0.18.4"
39+
cargo-generate = "0.18.4"
40+
clang = "2.0.0"
41+
42+
[lib]
43+
crate-type = ["cdylib"]

src/app/code_editor.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ impl Default for CodeFile {
5555
}
5656

5757
impl CodeFile {
58+
59+
60+
// These implementations will be slightly more challenging. We can't use include_bytes!()
61+
// since that doesnt work on runtime file creation. Instead, LocalStorage seems like the best bet
62+
// Local Storage utilizes a key value pair and saves it to the local browser.
63+
#[wasm_bindgen]
64+
fn load_from_file(key: &str) -> Option<String>{
65+
66+
}
67+
68+
69+
70+
#[wasm_bindgen]
71+
fn save(key: &str, data: &str) -> Option<String>{
72+
73+
}
74+
75+
5876
// Load some code from a path
5977
fn load_from_file(&mut self, file_path: &Path) -> std::io::Result<()> {
6078
let CodeFile { code, .. } = self;

src/app/icons.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ pub const ICON_DIR: &'static str = "assets/icons/pack/white/";
2121
pub const SMALL_ICON_SIZE: Vec2 = Vec2::new(8.0, 8.0);
2222
pub const DEFAULT_ICON_SIZE: Vec2 = Vec2::new(12.0, 12.0);
2323

24+
25+
26+
#[wasm_bindgen] //TODO: implement this using local binary-stored data.
27+
pub fn load_icons() -> HashMap<&'static str, RetainedImage> {
28+
29+
}
30+
31+
32+
2433
// This function returns a mapping of icon names to RetainedImages
2534
pub fn load_icons(icon_path: &Path) -> HashMap<&'static str, RetainedImage> {
2635

src/app/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,28 @@ pub struct IronCoderApp {
7373
}
7474

7575
impl Default for IronCoderApp {
76+
77+
#[wasm_bindgen] //TODO: Locally store the board files
78+
fn default() -> Self {
79+
80+
// Might be difficult to find a way to store the entire directory,
81+
// so it'll be important to find the necessary components and load them in
82+
// with include_bytes!()
83+
84+
85+
86+
}
87+
7688
fn default() -> Self {
7789
// Populate the boards
78-
let boards_dir = Path::new("./iron-coder-boards");
90+
91+
92+
let boards_dir = Path::new("./iron-coder-boards");
7993
let boards: Vec<board::Board> = board::get_boards(boards_dir);
94+
95+
96+
97+
8098
Self {
8199
project: Project::default(),
82100
display_about: false,

src/board/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ impl Hash for Board {
126126
/// information about them.
127127
impl Board {
128128

129+
130+
131+
#[wasm_bindgen] //TODO: Implement
132+
fn load_from_toml(path: &Path) -> std::io::Result<Self> {
133+
// Anything relating to a file will have to utilize the include_bytes! macro.
134+
// It is very likely that any structs with paths to images as member variables
135+
// will have to be replaced with constant data, which is then assigned at compile time.
136+
// Functions like this will then instead
137+
}
138+
139+
129140
/// Loads a board from its toml description
130141
fn load_from_toml(path: &Path) -> std::io::Result<Self> {
131142

src/board/parsing.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,24 @@ impl<'ast> Visit<'ast> for BspParseInfo {
114114
/// Board impls regarding parsing of BSP syntax
115115
impl Board {
116116

117+
#[wasm_bindgen] //TODO: Implement
118+
fn parse_bsp(&self) -> Option<syn::File>{
119+
// To include files in wasm, you have to do this, but this won't work since
120+
// all paths need to be known at compile time. Likely will need to go back
121+
// and change the board implementations.
122+
const svg_string: &'static [u8] = include_bytes!(path)
123+
124+
125+
}
126+
117127
// Attempt to parse the BSP lib file.
118128
fn parse_bsp(&self) -> Option<syn::File> {
119129
let mut syntax = None;
120130
if let Some(bsp_dir) = self.bsp_path.clone() {
121131
let src = bsp_dir.join("src/lib.rs");
132+
122133
let src = fs::read_to_string(src.as_path()).unwrap();
134+
123135
syntax = match syn::parse_file(src.as_str()) {
124136
Ok(syntax) => {
125137
Some(syntax)

src/board/svg_reader.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ pub struct SvgBoardInfo {
4141

4242
impl SvgBoardInfo {
4343

44+
45+
// We could make a wasm build target version of this function, but most likely we can just
46+
// prerender and include the .png files.
47+
4448
/// Parse an Iron Coder SVG Board image from the filesystem.
4549
pub fn from_path(path: &Path) -> Result<SvgBoardInfo, Error> {
4650

0 commit comments

Comments
 (0)