# frozen_string_literal: true

require "bundler/gem_tasks"
require "minitest/test_task"
require "rake/extensiontask"
require "rubocop/rake_task"
require "rb_sys/extensiontask"

Minitest::TestTask.create

RuboCop::RakeTask.new

desc "build the .gem file, including native extensions, according to the .gemspec"
task build: :compile

GEMSPEC = Gem::Specification.load("regorusrb.gemspec")

RbSys::ExtensionTask.new("regorusrb", GEMSPEC) do |ext|
  ext.lib_dir = "lib/regorus"
  ext.cross_compile = true
  ext.cross_platform = %w[x86-mingw32 x64-mingw-ucrt x64-mingw32 x86-linux x86_64-linux x86_64-darwin arm64-darwin]
end

task default: %i[compile test rubocop]

desc "Build native extension for a given platform (i.e. rake 'native[x86_64-linux]')"
task :native, [:platform] do |_t, platform:|
  sh "bundle", "exec", "rb-sys-dock", "--platform", platform, "--build"
end
