ruby_tree_sitter 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 550b12aa9a45d1a5ea207bde42277aec34d79b2c766486b21f6c351bc7399f19
4
- data.tar.gz: 723ccfe297603caf4eadba688ea9c952d48fe7b8a9dbbe061dc893dc8339fbe5
3
+ metadata.gz: e0488c0541ab1295e21de7a53a3af6bbfb0d2e5a2340874803037b00956e16e3
4
+ data.tar.gz: 9e5b5d202e3857ee5840322c1899684e12aa8469faa3c199f0cb8b1d1d183913
5
5
  SHA512:
6
- metadata.gz: 425e2f54efc9312dec9e70aea9ae5ce6a1531bc2a1de1a4e8d49f5d0ef90255f9f7e64a8ac34a4810c60a74063dcda3f481939a1936df17b5dd60ebfaeab0e5c
7
- data.tar.gz: a044a8b400406d875b40033e7f9070818c9505a3d7e5cdf86f07e78de03e6a5bd6bc2bdbe15c3fe8920c52cd0cc5fc33e65156432a3e15bdb3a5d67323833962
6
+ metadata.gz: b0d6108292ce09bed1aca0d83899df812019c5689901c762b0b8f54b951f68dc4256495b1e10ad2faf64523f0cfad7262fd07aad7dab1666d599a0453dd40b20
7
+ data.tar.gz: 6d84ad3d549c81a18a64509d826ae86d12bf90da60cdb0bcff40d5a85008c80ec309afe2d3190707601586d814f8a07ee919887f67c3103ebf352585b69b1e44
data/README.md CHANGED
@@ -68,12 +68,23 @@ TreeStand provides an idiomatic Ruby interface to work with tree-sitter parsers.
68
68
 
69
69
  ## Dependencies
70
70
 
71
- This gem is a binding for `tree-sitter`. It doesn't have a version of
72
- `tree-sitter` baked in it by default.
71
+ This gem is a binding for `tree-sitter`, and comes with a pre-built version
72
+ of `tree-sitter` bundled with it, so you can start using it without any
73
+ special configuration.
73
74
 
74
- You must install `tree-sitter` and make sure that their dynamic library is
75
- accessible from `$PATH`, or build the gem with `--disable-sys-libs`, which will
76
- download the latest tagged `tree-sitter` and build against it (see [Build from source](docs/Contributing.md#build-from-source) .)
75
+ We support the following platforms:
76
+
77
+ - `aarch64-linux-gnu`
78
+ - `aarch64-linux-musl`
79
+ - `arm-linux-gnu`
80
+ - `arm-linux-musl`
81
+ - `x86_64-linux-gnu`
82
+ - `x86_64-linux-musl`
83
+ - `x86-linux-musl`
84
+ - `arm64-darwin`
85
+ - `x86_64-darwin`
86
+
87
+ (see [Build from source](docs/Contributing.md#build-from-source)).
77
88
 
78
89
  You can either install `tree-sitter` from source or through your go-to package manager.
79
90
 
@@ -108,7 +119,7 @@ brew install tree-sitter
108
119
  From [rubygems](https://rubygems.org/gems/ruby_tree_sitter), in your `Gemfile`:
109
120
 
110
121
  ```ruby
111
- gem 'ruby_tree_sitter', '~> 1.0'
122
+ gem 'ruby_tree_sitter', '~> 1.6'
112
123
  ```
113
124
 
114
125
  Or manually:
@@ -123,18 +134,19 @@ Or from `git` sources, which will compile on installation:
123
134
  gem 'ruby_tree_sitter', git: 'https://github.com/Faveod/ruby-tree-sitter'
124
135
  ```
125
136
 
126
- ### Disable system libraries
137
+ ### Enable system libraries
127
138
 
128
- To install with `--disable-sys-lib`, you can either:
139
+ To install with `--enable-sys-libs`, you can either:
129
140
 
130
141
  ```sh
131
- gem install ruby_tree_sitter -- --disable-sys-libs
142
+ gem install ruby_tree_sitter --platform=ruby -- --enable-sys-libs
132
143
  ```
133
144
 
134
145
  Or via bundle:
135
146
 
136
147
  ```sh
137
- bundle config set build.ruby_tree_sitter --disable-sys-libs
148
+ bundle config force_ruby_platform true
149
+ bundle config set build.ruby_tree_sitter --enable-sys-libs
138
150
  ```
139
151
 
140
152
  ### No compilation
@@ -163,16 +175,6 @@ You will have to install parsers yourself, either by:
163
175
  [Faveod/tree-sitter-parsers](https://github.com/Faveod/tree-sitter-parsers)
164
176
  which supports numerous architectures.
165
177
 
166
- ### A note on static vs dynamic linking
167
-
168
- This extension will statically link against a downloaded version of
169
- `tree-sitter` when you use the `--disable-sys-lib`. So any installed version of
170
- `tree-sitter` will not be loaded.
171
-
172
- The native gems are also statically linked.
173
-
174
- All other methods will dynamically link against the installed `tree-sitter`.
175
-
176
178
  ## Examples
177
179
 
178
180
  See `examples` directory.
@@ -15,7 +15,7 @@ cflags = []
15
15
  ldflags = []
16
16
 
17
17
  def system_tree_sitter?
18
- enable_config('sys-libs', true)
18
+ enable_config('sys-libs', false)
19
19
  end
20
20
 
21
21
  def env_var_on?(var)
@@ -26,6 +26,8 @@ end
26
26
  # System lib vs Downloaded lib #
27
27
  # ################################## #
28
28
 
29
+ repo = TreeSitter::Repo.new
30
+
29
31
  dir_include, dir_lib =
30
32
  if system_tree_sitter?
31
33
  [
@@ -33,7 +35,6 @@ dir_include, dir_lib =
33
35
  %w[/opt/lib /opt/local/lib /usr/lib /usr/local/lib],
34
36
  ]
35
37
  else
36
- repo = TreeSitter::Repo.new
37
38
  if !repo.download
38
39
  msg = <<~MSG
39
40
 
@@ -48,19 +49,19 @@ dir_include, dir_lib =
48
49
  # We need to make sure we're selecting the proper toolchain.
49
50
  # Especially needed for corss-compilation.
50
51
  ENV.store('CC', RbConfig::CONFIG['CC'])
52
+ repo.patch
51
53
  repo.compile
52
- repo.keep_static_lib
53
54
  repo.include_and_lib_dirs
54
55
  end
55
56
 
57
+ dir_config('tree-sitter', dir_include&.first, dir_lib&.first)
58
+
56
59
  # ################################## #
57
60
  # Generate Makefile #
58
61
  # ################################## #
59
62
 
60
- header = find_header('tree_sitter/api.h', *dir_include)
61
- library = find_library('tree-sitter', # libtree-sitter
62
- 'ts_parser_new', # a symbol
63
- *dir_lib)
63
+ header = find_header('tree_sitter/api.h')
64
+ library = find_library('tree-sitter', 'ts_parser_new')
64
65
 
65
66
  if !header || !library
66
67
  abort <<~MSG
@@ -144,6 +145,5 @@ cflags.concat %w[-std=c99 -fPIC -Wall]
144
145
  append_cflags(cflags)
145
146
  append_ldflags(ldflags)
146
147
 
147
- dir_config('tree-sitter')
148
148
  create_header
149
149
  create_makefile('tree_sitter/tree_sitter')
@@ -29,7 +29,9 @@ module TreeSitter
29
29
  def compile
30
30
  # We need to clean because the same folder is used over and over
31
31
  # by rake-compiler-dock
32
- sh "cd #{src} && make clean && make"
32
+ ar = RbConfig::MAKEFILE_CONFIG['AR']
33
+ ar = " AR=#{ar}" if ar
34
+ sh "cd #{src} && make clean &&#{ar} make libtree-sitter.a"
33
35
  end
34
36
 
35
37
  def exe?(name)
@@ -59,14 +61,14 @@ module TreeSitter
59
61
  end
60
62
 
61
63
  def include_and_lib_dirs
62
- [[src / 'lib' / 'include'], [src.to_s]]
64
+ [[(src / 'lib' / 'include').to_s], [src.to_s]]
63
65
  end
64
66
 
65
- def keep_static_lib
66
- src
67
- .children
68
- .filter { |f| /\.(dylib|so)/ =~ f.basename.to_s }
69
- .each(&:unlink)
67
+ def patch
68
+ root = Pathname.new(File.expand_path(__dir__)).realpath.parent.parent
69
+ patch = root / 'patches' / 'cross-compile.patch'
70
+
71
+ sh "patch --forward #{src / 'Makefile'} #{patch}"
70
72
  end
71
73
 
72
74
  def sh(cmd)
@@ -98,9 +100,14 @@ module TreeSitter
98
100
  def sources_from_git
99
101
  return false if !exe?(:git)
100
102
 
101
- sh "git clone #{url[:git]} #{src}"
102
- sh "cd #{src} && git checkout tags/v#{version}"
103
-
103
+ sh <<~SHELL.chomp
104
+ mkdir #{src} \\
105
+ && cd #{src} \\
106
+ && git init \\
107
+ && git remote add origin "#{url[:git]}" \\
108
+ && git fetch origin --depth 1 tags/v#{version} \\
109
+ && git reset --hard FETCH_HEAD
110
+ SHELL
104
111
  true
105
112
  end
106
113
 
@@ -126,6 +126,7 @@ module TreeSitter
126
126
  def search_for_lib(name)
127
127
  files =
128
128
  [name, name.upcase, name.downcase]
129
+ .uniq
129
130
  .flat_map do |n|
130
131
  base = "#{n}.#{ext}"
131
132
  [base, "tree-sitter-#{base}", "libtree-sitter-#{base}"]
@@ -4,5 +4,5 @@ module TreeSitter
4
4
  # The version of the tree-sitter library.
5
5
  TREESITTER_VERSION = '0.22.6'
6
6
  # The current version of the gem.
7
- VERSION = '1.5.1'
7
+ VERSION = '1.6.0'
8
8
  end
data/lib/tree_sitter.rb CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
  require 'set'
4
4
 
5
- require 'tree_sitter/tree_sitter'
5
+ begin
6
+ RUBY_VERSION =~ /(\d+\.\d+)/
7
+ require "tree_sitter/#{Regexp.last_match(1)}/tree_sitter"
8
+ rescue LoadError
9
+ require 'tree_sitter/tree_sitter'
10
+ end
11
+
6
12
  require 'tree_sitter/version'
7
13
 
8
14
  require 'tree_sitter/mixins/language'
data/tree_sitter.gemspec CHANGED
@@ -17,7 +17,6 @@ Gem::Specification.new do |spec|
17
17
  spec.version = TreeSitter::VERSION
18
18
 
19
19
  spec.metadata = {
20
- 'allowed_push_host' => 'https://rubygems.org',
21
20
  'homepage_uri' => spec.homepage,
22
21
  'source_code_uri' => spec.homepage,
23
22
  'changelog_uri' => spec.homepage,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_tree_sitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firas al-Khalil
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-07-09 00:00:00.000000000 Z
12
+ date: 2024-08-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sorbet-runtime
@@ -103,7 +103,6 @@ homepage: https://www.github.com/Faveod/ruby-tree-sitter
103
103
  licenses:
104
104
  - MIT
105
105
  metadata:
106
- allowed_push_host: https://rubygems.org
107
106
  homepage_uri: https://www.github.com/Faveod/ruby-tree-sitter
108
107
  source_code_uri: https://www.github.com/Faveod/ruby-tree-sitter
109
108
  changelog_uri: https://www.github.com/Faveod/ruby-tree-sitter
@@ -123,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
122
  - !ruby/object:Gem::Version
124
123
  version: '0'
125
124
  requirements: []
126
- rubygems_version: 3.5.11
125
+ rubygems_version: 3.3.26
127
126
  signing_key:
128
127
  specification_version: 4
129
128
  summary: Ruby bindings for Tree-Sitter