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
|
# File 'lib/cmdstan/install.rb', line 14
def install_cmdstan
version = cmdstan_version
dir = CmdStan.path
if RbConfig::CONFIG["host_os"] !~ /darwin/i && RbConfig::CONFIG["host_cpu"] =~ /arm|aarch64/i
checksum = "87ea47f0576d581f0af7e3c1a2f9843d16a9c7b21ed94621c906f7a3183b410d"
url = "https://github.com/stan-dev/cmdstan/releases/download/v#{version}/cmdstan-#{version}-linux-arm64.tar.gz"
else
checksum = "5bf668994e163419123d22bb7248ef1d30cbe2e7a14d50aa1c282b961f8172cd"
url = "https://github.com/stan-dev/cmdstan/releases/download/v#{version}/cmdstan-#{version}.tar.gz"
end
puts "Installing CmdStan version: #{version}"
puts "Install directory: #{dir}"
FileUtils.mkdir_p(File.expand_path("../../tmp", __dir__)) unless ENV["CMDSTAN"]
if cmdstan_installed?
puts "Already installed"
return true
end
unless Dir.exist?(dir)
Dir.mktmpdir do |tmpdir|
puts "Downloading..."
download_path = File.join(tmpdir, "cmdstan-#{version}.tar.gz")
download_file(url, download_path, checksum)
puts "Unpacking..."
path = File.join(tmpdir, "cmdstan-#{version}")
FileUtils.mkdir_p(path)
tar_args = Gem.win_platform? ? ["--force-local"] : []
system "tar", "xzf", download_path, "-C", path, "--strip-components=1", *tar_args
FileUtils.mv(path, dir)
end
end
puts "Building..."
make_command = Gem.win_platform? ? "mingw32-make" : "make"
Dir.chdir(dir) do
output, status = Open3.capture2e(make_command, "build", "PRECOMPILED_HEADERS=false")
if status.exitstatus != 0
puts output
raise Error, "Build failed"
end
end
puts "Installed"
true
end
|