You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once we have prepared the tool and the grammar, we can compile the parser as dynamic library.
53
+
_`tree-sitter-cli` is the preferred way to compile dynamic library._
53
54
54
-
There are no official instructions on how to do this on the internet, but we can get some hints from Tree-sitter's [source code](https://github.com/tree-sitter/tree-sitter/blob/a62bac5370dc5c76c75935834ef083457a6dd0e1/cli/loader/src/lib.rs#L111).
55
-
56
-
One way is to set an environment variable called `TREE_SITTER_LIBDIR` to the path where you want to store the dynamic library, and then run `tree-sitter test` in the directory of your custom language parser.
57
-
58
-
This will generate a dynamic library at the `TREE_SITTER_LIBDIR` path.
59
-
60
-
For example:
55
+
The [official way](https://tree-sitter.github.io/tree-sitter/cli/build.html) to compile a parser as a dynamic library is to use the `tree-sitter build` command.
61
56
62
57
```sh
63
-
cd path/to/mojo/parser
64
-
export TREE_SITTER_LIBDIR=path/to/your/dir
65
-
tree-sitter test
58
+
tree-sitter build --output mojo.so
66
59
```
67
60
61
+
The build command compiles your parser into a dynamically-loadable library as a shared object (.so, .dylib, or .dll).
62
+
63
+
68
64
Another way is to use the following [commands](https://github.com/tree-sitter/tree-sitter/blob/a62bac5370dc5c76c75935834ef083457a6dd0e1/cli/loader/src/lib.rs#L380-L410) to compile the parser manually:
69
65
70
66
```shell
@@ -79,8 +75,21 @@ For example, in mojo's case, the full command will be:
`tree-sitter-cli` is the preferred way to compile dynamic library.
78
+
:::details Old tree-sitter does not have build command
79
+
80
+
[Previously](https://github.com/tree-sitter/tree-sitter/pull/3174) there are no official instructions on how to do this on the internet, but we can get some hints from Tree-sitter's [source code](https://github.com/tree-sitter/tree-sitter/blob/a62bac5370dc5c76c75935834ef083457a6dd0e1/cli/loader/src/lib.rs#L111).
81
+
82
+
One way is to set an environment variable called `TREE_SITTER_LIBDIR` to the path where you want to store the dynamic library, and then run `tree-sitter test` in the directory of your custom language parser.
83
+
84
+
This will generate a dynamic library at the `TREE_SITTER_LIBDIR` path.
0 commit comments