-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRakefile
More file actions
82 lines (68 loc) · 2.39 KB
/
Rakefile
File metadata and controls
82 lines (68 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# frozen_string_literal: true
require 'bundler/gem_tasks'
require 'fileutils'
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
rescue LoadError
# RSpec not available, skip test tasks
desc 'Run tests (requires rspec gem)'
task :spec do
puts 'RSpec not available. Install with: gem install rspec'
end
end
desc 'Download pre-built C library binary from GitHub releases'
task :download_binary do
require_relative 'lib/jsonstructure/binary_installer'
installer = JsonStructure::BinaryInstaller.new
installer.install
end
desc 'Build the C library locally (for development only)'
task :build_c_lib_local do
puts 'Building C library locally...'
c_dir = File.expand_path('../c', __dir__)
unless Dir.exist?(c_dir)
puts 'C library source not found. Skipping local build.'
puts 'This is normal when installing from a gem.'
next
end
build_dir = File.join(c_dir, 'build')
Dir.mkdir(build_dir) unless Dir.exist?(build_dir)
Dir.chdir(build_dir) do
system('cmake', '..', '-DCMAKE_BUILD_TYPE=Release', '-DJS_BUILD_SHARED=ON', '-DJS_BUILD_TESTS=OFF', '-DJS_BUILD_EXAMPLES=OFF') || raise('CMake configuration failed')
system('cmake', '--build', '.') || raise('Build failed')
end
# Copy to ext directory
ext_dir = File.expand_path('ext', __dir__)
FileUtils.mkdir_p(ext_dir)
lib_name = case RbConfig::CONFIG['host_os']
when /darwin|mac os/
'libjson_structure.dylib'
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
'json_structure.dll'
else
'libjson_structure.so'
end
src = File.join(build_dir, lib_name)
dst = File.join(ext_dir, lib_name)
FileUtils.cp(src, dst) if File.exist?(src)
puts 'C library built successfully!'
end
desc 'Run tests (downloads binary first if needed, falls back to local build for development)'
task :test do
# Try to download binary first
begin
Rake::Task[:download_binary].invoke
rescue StandardError => e
puts "Binary download failed: #{e.message}"
puts "Attempting local build for development..."
begin
Rake::Task[:build_c_lib_local].invoke
rescue StandardError => build_error
puts "Local build also failed: #{build_error.message}"
raise "Cannot obtain C library binary. Please check the error messages above."
end
end
Rake::Task[:spec].invoke
end
task default: :test