rubydex 0.1.0.beta1-arm64-darwin

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/exe/rdx ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
5
+ require "optparse"
6
+
7
+ OptionParser.new do |parser|
8
+ parser.banner = "Usage: [path1, path2]"
9
+
10
+ parser.on("--version", "Print the gem's version") do
11
+ require "rubydex/version"
12
+ puts "v#{Rubydex::VERSION}"
13
+ exit
14
+ end
15
+
16
+ parser.on("-h", "--help", "Prints this help") do
17
+ puts parser
18
+ exit
19
+ end
20
+ end.parse!
21
+
22
+ require "rubydex"
23
+
24
+ workspace_path = ARGV.first
25
+
26
+ # If a workspace path is passed, we need to ensure that Bundler is setup in that context so that we find the
27
+ # dependencies for that project
28
+ if workspace_path
29
+ gemfile_path = File.join(workspace_path, "Gemfile")
30
+
31
+ if File.exist?(gemfile_path)
32
+ ENV["BUNDLE_GEMFILE"] = gemfile_path
33
+
34
+ begin
35
+ Bundler.setup
36
+ rescue Bundler::BundlerError => e
37
+ $stderr.puts(<<~MESSAGE)
38
+ Bundle setup failed for #{gemfile_path}. Indexing of dependencies may be partial
39
+ Error:
40
+ #{e.message}
41
+ MESSAGE
42
+ end
43
+ end
44
+ end
45
+
46
+ graph = Rubydex::Graph.new(workspace_path: workspace_path)
47
+ graph.index_workspace
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "pathname"
5
+
6
+ release = ENV["RELEASE"]
7
+ gem_dir = Pathname.new("../..").expand_path(__dir__)
8
+ root_dir = gem_dir.join("rust")
9
+ target_dir = root_dir.join("target")
10
+ target_dir = target_dir.join("x86_64-pc-windows-gnu") if Gem.win_platform?
11
+ target_dir = target_dir.join(release ? "release" : "debug")
12
+
13
+ bindings_path = root_dir.join("rubydex-sys").join("rustbindings.h")
14
+
15
+ cargo_args = ["--manifest-path #{root_dir.join("Cargo.toml")}"]
16
+ cargo_args << "--release" if release
17
+
18
+ if Gem.win_platform?
19
+ cargo_args << "--target x86_64-pc-windows-gnu"
20
+ ENV["RUSTFLAGS"] = "-C target-feature=+crt-static"
21
+ end
22
+
23
+ append_cflags("-Werror=unused-but-set-variable")
24
+ append_cflags("-Werror=implicit-function-declaration")
25
+
26
+ if Gem.win_platform?
27
+ $LDFLAGS << " #{target_dir.join("librubydex_sys.a")}"
28
+
29
+ # On Windows, statically link system libraries to avoid having to distribute and load DLLs
30
+ #
31
+ # These libraries are the ones informed by `cargo rustc -- --print native-static-libs`, which displays the
32
+ # libraries necessary for statically linking the Rust code on the current platform
33
+ ["kernel32", "ntdll", "userenv", "ws2_32", "dbghelp", "msvcrt"].each do |lib|
34
+ $LDFLAGS << " -l#{lib}"
35
+ end
36
+ else
37
+ append_ldflags("-Wl,-rpath,#{target_dir}")
38
+ # We cannot use append_ldflags here because the Rust code is only compiled later. If it's not compiled yet, this will
39
+ # fail and the flag will not be added
40
+ $LDFLAGS << " -L#{target_dir} -lrubydex_sys"
41
+ end
42
+
43
+ create_makefile("rubydex/rubydex")
44
+
45
+ cargo_command = if ENV["SANITIZER"]
46
+ ENV["RUSTFLAGS"] = "-Zsanitizer=#{ENV["SANITIZER"]}"
47
+ "cargo +nightly build -Zbuild-std #{cargo_args.join(" ")}".strip
48
+ else
49
+ "cargo build #{cargo_args.join(" ")}".strip
50
+ end
51
+
52
+ rust_srcs = Dir.glob("#{root_dir}/**/*.rs")
53
+
54
+ makefile = File.read("Makefile")
55
+ new_makefile = makefile.gsub("$(OBJS): $(HDRS) $(ruby_headers)", <<~MAKEFILE.chomp)
56
+ .PHONY: compile_rust
57
+ RUST_SRCS = #{File.expand_path("Cargo.toml", root_dir)} #{File.expand_path("Cargo.lock", root_dir)} #{rust_srcs.join(" ")}
58
+
59
+ .rust_built: $(RUST_SRCS)
60
+ \t#{cargo_command} || (echo "Compiling Rust failed" && exit 1)
61
+ \t$(COPY) #{bindings_path} #{__dir__}
62
+ \ttouch $@
63
+
64
+ compile_rust: .rust_built
65
+
66
+ $(OBJS): $(HDRS) $(ruby_headers) .rust_built
67
+ MAKEFILE
68
+
69
+ new_makefile.gsub!("$(Q) $(POSTLINK)", <<~MAKEFILE.chomp)
70
+ $(Q) $(POSTLINK)
71
+ \t$(Q)$(RM) .rust_built
72
+ MAKEFILE
73
+
74
+ # Bundle all dependency licenses when building a release version of the gem
75
+ if release
76
+ unless system("cargo about --version > /dev/null 2>&1")
77
+ abort <<~MESSAGE
78
+ ERROR: cargo-about is not installed and required to build the release version of the gem.
79
+ Please install it by running:
80
+ cargo install cargo-about
81
+ MESSAGE
82
+ end
83
+
84
+ licenses_file = root_dir.join("THIRD_PARTY_LICENSES.html")
85
+ about_config = root_dir.join("about.toml")
86
+ about_template = root_dir.join("about.hbs")
87
+
88
+ new_makefile.gsub!(".rust_built: $(RUST_SRCS)", <<~MAKEFILE.chomp)
89
+ #{licenses_file}: #{about_config} #{about_template}
90
+ \t$(Q)$(RM) #{licenses_file}
91
+ \tcargo about generate #{about_template} --manifest-path #{root_dir.join("Cargo.toml")} --workspace > #{licenses_file}
92
+ \t$(COPY) #{licenses_file} #{gem_dir}
93
+
94
+ .rust_built: $(RUST_SRCS) #{licenses_file}
95
+ MAKEFILE
96
+ end
97
+
98
+ File.write("Makefile", new_makefile)
99
+
100
+ begin
101
+ require "extconf_compile_commands_json"
102
+
103
+ ExtconfCompileCommandsJson.generate!
104
+ ExtconfCompileCommandsJson.symlink!
105
+ rescue LoadError # rubocop:disable Lint/SuppressedException
106
+ end
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubydex
4
+ class Comment
5
+ #: String
6
+ attr_reader :string
7
+
8
+ #: Location
9
+ attr_reader :location
10
+
11
+ #: (?string: String, ?location: Location) -> void
12
+ def initialize(string:, location:)
13
+ @string = string
14
+ @location = location
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubydex
4
+ class Diagnostic
5
+ #: Symbol
6
+ attr_reader :rule
7
+
8
+ #: String
9
+ attr_reader :message
10
+
11
+ #: Location
12
+ attr_reader :location
13
+
14
+ #: (rule: Symbol, message: String, location: Location) -> void
15
+ def initialize(rule:, message:, location:)
16
+ @rule = rule
17
+ @message = message
18
+ @location = location
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubydex
4
+ # The global graph representing all declarations and their relationships for the workspace
5
+ #
6
+ # Note: this class is partially defined in C to integrate with the Rust backend
7
+ class Graph
8
+ #: (?workspace_path: String) -> void
9
+ def initialize(workspace_path: Dir.pwd)
10
+ @workspace_path = workspace_path
11
+ end
12
+
13
+ # Index all files and dependencies of the workspace that exists in `@workspace_path`
14
+ #: -> String?
15
+ def index_workspace
16
+ paths = Dir.glob("#{@workspace_path}/**/*.rb")
17
+ paths.concat(
18
+ workspace_dependency_paths.flat_map do |path|
19
+ Dir.glob("#{path}/**/*.rb")
20
+ end,
21
+ )
22
+ index_all(paths)
23
+ end
24
+
25
+ private
26
+
27
+ # Gathers the paths we have to index for all workspace dependencies
28
+ def workspace_dependency_paths
29
+ specs = Bundler.locked_gems&.specs
30
+ return [] unless specs
31
+
32
+ paths = specs.filter_map do |lazy_spec|
33
+ spec = Gem::Specification.find_by_name(lazy_spec.name)
34
+ spec.require_paths.map { |path| File.join(spec.full_gem_path, path) }
35
+ rescue Gem::MissingSpecError
36
+ nil
37
+ end
38
+
39
+ paths.flatten!
40
+ paths.uniq!
41
+ paths
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubydex
4
+ class Location
5
+ include Comparable
6
+
7
+ #: String
8
+ attr_reader :uri
9
+
10
+ #: Integer
11
+ attr_reader :start_line, :end_line, :start_column, :end_column
12
+
13
+ #: (?uri: String, ?start_line: Integer, ?end_line: Integer, ?start_column: Integer, ?end_column: Integer) -> void
14
+ def initialize(uri:, start_line:, end_line:, start_column:, end_column:)
15
+ @uri = uri
16
+ @start_line = start_line
17
+ @end_line = end_line
18
+ @start_column = start_column
19
+ @end_column = end_column
20
+ end
21
+
22
+ #: () -> String
23
+ def path
24
+ uri = URI(@uri)
25
+ raise Rubydex::Error, "URI is not a file:// URI: #{@uri}" unless uri.scheme == "file"
26
+
27
+ path = uri.path
28
+ # TODO: This has to go away once we have a proper URI abstraction
29
+ path.delete_prefix!("/") if Gem.win_platform?
30
+ path
31
+ end
32
+
33
+ #: (other: BasicObject) -> Integer
34
+ def <=>(other)
35
+ return -1 unless other.is_a?(Location)
36
+
37
+ a = [@uri, @start_line, @start_column, @end_line, @end_column]
38
+ b = [other.uri, other.start_line, other.start_column, other.end_line, other.end_column]
39
+ a <=> b
40
+ end
41
+
42
+ #: -> String
43
+ def to_s
44
+ "#{path}:#{@start_line}:#{@start_column}-#{@end_line}:#{@end_column}"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubydex
4
+ VERSION = "0.1.0.beta1"
5
+ end
data/lib/rubydex.rb ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler"
4
+ require "uri"
5
+
6
+ module Rubydex
7
+ class Error < StandardError; end
8
+ end
9
+
10
+ require "rubydex/version"
11
+
12
+ begin
13
+ # Load the precompiled version of the library
14
+ ruby_version = /(\d+\.\d+)/.match(RUBY_VERSION)
15
+ require "rubydex/#{ruby_version}/rubydex"
16
+ rescue LoadError
17
+ # It's important to leave for users that can not or don't want to use the gem with precompiled binaries.
18
+ require "rubydex/rubydex"
19
+ end
20
+
21
+ require "rubydex/location"
22
+ require "rubydex/comment"
23
+ require "rubydex/diagnostic"
24
+ require "rubydex/graph"
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubydex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.beta1
5
+ platform: arm64-darwin
6
+ authors:
7
+ - Shopify
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-01-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A high performance static analysis suite for Ruby, built in Rust with
14
+ Ruby APIs
15
+ email:
16
+ - ruby@shopify.com
17
+ executables:
18
+ - rdx
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - LICENSE.txt
23
+ - README.md
24
+ - THIRD_PARTY_LICENSES.html
25
+ - exe/rdx
26
+ - ext/rubydex/extconf.rb
27
+ - lib/rubydex.rb
28
+ - lib/rubydex/3.2/rubydex.bundle
29
+ - lib/rubydex/3.3/rubydex.bundle
30
+ - lib/rubydex/3.4/rubydex.bundle
31
+ - lib/rubydex/4.0/rubydex.bundle
32
+ - lib/rubydex/comment.rb
33
+ - lib/rubydex/diagnostic.rb
34
+ - lib/rubydex/graph.rb
35
+ - lib/rubydex/location.rb
36
+ - lib/rubydex/version.rb
37
+ homepage: https://github.com/Shopify/rubydex
38
+ licenses:
39
+ - MIT
40
+ metadata:
41
+ allowed_push_host: https://rubygems.org
42
+ homepage_uri: https://github.com/Shopify/rubydex
43
+ source_code_uri: https://github.com/Shopify/rubydex
44
+ changelog_uri: https://github.com/Shopify/rubydex/releases
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '3.2'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: 4.1.dev
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.3.11
62
+ requirements: []
63
+ rubygems_version: 3.4.19
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: A high performance static analysis suite for Ruby
67
+ test_files: []