class RbSys::CargoBuilder

def finalize_directory(dest_path, lib_dir, extension_dir)

Copied from ExtConfBuilder
def finalize_directory(dest_path, lib_dir, extension_dir)
  require "fileutils"
  require "tempfile"
  ext_path = final_extension_path(dest_path)
  begin
    tmp_dest = Dir.mktmpdir(".gem.", extension_dir)
    # Some versions of `mktmpdir` return absolute paths, which will break make
    # if the paths contain spaces. However, on Ruby 1.9.x on Windows, relative
    # paths cause all C extension builds to fail.
    #
    # As such, we convert to a relative path unless we are using Ruby 1.9.x on
    # Windows. This means that when using Ruby 1.9.x on Windows, paths with
    # spaces do not work.
    #
    # Details: https://github.com/rubygems/rubygems/issues/977#issuecomment-171544940
    tmp_dest_relative = get_relative_path(tmp_dest.clone, extension_dir)
    if tmp_dest_relative
      full_tmp_dest = File.join(extension_dir, tmp_dest_relative)
      # TODO: remove in RubyGems 3
      if Gem.install_extension_in_lib && lib_dir
        FileUtils.mkdir_p lib_dir
        FileUtils.cp_r ext_path, lib_dir, remove_destination: true
      end
      FileUtils::Entry_.new(full_tmp_dest).traverse do |ent|
        destent = ent.class.new(dest_path, ent.rel)
        destent.exist? || FileUtils.mv(ent.path, destent.path)
      end
    end
  ensure
    FileUtils.rm_rf tmp_dest if tmp_dest
  end
end