Allow building the wasm libs with native emscripten instead of docker

And build them on the mac CI as well as the linux CI
This commit is contained in:
Max Brunsfeld 2019-05-14 11:12:56 -07:00
parent a1ed12f4f4
commit ad43b211f4
7 changed files with 200 additions and 83 deletions

View file

@ -9,7 +9,7 @@ use webbrowser;
const PLAYGROUND_JS: &'static [u8] = include_bytes!("../../docs/assets/js/playground.js");
const LIB_JS: &'static [u8] = include_bytes!("../../lib/binding_web/tree-sitter.js");
const LIB_WASM: &'static [u8] = include_bytes!("../../lib/binding_web/tree-sitter.wasm");
const HTML: &'static [u8] = include_bytes!("./web_ui.html");
const HTML: &'static str = include_str!("./web_ui.html");
pub fn serve(grammar_path: &Path) {
let port = get_available_port().expect("Couldn't find an available port");
@ -18,19 +18,28 @@ pub fn serve(grammar_path: &Path) {
let grammar_name = wasm::get_grammar_name(&grammar_path.join("src"))
.map_err(|e| format!("Failed to get wasm filename: {:?}", e))
.unwrap();
let language_wasm = fs::read(format!("./tree-sitter-{}.wasm", grammar_name)).unwrap();
let wasm_filename = format!("tree-sitter-{}.wasm", grammar_name);
let language_wasm = fs::read(grammar_path.join(&wasm_filename))
.map_err(|_| {
format!(
"Failed to read '{}'. Run `tree-sitter build-wasm` first.",
wasm_filename
)
})
.unwrap();
webbrowser::open(&format!("http://127.0.0.1:{}", port))
.map_err(|e| format!("Failed to open '{}' in a web browser. Error: {}", url, e))
.unwrap();
let html = HTML.replace("THE_LANGUAGE_NAME", &grammar_name);
let html_header = Header::from_str("Content-type: text/html").unwrap();
let js_header = Header::from_str("Content-type: application/javascript").unwrap();
let wasm_header = Header::from_str("Content-type: application/wasm").unwrap();
for request in server.incoming_requests() {
let (body, header) = match request.url() {
"/" => (HTML, &html_header),
"/" => (html.as_ref(), &html_header),
"/playground.js" => (PLAYGROUND_JS, &js_header),
"/tree-sitter.js" => (LIB_JS, &js_header),
"/tree-sitter.wasm" => (LIB_WASM, &wasm_header),