Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support build from source through cargo #29

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ jobs:
- name: Install bats-core
run: brew install bats-core

- name: Remove rust's cargo (if any)
run: |
if test -n "$(command -v cargo)"; then
rm -f $(command -v cargo)
fi

- name: Test plugin
run: |
asdf plugin-add deno $GITHUB_WORKSPACE
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
- git
- gunzip (for v0.35.0 or lower)
- unzip (for v0.36.0 or higher)
- To build from source, you will need these dependencies:
- cargo (you can install it through [asdf-rust](https://github.com/asdf-community/asdf-rust))

## Installation

Expand Down
101 changes: 63 additions & 38 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,34 @@ fail() {
exit 1
}

install_from_archive() {
local source_path=$1
local download_url=$2
local uncompress_command=$3
curl --fail --silent --location --create-dirs --output "$source_path" "$download_url"
$uncompress_command "$source_path"
}

install_from_source() {
local install_path=$1
local version=$2

if [ "$version" == "" ] || [ "$version" == "latest" ]; then
cargo install --root "$1" deno --locked
spywhere marked this conversation as resolved.
Show resolved Hide resolved
else
cargo install --root "$1" --version "$2" deno --locked
spywhere marked this conversation as resolved.
Show resolved Hide resolved
fi
}

install_deno() {
local install_type=$1
local version=$2
local install_path=$3

if [ "$install_type" != "version" ]; then
fail "asdf-deno supports release installs only"
if [ -z "$(command -v cargo)" ] || ! cargo >/dev/null 2>&1; then
fail "build from source (${version:-latest}) require 'cargo' to be installed"
fi
fi

local platform
Expand All @@ -33,48 +54,52 @@ install_deno() {
local uncompress_command
local archive_file

if [[ $version > "0.35.0" ]]; then
case "$OSTYPE" in
darwin*) platform="apple-darwin" ;;
linux*) platform="unknown-linux-gnu" ;;
*) fail "Unsupported platform" ;;
esac

case "$(uname -m)" in
x86_64) architecture="x86_64" ;;
arm64) architecture="aarch64" ;;
*) fail "Unsupported architecture" ;;
esac

archive_format="zip"
archive_file="deno-${architecture}-${platform}.${archive_format}"
uncompress_command="unzip -d ${install_path}/bin"
if [ "$install_type" == "version" ]; then
spywhere marked this conversation as resolved.
Show resolved Hide resolved
if [[ $version > "0.35.0" ]]; then
case "$OSTYPE" in
darwin*) platform="apple-darwin" ;;
linux*) platform="unknown-linux-gnu" ;;
*) fail "Unsupported platform" ;;
esac

case "$(uname -m)" in
x86_64) architecture="x86_64" ;;
arm64) architecture="aarch64" ;;
*) fail "Unsupported architecture" ;;
esac

archive_format="zip"
archive_file="deno-${architecture}-${platform}.${archive_format}"
uncompress_command="unzip -d ${install_path}/bin"
else
case "$OSTYPE" in
darwin*) platform="osx" ;;
linux*) platform="linux" ;;
*) fail "Unsupported platform" ;;
esac

case "$(uname -m)" in
x86_64) architecture="x64" ;;
*) fail "Unsupported architecture" ;;
esac

archive_format="gz"
archive_file="deno_${platform}_${architecture}.${archive_format}"
uncompress_command="gunzip"
fi

local download_url="https://github.com/denoland/deno/releases/download/v${version}/${archive_file}"
local source_path="${install_path}/bin/deno.${archive_format}"
echo "* Downloading and installing deno..."
install_from_archive "$source_path" "$download_url" "$uncompress_command"
rm "$source_path"
else
case "$OSTYPE" in
darwin*) platform="osx" ;;
linux*) platform="linux" ;;
*) fail "Unsupported platform" ;;
esac

case "$(uname -m)" in
x86_64) architecture="x64" ;;
*) fail "Unsupported architecture" ;;
esac

archive_format="gz"
archive_file="deno_${platform}_${architecture}.${archive_format}"
uncompress_command="gunzip"
echo "* Building and installing deno..."
install_from_source "$install_path" "$version"
fi

local download_url="https://github.com/denoland/deno/releases/download/v${version}/${archive_file}"
local source_path="${install_path}/bin/deno.${archive_format}"

echo "* Downloading and installing deno..."
curl --fail --silent --location --create-dirs --output "$source_path" "$download_url"
$uncompress_command "$source_path"
chmod +x "${install_path}/bin/deno"
mkdir "${install_path}/.deno"
rm "$source_path"
echo "The installation was successful!"
}

Expand Down
4 changes: 2 additions & 2 deletions test/install.bats
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bats

@test "install command fails if the input is not version number" {
@test "install command fails if the input is a ref and cargo is not installed" {
run asdf install deno ref
[ "$status" -eq 1 ]
echo "$output" | grep "supports release installs only"
echo "$output" | grep "build from source (latest) require 'cargo' to be installed"
}