#!/usr/bin/env bash

# Source parent plagin
. "$(nv_get_plugin_full_path 'rust')"

# Return full url for tarball
plug_url_for_download() {
    local version=$1
    local arch=$(nv_get_system_arch "i686" "x86_64")
    local system=$(nv_get_system "unknown-linux-gnu" "apple-darwin")
    case $version in
        *nightly*)
            # just drop date and and download
            echo "https://static.rust-lang.org/dist/rustc-nightly-${arch}-${system}.tar.gz"
        ;;
        *)
            echo "https://static.rust-lang.org/dist/rustc-${version}-${arch}-${system}.tar.gz"
    esac
}

# Like we build
plug_build() {
    local src_path=$1
    local build_path=$2
    cp -r "$src_path"/*/* "$build_path"
}

plug_build_env() {
    local build_path=$1 
    local env_name_full=$2
    cp -r "$build_path"/rustc/* $env_name_full
}
