Fix include_bytes error when building cli outside of source tree
Refs #1523
This commit is contained in:
parent
2032133f8a
commit
836d753c73
1 changed files with 10 additions and 9 deletions
|
|
@ -10,8 +10,9 @@ use std::{
|
|||
use tiny_http::{Header, Response, Server};
|
||||
use webbrowser;
|
||||
|
||||
macro_rules! resource {
|
||||
macro_rules! optional_resource {
|
||||
($name: tt, $path: tt) => {
|
||||
#[cfg(TREE_SITTER_EMBED_WASM_BINDING)]
|
||||
fn $name(tree_sitter_dir: &Option<PathBuf>) -> Cow<'static, [u8]> {
|
||||
if let Some(tree_sitter_dir) = tree_sitter_dir {
|
||||
Cow::Owned(fs::read(tree_sitter_dir.join($path)).unwrap())
|
||||
|
|
@ -19,13 +20,6 @@ macro_rules! resource {
|
|||
Cow::Borrowed(include_bytes!(concat!("../../", $path)))
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! optional_resource {
|
||||
($name: tt, $path: tt) => {
|
||||
#[cfg(TREE_SITTER_EMBED_WASM_BINDING)]
|
||||
resource!($name, $path);
|
||||
|
||||
#[cfg(not(TREE_SITTER_EMBED_WASM_BINDING))]
|
||||
fn $name(tree_sitter_dir: &Option<PathBuf>) -> Cow<'static, [u8]> {
|
||||
|
|
@ -38,11 +32,18 @@ macro_rules! optional_resource {
|
|||
};
|
||||
}
|
||||
|
||||
resource!(get_main_html, "cli/src/playground.html");
|
||||
optional_resource!(get_playground_js, "docs/assets/js/playground.js");
|
||||
optional_resource!(get_lib_js, "lib/binding_web/tree-sitter.js");
|
||||
optional_resource!(get_lib_wasm, "lib/binding_web/tree-sitter.wasm");
|
||||
|
||||
fn get_main_html(tree_sitter_dir: &Option<PathBuf>) -> Cow<'static, [u8]> {
|
||||
if let Some(tree_sitter_dir) = tree_sitter_dir {
|
||||
Cow::Owned(fs::read(tree_sitter_dir.join("cli/src/playground.html")).unwrap())
|
||||
} else {
|
||||
Cow::Borrowed(include_bytes!("playground.html"))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn serve(grammar_path: &Path, open_in_browser: bool) {
|
||||
let port = get_available_port().expect("Couldn't find an available port");
|
||||
let addr = format!("127.0.0.1:{}", port);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue