diff --git a/scripts/dvm b/scripts/dvm index c212071..522419e 100644 --- a/scripts/dvm +++ b/scripts/dvm @@ -242,10 +242,26 @@ _dvm_download_dartium() { curl -f -O "$base_uri/dartium/$dartium_archive" } +# Returns the CPU architechture for Dart in the specified SDK version. +# +# Used by Apple Silicon (arm64) based Macs to determine the architecture of the +# Dart SDK archive to download. For SDK 2.14.1 and later, download the arm64 +# bundle. Prior to that, only Intel binaries are available. +_macos_arm64_sdk_arch() { + local archBoundary="2.14.1" + if [[ "$1" == "latest" || "$(printf "$1\n$archBoundary\n" | sort -t. -n -k 1,1 -k 2,2 -k 3,3 | head -n1)" == "$archBoundary" ]]; then + echo "arm64" + else + echo "x64" + fi +} + # Returns the CPU architechture for Dartium in the specified SDK version. -_dvm_dartium_arch() { - # SDKs <= 1.19.x are ia32, > 1.20.0 are x64. - # Through a happy quirk of fate, 1.20.0 never existed. +# +# In Dart SDKx 1.19.x and earlier, Dartium shipped only as an ia32 build. In +# SDKs later than 1.20.0, it was produced as an x64 build. Through a happy +# quirk of fate, 1.20.0 never existed. +_macos_dartium_arch() { local archBoundary="1.20.0" if [[ "$1" == "latest" || "$(printf "$1\n$archBoundary\n" | sort -t. -n -k 1,1 -k 2,2 -k 3,3 | head -n1)" == "$archBoundary" ]]; then echo "x64" @@ -275,8 +291,15 @@ dvm_install() { fi case $(uname -a) in + Darwin*arm64*) + local arch="$(_macos_arm64_sdk_arch "$version")" + local sdk_archive="dartsdk-macos-$arch-release.zip" + arch="$(_macos_dartium_arch "$version")" + local content_shell_archive="content_shell-macos-$arch-release.zip" + local dartium_archive="dartium-macos-$arch-release.zip" + ;; Darwin*) - local arch="$(_dvm_dartium_arch "$version")" + local arch="$(_macos_dartium_arch "$version")" local sdk_archive="dartsdk-macos-x64-release.zip" local content_shell_archive="content_shell-macos-$arch-release.zip" local dartium_archive="dartium-macos-$arch-release.zip"