on master help sign in
helix-loader + helix-core now compile for WASM
commit9191af3f8d73d2101c46192a4a80c41a19012320 authorBlaž Hrastnik <blaz@mxxn.io> dateSun 27 Mar 2022, 11:23 (5 years ago) parent8bb89da
2 files changed+16−2
helix-loader/Cargo.toml+6−1 helix-loader/src/grammar.rs+10−1
helix-loader/Cargo.toml+6−1
@@ -15,11 +15,16 @@ serde = { version = "1.0", features = ["derive"] }
1515toml = "0.5"
1616etcetera = "0.3"
1717tree-sitter = "0.20"
18−libloading = "0.7"
1918once_cell = "1.9"
2019
2120log = "0.4"
2221
22+# TODO: these two should be on !wasm32 only
23+
2324# cloning/compiling tree-sitter grammars
2425cc = { version = "1" }
2526threadpool = { version = "1.0" }
27+
28+[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
29+libloading = "0.7"
30+
helix-loader/src/grammar.rs+10−1
@@ -1,5 +1,4 @@
11use anyhow::{anyhow, Context, Result};
2−use libloading::{Library, Symbol};
32use serde::{Deserialize, Serialize};
43use std::fs;
54use std::time::SystemTime;
@@ -17,6 +16,9 @@ const DYLIB_EXTENSION: &str = "so";
1716#[cfg(windows)]
1817const DYLIB_EXTENSION: &str = "dll";
1918
19+#[cfg(target_arch = "wasm32")]
20+const DYLIB_EXTENSION: &str = "wasm";
21+
2022#[derive(Debug, Serialize, Deserialize)]
2123struct Configuration {
2224 #[serde(rename = "use-grammars")]
@@ -57,7 +59,14 @@ pub enum GrammarSource {
5759const BUILD_TARGET: &str = env!("BUILD_TARGET");
5860const REMOTE_NAME: &str = "origin";
5961
62+#[cfg(target_arch = "wasm32")]
63+pub fn get_language(name: &str) -> Result<Language> {
64+ unimplemented!()
65+}
66+
67+#[cfg(not(target_arch = "wasm32"))]
6068pub fn get_language(name: &str) -> Result<Language> {
69+ use libloading::{Library, Symbol};
6170 let name = name.to_ascii_lowercase();
6271 let mut library_path = crate::runtime_dir().join("grammars").join(&name);
6372 library_path.set_extension(DYLIB_EXTENSION);