Module: ChDB::ExtConf

Defined in:
ext/chdb/extconf.rb

Class Method Summary collapse

Class Method Details

.abort_could_not_find(missing) ⇒ Object



56
57
58
59
60
61
62
# File 'ext/chdb/extconf.rb', line 56

def abort_could_not_find(missing)
  message = "    Could not find \#{missing}.\n    Please visit https://github.com/chdb-io/chdb-ruby for installation instructions.\n  MSG\n  abort(\"\\n\#{message}\\n\")\nend\n"

.compiled?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'ext/chdb/extconf.rb', line 21

def compiled?
  return false if cross_build?

  major_version = RUBY_VERSION.match(/(\d+\.\d+)/)[1]
  version_dir = File.join(package_root_dir, 'lib', 'chdb', major_version)

  extension = if determine_target_platform.include?('darwin')
                'bundle'
              else
                'so'
              end
  lib_file = "#{libname}.#{extension}"

  File.exist?(File.join(version_dir, lib_file))
end

.configureObject



11
12
13
14
15
16
17
18
19
# File 'ext/chdb/extconf.rb', line 11

def configure
  configure_cross_compiler

  download_and_extract

  configure_extension

  create_makefile('chdb/chdb_native')
end

.configure_cross_compilerObject



37
38
39
40
# File 'ext/chdb/extconf.rb', line 37

def configure_cross_compiler
  RbConfig::CONFIG['CC'] = RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
  ENV['CC'] = RbConfig::CONFIG['CC']
end

.configure_extensionObject



50
51
52
53
54
# File 'ext/chdb/extconf.rb', line 50

def configure_extension
  include_path = File.expand_path('ext/chdb/include', package_root_dir)
  append_cppflags("-I#{include_path}")
  abort_could_not_find('chdb.h') unless find_header('chdb.h', include_path)
end

.cross_build?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'ext/chdb/extconf.rb', line 42

def cross_build?
  enable_config('cross-build')
end

.download_and_extractObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'ext/chdb/extconf.rb', line 64

def download_and_extract
  target_platform = determine_target_platform
  version = fetch_chdb_version
  download_dir = determine_download_directory(target_platform, version)
  need_download = false

  if Dir.exist?(download_dir)
    required_files = [
      File.join(download_dir, 'chdb.h'),
      File.join(download_dir, 'libchdb.so')
    ]

    need_download = !required_files.all? { |f| File.exist?(f) }
    if need_download
      puts 'Missing required files, cleaning download directory...'
      FileUtils.rm_rf(Dir.glob("#{download_dir}/*"))
    end
  else
    FileUtils.mkdir_p(download_dir)
    need_download = true
  end

  if need_download
    file_name = get_file_name(target_platform)
    url = build_download_url(version, file_name)
    download_tarball(url, download_dir, file_name)
    extract_tarball(download_dir, file_name)
  end

  copy_files(download_dir, version)
end

.libnameObject



46
47
48
# File 'ext/chdb/extconf.rb', line 46

def libname
  'chdb_native'
end