From 3af6f345e088f1dbf2634f4235588ddde619abd3 Mon Sep 17 00:00:00 2001 From: Rexios Date: Tue, 10 May 2022 18:41:37 -0400 Subject: [PATCH 1/3] Added macOS arm64 support --- scripts/dvm | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/dvm b/scripts/dvm index c212071..04a05cf 100644 --- a/scripts/dvm +++ b/scripts/dvm @@ -242,8 +242,19 @@ _dvm_download_dartium() { curl -f -O "$base_uri/dartium/$dartium_archive" } +# Returns the CPU architechture for Dart in the specified SDK version. +_macos_m1_dart_arch() { + # SDKs >= 2.14.1 are compiled for arm64. + 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() { +_macos_dartium_arch() { # SDKs <= 1.19.x are ia32, > 1.20.0 are x64. # Through a happy quirk of fate, 1.20.0 never existed. local archBoundary="1.20.0" @@ -275,8 +286,13 @@ dvm_install() { fi case $(uname -a) in + Darwin*arm64*) + local arch="$(_macos_m1_dart_arch "$version")" + local sdk_archive="dartsdk-macos-$arch-release.zip" + # M1 users probably won't be using dartium or the content shell + ;; 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" From 9be9b4271f92ba57798eb32846f1122df90b4e1c Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 11 May 2022 09:42:13 -0700 Subject: [PATCH 2/3] Use arm64 in place of M1 and update comments Pedantic tweak to use the term arm64 in place of M1, since presumably (hopefully) we'll see further iterations of Apple Silicon Macs such as M2, etc. Added a bit more detail to the doc comments for both the SDK architecture selection function and the Dartium architecture selection function. --- scripts/dvm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/dvm b/scripts/dvm index 04a05cf..38f464f 100644 --- a/scripts/dvm +++ b/scripts/dvm @@ -243,8 +243,11 @@ _dvm_download_dartium() { } # Returns the CPU architechture for Dart in the specified SDK version. -_macos_m1_dart_arch() { - # SDKs >= 2.14.1 are compiled for arm64. +# +# 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" @@ -254,9 +257,11 @@ _macos_m1_dart_arch() { } # Returns the CPU architechture for Dartium in the specified SDK version. +# +# 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() { - # SDKs <= 1.19.x are ia32, > 1.20.0 are x64. - # Through a happy quirk of fate, 1.20.0 never existed. 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" @@ -287,7 +292,7 @@ dvm_install() { case $(uname -a) in Darwin*arm64*) - local arch="$(_macos_m1_dart_arch "$version")" + local arch="$(_macos_arm64_sdk_arch "$version")" local sdk_archive="dartsdk-macos-$arch-release.zip" # M1 users probably won't be using dartium or the content shell ;; From 65052a55c43deb1366fe74bcdbdd5d7f904b67a8 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 11 May 2022 09:49:30 -0700 Subject: [PATCH 3/3] Support downloading Dartium on arm64 Macs The chance that anyone is actually using Dartium or Content Shell, and thus Dart 1.x in 2022 is pretty slim, but adding this for completionism and for the fun factor of jumping in the time machine and paying a visit to Dart's origins in Chromium. Older versions of Dartium were time-limited to stop working after some fixed amount of time due to the security implications of running an out-of-date browser with two VMs running simultaneously and memory leaks galore. My recollection is that later versions of Dartium removed this time limit in order to give Dart 1.x users time to migrate to Dart 2, so those are likely usable even today. --- scripts/dvm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/dvm b/scripts/dvm index 38f464f..522419e 100644 --- a/scripts/dvm +++ b/scripts/dvm @@ -294,7 +294,9 @@ dvm_install() { Darwin*arm64*) local arch="$(_macos_arm64_sdk_arch "$version")" local sdk_archive="dartsdk-macos-$arch-release.zip" - # M1 users probably won't be using dartium or the content shell + 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="$(_macos_dartium_arch "$version")"