Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit

Permalink
Use wasm-bindgen
Browse files Browse the repository at this point in the history
  • Loading branch information
noClaps committed Jan 4, 2025
1 parent 839baba commit f6397e1
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 172 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/build-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ jobs:
sudo apt install clang llvm gcc-multilib -y
export CC=clang
export CXX=clang++
- run: rustup target add wasm32-wasip1-threads
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: cargo install wasm-pack
- run: |
mkdir dist
bun run build --target wasm32-wasip1-threads
wasm-pack build --release -d ./dist
- uses: actions/upload-artifact@v4
with:
path: dist
188 changes: 47 additions & 141 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 1 addition & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
napi = { version = "3.0.0-alpha.24", default-features = false, features = [
"napi8",
] }
napi-derive = { version = "3.0.0-alpha.22", default-features = false, features = [
"type-def",
] }
tree-sitter-agda = "1.3.3"
tree-sitter-bash = "0.23.3"
tree-sitter-c = "0.23.4"
Expand All @@ -33,10 +27,4 @@ tree-sitter-ruby = "0.23.1"
tree-sitter-rust = "0.23.2"
tree-sitter-scala = "0.23.4"
tree-sitter-typescript = "0.23.2"

[build-dependencies]
napi-build = "2.1.4"

[profile.release]
lto = true
strip = "symbols"
wasm-bindgen = "0.2.99"
5 changes: 0 additions & 5 deletions build.rs

This file was deleted.

7 changes: 0 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@
"README.md",
"package.json"
],
"napi": {
"binaryName": "highlight",
"targets": [
"wasm32-wasip1-threads"
]
},
"scripts": {
"build": "napi build --platform --release --strip -o ./dist",
"bump": "bunx changelogen --bump && bun bump-version.ts"
},
"type": "module"
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use napi_derive::napi;
use tree_sitter_highlight::{Highlight, HighlightConfiguration, Highlighter, HtmlRenderer};
use wasm_bindgen::prelude::*;

fn get_highlight_query(language: String) -> String {
let cpp = format!(
Expand Down Expand Up @@ -116,7 +116,7 @@ fn get_language(language: String) -> HighlightConfiguration {
.unwrap()
}

#[napi]
#[wasm_bindgen]
pub fn highlight(highlight_names: Vec<String>, language: String, code: String) -> String {
let mut highlighter = Highlighter::new();

Expand Down

0 comments on commit f6397e1

Please sign in to comment.