Browse Source

Set up wasm build system

main
Dylan Baker 3 years ago
parent
commit
601fb6b0f0
4 changed files with 138 additions and 8 deletions
  1. 111
    0
      Cargo.lock
  2. 4
    2
      Cargo.toml
  3. 2
    0
      Makefile
  4. 21
    6
      src/lib.rs

+ 111
- 0
Cargo.lock View File

@@ -9,6 +9,18 @@ dependencies = [
9 9
  "memchr",
10 10
 ]
11 11
 
12
+[[package]]
13
+name = "bumpalo"
14
+version = "3.6.1"
15
+source = "registry+https://github.com/rust-lang/crates.io-index"
16
+checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe"
17
+
18
+[[package]]
19
+name = "cfg-if"
20
+version = "1.0.0"
21
+source = "registry+https://github.com/rust-lang/crates.io-index"
22
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
23
+
12 24
 [[package]]
13 25
 name = "elastic"
14 26
 version = "0.1.0"
@@ -17,6 +29,7 @@ dependencies = [
17 29
  "regex",
18 30
  "serde",
19 31
  "serde_json",
32
+ "wasm-bindgen",
20 33
 ]
21 34
 
22 35
 [[package]]
@@ -31,12 +44,39 @@ version = "1.4.0"
31 44
 source = "registry+https://github.com/rust-lang/crates.io-index"
32 45
 checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
33 46
 
47
+[[package]]
48
+name = "log"
49
+version = "0.4.14"
50
+source = "registry+https://github.com/rust-lang/crates.io-index"
51
+checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
52
+dependencies = [
53
+ "cfg-if",
54
+]
55
+
34 56
 [[package]]
35 57
 name = "memchr"
36 58
 version = "2.3.4"
37 59
 source = "registry+https://github.com/rust-lang/crates.io-index"
38 60
 checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
39 61
 
62
+[[package]]
63
+name = "proc-macro2"
64
+version = "1.0.26"
65
+source = "registry+https://github.com/rust-lang/crates.io-index"
66
+checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec"
67
+dependencies = [
68
+ "unicode-xid",
69
+]
70
+
71
+[[package]]
72
+name = "quote"
73
+version = "1.0.9"
74
+source = "registry+https://github.com/rust-lang/crates.io-index"
75
+checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
76
+dependencies = [
77
+ "proc-macro2",
78
+]
79
+
40 80
 [[package]]
41 81
 name = "regex"
42 82
 version = "1.4.5"
@@ -76,3 +116,74 @@ dependencies = [
76 116
  "ryu",
77 117
  "serde",
78 118
 ]
119
+
120
+[[package]]
121
+name = "syn"
122
+version = "1.0.68"
123
+source = "registry+https://github.com/rust-lang/crates.io-index"
124
+checksum = "3ce15dd3ed8aa2f8eeac4716d6ef5ab58b6b9256db41d7e1a0224c2788e8fd87"
125
+dependencies = [
126
+ "proc-macro2",
127
+ "quote",
128
+ "unicode-xid",
129
+]
130
+
131
+[[package]]
132
+name = "unicode-xid"
133
+version = "0.2.1"
134
+source = "registry+https://github.com/rust-lang/crates.io-index"
135
+checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
136
+
137
+[[package]]
138
+name = "wasm-bindgen"
139
+version = "0.2.73"
140
+source = "registry+https://github.com/rust-lang/crates.io-index"
141
+checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9"
142
+dependencies = [
143
+ "cfg-if",
144
+ "wasm-bindgen-macro",
145
+]
146
+
147
+[[package]]
148
+name = "wasm-bindgen-backend"
149
+version = "0.2.73"
150
+source = "registry+https://github.com/rust-lang/crates.io-index"
151
+checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae"
152
+dependencies = [
153
+ "bumpalo",
154
+ "lazy_static",
155
+ "log",
156
+ "proc-macro2",
157
+ "quote",
158
+ "syn",
159
+ "wasm-bindgen-shared",
160
+]
161
+
162
+[[package]]
163
+name = "wasm-bindgen-macro"
164
+version = "0.2.73"
165
+source = "registry+https://github.com/rust-lang/crates.io-index"
166
+checksum = "3e734d91443f177bfdb41969de821e15c516931c3c3db3d318fa1b68975d0f6f"
167
+dependencies = [
168
+ "quote",
169
+ "wasm-bindgen-macro-support",
170
+]
171
+
172
+[[package]]
173
+name = "wasm-bindgen-macro-support"
174
+version = "0.2.73"
175
+source = "registry+https://github.com/rust-lang/crates.io-index"
176
+checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c"
177
+dependencies = [
178
+ "proc-macro2",
179
+ "quote",
180
+ "syn",
181
+ "wasm-bindgen-backend",
182
+ "wasm-bindgen-shared",
183
+]
184
+
185
+[[package]]
186
+name = "wasm-bindgen-shared"
187
+version = "0.2.73"
188
+source = "registry+https://github.com/rust-lang/crates.io-index"
189
+checksum = "d9a543ae66aa233d14bb765ed9af4a33e81b8b58d1584cf1b47ff8cd0b9e4489"

+ 4
- 2
Cargo.toml View File

@@ -4,10 +4,12 @@ version = "0.1.0"
4 4
 authors = ["Dylan Baker <dylan@simulacrum.party>"]
5 5
 edition = "2018"
6 6
 
7
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8
-
9 7
 [dependencies]
10 8
 lazy_static = "1.4.0"
11 9
 regex = "1.4.5"
12 10
 serde = "1.0.125"
13 11
 serde_json = "1.0.64"
12
+wasm-bindgen = "0.2.73"
13
+
14
+[lib]
15
+crate-type = ["cdylib"]

+ 2
- 0
Makefile View File

@@ -0,0 +1,2 @@
1
+elastic:
2
+	wasm-pack build --target web

+ 21
- 6
src/lib.rs View File

@@ -4,11 +4,26 @@ pub mod lexer;
4 4
 pub mod parser;
5 5
 pub mod token;
6 6
 
7
-use compiler::Query;
8
-use error::ElasticError;
7
+use wasm_bindgen::prelude::*;
9 8
 
10
-pub fn compile(input: &str) -> Result<Query, ElasticError> {
11
-    let tokens = lexer::scan(&input)?;
12
-    let select = parser::parse(tokens)?;
13
-    compiler::compile(select)
9
+#[wasm_bindgen]
10
+pub fn compile(input: &str) -> String {
11
+    let tokens = match lexer::scan(&input) {
12
+        Ok(tokens) => tokens,
13
+        Err(e) => return e.message,
14
+    };
15
+    let select = match parser::parse(tokens) {
16
+        Ok(select) => select,
17
+        Err(e) => return e.message,
18
+    };
19
+    let query = match compiler::compile(select) {
20
+        Ok(query) => query,
21
+        Err(e) => return e.message,
22
+    };
23
+
24
+    format!(
25
+        "GET /{}/_search\n{}",
26
+        query.source.name,
27
+        serde_json::to_string_pretty(&query.body).unwrap()
28
+    )
14 29
 }

Loading…
Cancel
Save