-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
47 lines (36 loc) · 1.16 KB
/
Copy pathRakefile
File metadata and controls
47 lines (36 loc) · 1.16 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
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "shellwords"
RSpec::Core::RakeTask.new(:spec)
task default: %i[compile spec]
desc "Compile the Rust extension"
task :compile do
# Set up Ruby environment for linking
require "rbconfig"
profile = ENV.fetch("CARGO_PROFILE", "release")
manifest_path = File.join(__dir__, "Cargo.toml")
lib_dir = File.join(__dir__, "lib", "mq")
FileUtils.mkdir_p(lib_dir)
sh "cargo build --manifest-path #{manifest_path} --release"
# Find the built library
target_dir = File.join(__dir__, "target", profile)
ext_name = RbConfig::CONFIG["DLEXT"]
# Copy the library to lib/mq
found = false
Dir.glob(File.join(target_dir, "libmq_ruby.{so,dylib,dll}")).each do |lib|
dest = File.join(lib_dir, "mq_ruby.#{ext_name}")
FileUtils.cp(lib, dest)
puts "Copied #{lib} to #{dest}"
found = true
end
unless found
warn "Warning: Could not find compiled library"
end
end
desc "Clean build artifacts"
task :clean do
sh "cargo clean --manifest-path #{__dir__}/Cargo.toml" rescue nil
FileUtils.rm_f(Dir.glob("lib/mq/*.{so,dylib,dll,bundle}"))
end
task clobber: :clean