zvec-ruby 0.1.0

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.
@@ -0,0 +1,100 @@
1
+ require "mkmf-rice"
2
+
3
+ # Find zvec installation
4
+ zvec_dir = ENV["ZVEC_DIR"]
5
+
6
+ if zvec_dir
7
+ zvec_include = File.join(zvec_dir, "src", "include")
8
+ zvec_lib = File.join(zvec_dir, "build", "lib")
9
+ zvec_ext_lib = File.join(zvec_dir, "build", "external", "usr", "local", "lib")
10
+
11
+ unless File.directory?(zvec_include)
12
+ zvec_include = File.join(zvec_dir, "include")
13
+ end
14
+ unless File.directory?(zvec_lib)
15
+ zvec_lib = File.join(zvec_dir, "lib")
16
+ end
17
+
18
+ dir_config("zvec", zvec_include, zvec_lib)
19
+ $INCFLAGS << " -I#{zvec_include}"
20
+ $LDFLAGS << " -L#{zvec_lib}"
21
+ $LDFLAGS << " -L#{zvec_ext_lib}" if File.directory?(zvec_ext_lib)
22
+
23
+ # Also add thirdparty include paths for transitive headers
24
+ thirdparty = File.join(zvec_dir, "thirdparty")
25
+ if File.directory?(thirdparty)
26
+ # rocksdb headers
27
+ rocksdb_inc = File.join(thirdparty, "rocksdb", "include")
28
+ $INCFLAGS << " -I#{rocksdb_inc}" if File.directory?(rocksdb_inc)
29
+ end
30
+ # Arrow/external headers from build
31
+ ext_inc = File.join(zvec_dir, "build", "external", "usr", "local", "include")
32
+ $INCFLAGS << " -I#{ext_inc}" if File.directory?(ext_inc)
33
+ elsif pkg_config("zvec")
34
+ # pkg-config found it
35
+ else
36
+ # Try common install paths
37
+ ["/usr/local", "/opt/homebrew", "/usr"].each do |prefix|
38
+ inc = File.join(prefix, "include")
39
+ lib = File.join(prefix, "lib")
40
+ if File.exist?(File.join(inc, "zvec", "db", "collection.h"))
41
+ $INCFLAGS << " -I#{inc}"
42
+ $LDFLAGS << " -L#{lib}"
43
+ break
44
+ end
45
+ end
46
+ end
47
+
48
+ $CXXFLAGS << " -std=c++17"
49
+
50
+ have_header("zvec/db/collection.h") or
51
+ abort "Cannot find zvec headers. Set ZVEC_DIR or install zvec system-wide."
52
+
53
+ # zvec is composed of multiple static libraries that must be linked in order
54
+ ZVEC_LIBS = %w[
55
+ zvec_db
56
+ zvec_sqlengine
57
+ zvec_index
58
+ zvec_common
59
+ zvec_core
60
+ zvec_proto
61
+ zvec_ailego
62
+ ]
63
+
64
+ THIRDPARTY_LIBS = %w[
65
+ rocksdb
66
+ roaring
67
+ arrow
68
+ arrow_compute
69
+ arrow_acero
70
+ arrow_dataset
71
+ parquet
72
+ arrow_bundled_dependencies
73
+ antlr4-runtime
74
+ protobuf
75
+ glog
76
+ gflags_nothreads
77
+ lz4
78
+ ]
79
+
80
+ # Libraries with static initializers (metric/index registration) need force-loading
81
+ FORCE_LOAD_LIBS = %w[zvec_core zvec_index]
82
+
83
+ if RUBY_PLATFORM =~ /darwin/ && defined?(zvec_lib)
84
+ force_flags = FORCE_LOAD_LIBS.map do |l|
85
+ path = File.join(zvec_lib, "lib#{l}.a")
86
+ File.exist?(path) ? "-force_load #{path}" : "-l#{l}"
87
+ end
88
+ normal_libs = (ZVEC_LIBS - FORCE_LOAD_LIBS)
89
+ $libs << " " + force_flags.join(" ")
90
+ $libs << " " + normal_libs.map { |l| "-l#{l}" }.join(" ")
91
+ else
92
+ $libs << " -Wl,--whole-archive"
93
+ $libs << " " + FORCE_LOAD_LIBS.map { |l| "-l#{l}" }.join(" ")
94
+ $libs << " -Wl,--no-whole-archive"
95
+ $libs << " " + (ZVEC_LIBS - FORCE_LOAD_LIBS).map { |l| "-l#{l}" }.join(" ")
96
+ end
97
+ $libs << " " + THIRDPARTY_LIBS.map { |l| "-l#{l}" }.join(" ")
98
+ $libs << " -lz -lpthread -ldl -lc++"
99
+
100
+ create_makefile("zvec/zvec_ext")