Bläddra i källkod

add zig bindings and build

pull/364/head
Nikutsuki 2 veckor sedan
förälder
incheckning
a95b63deb1
5 ändrade filer med 60 tillägg och 4 borttagningar
  1. +10
    -4
      .gitignore
  2. +5
    -0
      bindings/zig/root.zig
  3. +16
    -0
      bindings/zig/test.zig
  4. +20
    -0
      build.zig
  5. +9
    -0
      build.zig.zon

+ 10
- 4
.gitignore Visa fil

@ -1,13 +1,16 @@
# Rust artifacts
target/
Cargo.lock
# Node artifacts
build/
prebuilds/
node_modules/
package-lock.json
# Swift artifacts
.build/
Package.resolved
# Go artifacts
_obj/
@ -25,6 +28,13 @@ dist/
*.dylib
*.dll
*.pc
*.exp
*.lib
# Zig artifacts
.zig-cache/
zig-cache/
zig-out/
# Example dirs
/examples/*/
@ -38,7 +48,3 @@ dist/
*.tar.gz
*.tgz
*.zip
# Zig artifacts
zig-out/
.zig-cache/

+ 5
- 0
bindings/zig/root.zig Visa fil

@ -0,0 +1,5 @@
extern fn tree_sitter_cpp() callconv(.c) *const anyopaque;
pub fn language() *const anyopaque {
return tree_sitter_cpp();
}

+ 16
- 0
bindings/zig/test.zig Visa fil

@ -0,0 +1,16 @@
const testing = @import("std").testing;
const ts = @import("tree-sitter");
const root = @import("tree-sitter-cpp");
const Parser = ts.Parser;
test "can load grammar" {
const parser = Parser.create();
defer parser.destroy();
const lang: *const ts.Language = @ptrCast(root.language());
defer lang.destroy();
try testing.expectEqual(void{}, parser.setLanguage(lang));
try testing.expectEqual(lang, parser.getLanguage());
}

+ 20
- 0
build.zig Visa fil

@ -44,4 +44,24 @@ pub fn build(b: *std.Build) void {
.install_subdir = "queries",
.include_extensions = &.{"scm"},
});
const module = b.addModule(library_name, .{
.root_source_file = b.path("bindings/zig/root.zig"),
.target = target,
.optimize = optimize,
});
module.linkLibrary(lib);
const tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("bindings/zig/test.zig"),
.target = target,
.optimize = optimize,
}),
});
tests.root_module.addImport(library_name, module);
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_tests.step);
}

+ 9
- 0
build.zig.zon Visa fil

@ -3,11 +3,20 @@
.fingerprint = 0xb8f4bd40e27ed859,
.minimum_zig_version = "0.16.0",
.version = "0.23.4",
.dependencies = .{
.tree_sitter = .{
.url = "git+https://github.com/tree-sitter/zig-tree-sitter#b4b72c903e69998fc88e27e154a5e3cc9166551b",
.hash = "tree_sitter-0.25.0-8heIf51vAQConvVIgvm-9mVIbqh7yabZYqPXfOpS3YoG",
.lazy = true,
},
},
.paths = .{
"build.zig",
"build.zig.zon",
"bindings/zig",
"src",
"queries",
"LICENSE",
},
}

Laddar…
Avbryt
Spara