From 443522d5266fa8000c4f482dc4d7803e32064fab Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 7 Jun 2021 17:06:44 +0200 Subject: [PATCH 1/7] Improve windows bootstrapping and make msys2 configurable --- .gitlab-ci.yml | 24 ++++++++++++++ bootstrap-haskell | 4 ++- bootstrap-haskell.ps1 | 55 +++++++++++++++++++++++++++------ lib/GHCup/Utils/File/Windows.hs | 13 ++++++-- 4 files changed, 82 insertions(+), 14 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c8cf9e6..62abb41 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -66,6 +66,14 @@ variables: ARCH: "64" CABAL_DIR: "$CI_PROJECT_DIR/cabal" +.darwin:aarch64: + tags: + - aarch64-darwin-m1 + variables: + OS: "DARWIN" + ARCH: "ARM64" + CABAL_DIR: "$CI_PROJECT_DIR/cabal" + .freebsd: tags: - x86_64-freebsd @@ -133,6 +141,14 @@ variables: before_script: - ./.gitlab/before_script/darwin/install_deps.sh +.test_ghcup_version:darwin:aarch64: + extends: + - .test_ghcup_version + - .darwin:aarch64 + - .root_cleanup + before_script: + - ./.gitlab/before_script/darwin/install_deps.sh + .test_ghcup_version:freebsd: extends: - .test_ghcup_version @@ -255,6 +271,14 @@ test:mac:latest: CABAL_VERSION: "3.4.0.0" needs: [] +test:mac:recommended:aarch64: + stage: test + extends: .test_ghcup_version:darwin:aarch64 + variables: + GHC_VERSION: "8.10.5" + CABAL_VERSION: "3.4.0.0" + needs: [] + ######## freebsd test ######## diff --git a/bootstrap-haskell b/bootstrap-haskell index a571e32..86aecfb 100755 --- a/bootstrap-haskell +++ b/bootstrap-haskell @@ -24,6 +24,7 @@ case "${plat}" in : "${GHCUP_INSTALL_BASE_PREFIX:=/c}" GHCUP_DIR=${GHCUP_INSTALL_BASE_PREFIX}/ghcup GHCUP_BIN=${GHCUP_INSTALL_BASE_PREFIX}/ghcup/bin + : "${GHCUP_MSYS2:=${GHCUP_DIR}/msys64}" ;; *) : "${GHCUP_INSTALL_BASE_PREFIX:=$HOME}" @@ -272,7 +273,7 @@ eghcup set ghc "${BOOTSTRAP_HASKELL_GHC_VERSION}" eghcup --cache install cabal "${BOOTSTRAP_HASKELL_CABAL_VERSION}" adjust_cabal_config() { - edo cabal user-config -a "extra-prog-path: $(cygpath -w $GHCUP_BIN), $(cygpath -w "$HOME"/AppData/Roaming/cabal/bin), $(cygpath -w "$GHCUP_DIR"/msys64/usr/bin), $(cygpath -w "$GHCUP_DIR"/msys64/mingw64/bin)" -a "extra-include-dirs: $(cygpath -w "$GHCUP_DIR"/msys64/mingw64/include)" -a "extra-lib-dirs: $(cygpath -w "$GHCUP_DIR"/msys64/mingw64/lib)" -f init + edo cabal user-config -a "extra-prog-path: $(cygpath -w $GHCUP_BIN), $(cygpath -w "$HOME"/AppData/Roaming/cabal/bin), $(cygpath -w "$GHCUP_MSYS2"/usr/bin), $(cygpath -w "$GHCUP_MSYS2"/mingw64/bin)" -a "extra-include-dirs: $(cygpath -w "$GHCUP_MSYS2"/mingw64/include)" -a "extra-lib-dirs: $(cygpath -w "$GHCUP_MSYS2"/mingw64/lib)" -f init } case "${plat}" in @@ -290,6 +291,7 @@ case "${plat}" in break ;; [Nn]*) echo "Make sure that your global cabal.config references the correct mingw64 paths (extra-prog-path, extra-include-dirs and extra-lib-dirs)." + echo "And set the environment variable GHCUP_MSYS2 to the root path of your msys2 installation." sleep 5 break ;; *) diff --git a/bootstrap-haskell.ps1 b/bootstrap-haskell.ps1 index 79b35cc..d91ad52 100644 --- a/bootstrap-haskell.ps1 +++ b/bootstrap-haskell.ps1 @@ -1,6 +1,6 @@ function Print-Msg { - param ( [Parameter(Mandatory=$true, HelpMessage='String to output')][string]$msg ) - Write-Host ('{0}' -f $msg) -ForegroundColor Green + param ( [Parameter(Mandatory=$true, HelpMessage='String to output')][string]$msg, [string]$color = "Green" ) + Write-Host ('{0}' -f $msg) -ForegroundColor $color } function Create-Shortcut { @@ -96,15 +96,17 @@ $ErrorActionPreference = 'Stop' $GhcupDir = "C:\ghcup" $MsysDir = ('{0}\msys64' -f $GhcupDir) $Bash = ('{0}\usr\bin\bash' -f $MsysDir) -$Msys2Shell = ('{0}\msys2_shell.cmd' -f $MsysDir) $BootstrapUrl = 'https://www.haskell.org/ghcup/sh/bootstrap-haskell-windows' +$GhcupMsys2 = [System.Environment]::GetEnvironmentVariable('GHCUP_MSYS2', 'user') Print-Msg -msg 'Preparing for GHCup installation...' if (Test-Path -Path ('{0}' -f $GhcupDir)) { - $decision = $Host.UI.PromptForChoice('Install', 'GHCup is already installed, what do you want to do?', @('&Reinstall' - '&Continue' - '&Abort'), 1) + $decision = $Host.UI.PromptForChoice('Install GHCup' + , 'GHCup is already installed, what do you want to do?' + , @('&Reinstall' + '&Continue' + '&Abort'), 1) if ($decision -eq 0) { $suffix = [IO.Path]::GetRandomFileName() Print-Msg -msg ('Backing up {0} to {0}-{1} ...' -f $GhcupDir, $suffix) @@ -112,7 +114,7 @@ if (Test-Path -Path ('{0}' -f $GhcupDir)) { } elseif ($decision -eq 1) { Print-Msg -msg 'Continuing installation...' } elseif ($decision -eq 2) { - Exit + Break } } @@ -122,7 +124,12 @@ $null = New-Item -Path ('{0}' -f $GhcupDir) -Name 'bin' -ItemType 'directory' -E Print-Msg -msg 'First checking for Msys2...' -if (!(Test-Path -Path ('{0}' -f $MsysDir))) { +if (!(Test-Path -Path ('{0}' -f $MsysDir)) -And !($GhcupMsys2)) { + $msys2Decision = $Host.UI.PromptForChoice('Install MSys2' + , 'Do you want GHCup to install a default MSys2 toolchain (recommended)?' + , @('&Yes' + '&No'), 0) + if ($msys2Decision -eq 0) { Print-Msg -msg ('...Msys2 doesn''t exist, installing into {0} ...this may take a while' -f $MsysDir) # Download the archive @@ -158,6 +165,32 @@ if (!(Test-Path -Path ('{0}' -f $MsysDir))) { Print-Msg -msg 'Setting default home directory...' & "$Bash" -lc "sed -i -e 's/db_home:.*$/db_home: windows/' /etc/nsswitch.conf" + } elseif ($msys2Decision -eq 1) { + Print-Msg -color Magenta -msg 'Skipping MSys2 installation.' + if ($GhcupMsys2) { + Print-Msg -msg 'GHCUP_MSYS2 env var set, using existing installation...' + $MsysDir = $GhcupMsys2 + } else { + $MsysDir = Read-Host -Prompt 'Input existing MSys2 toolchain directory' + } + + if (!(Test-Path -Path ('{0}' -f $MsysDir))) { + Print-Msg -color Red -msg ('MSys2 installation at ''{0}'' could not be found, aborting!' -f $MsysDir) + Break + } + Print-Msg -msg 'Making MSys2 discoverable for GHCup...' + $null = [Environment]::SetEnvironmentVariable("GHCUP_MSYS2", $MsysDir, [System.EnvironmentVariableTarget]::User) + $Bash = ('{0}\usr\bin\bash' -f $MsysDir) + } +} elseif ($GhcupMsys2) { + if (!(Test-Path -Path ('{0}' -f $GhcupMsys2))) { + Print-Msg -color Red -msg ('MSys2 installation at ''{0}'' could not be found, aborting!' -f $GhcupMsys2) + Break + } + $MsysDir = $GhcupMsys2 + Print-Msg -msg 'Making MSys2 discoverable for GHCup...' + $null = [Environment]::SetEnvironmentVariable("GHCUP_MSYS2", $MsysDir, [System.EnvironmentVariableTarget]::User) + $Bash = ('{0}\usr\bin\bash' -f $MsysDir) } else { Print-Msg -msg ('...Msys2 found in {0} ...skipping Msys2 installation.' -f $MsysDir) } @@ -171,10 +204,12 @@ Add-EnvPath -Path ('{0}\bin' -f $GhcupDir) -Container 'User' Print-Msg -msg 'Starting GHCup installer...' +$Msys2Shell = ('{0}\msys2_shell.cmd' -f $MsysDir) + if ((Get-Process -ID $PID).ProcessName.StartsWith("bootstrap-haskell")) { - & "$Bash" -lc ('export PATH="/c/ghcup/bin:$PATH" ; curl --proto ''=https'' --tlsv1.2 -sSf {0} | bash' -f $BootstrapUrl) + & "$Bash" -lc ('[ -n ''{1}'' ] && export GHCUP_MSYS2=$(cygpath -w ''{1}'') ; export PATH="/c/ghcup/bin:$PATH" ; curl --proto ''=https'' --tlsv1.2 -sSf {0} | bash' -f $BootstrapUrl, $MsysDir) } else { - & "$Msys2Shell" -mingw64 -mintty -c ('export PATH="/c/ghcup/bin:$PATH" ; trap ''echo Press any key to exit && read -n 1 && exit'' 2 ; curl --proto =https --tlsv1.2 -sSf -k {0} | bash ; echo ''Press any key to exit'' && read -n 1' -f $BootstrapUrl) + & "$Msys2Shell" -mingw64 -mintty -c ('[ -n ''{1}'' ] && export GHCUP_MSYS2=$(cygpath -w ''{1}'') ; export PATH="/c/ghcup/bin:$PATH" ; trap ''echo Press any key to exit && read -n 1 && exit'' 2 ; curl --proto =https --tlsv1.2 -sSf -k {0} | bash ; echo ''Press any key to exit'' && read -n 1' -f $BootstrapUrl, $MsysDir) } diff --git a/lib/GHCup/Utils/File/Windows.hs b/lib/GHCup/Utils/File/Windows.hs index 074c188..ba2710a 100644 --- a/lib/GHCup/Utils/File/Windows.hs +++ b/lib/GHCup/Utils/File/Windows.hs @@ -214,10 +214,10 @@ createProcessWithMingwPath :: MonadIO m => CreateProcess -> m CreateProcess createProcessWithMingwPath cp = do - baseDir <- liftIO ghcupBaseDir + msys2Dir <- liftIO ghcupMsys2Dir cEnv <- Map.fromList <$> maybe (liftIO getEnvironment) pure (env cp) - let mingWPaths = [baseDir "msys64" "usr" "bin" - ,baseDir "msys64" "mingw64" "bin"] + let mingWPaths = [msys2Dir "usr" "bin" + ,msys2Dir "mingw64" "bin"] paths = ["PATH", "Path"] curPaths = (\x -> maybe [] splitSearchPath (Map.lookup x cEnv)) =<< paths newPath = intercalate [searchPathSeparator] (mingWPaths ++ curPaths) @@ -226,6 +226,13 @@ createProcessWithMingwPath cp = do liftIO $ setEnv "Path" newPath pure $ cp { env = Just $ Map.toList envWithNewPath } +ghcupMsys2Dir :: IO FilePath +ghcupMsys2Dir = + lookupEnv "GHCUP_MSYS2" >>= \case + Just fp -> pure fp + Nothing -> do + baseDir <- liftIO ghcupBaseDir + pure (baseDir "msys64") -- | Checks whether the binary is a broken link. isBrokenSymlink :: FilePath -> IO Bool From 5cd9ce8835799d5546009a6bbe5eb8d4ac928b04 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 7 Jun 2021 17:09:47 +0200 Subject: [PATCH 2/7] Fix build with zip --- cabal.project | 5 ----- ghcup.cabal | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/cabal.project b/cabal.project index 1550800..2f71058 100644 --- a/cabal.project +++ b/cabal.project @@ -11,11 +11,6 @@ source-repository-package location: https://github.com/Bodigrim/tar tag: ac197ec7ea4838dc2b4e22b9b888b080cedf29cf -source-repository-package - type: git - location: https://github.com/hasufell/zip - tag: 6f02aa48622b8ba764d0cc0e6900f480a107aa96 - constraints: http-io-streams -brotli package libarchive diff --git a/ghcup.cabal b/ghcup.cabal index 91c94db..2e121b5 100644 --- a/ghcup.cabal +++ b/ghcup.cabal @@ -145,7 +145,7 @@ library , versions ^>=4.0.1 , word8 ^>=0.1.3 , yaml ^>=0.11.4.0 - , zip ^>=1.7.0 + , zip ^>=1.7.1 , zlib ^>=0.6.2.2 if (flag(internal-downloader) && !os(windows)) From 0d7d6c8382569b848b33e656fa961f324d0b083a Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 7 Jun 2021 19:35:06 +0200 Subject: [PATCH 3/7] Fix CI --- bootstrap-haskell | 2 +- stack.yaml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bootstrap-haskell b/bootstrap-haskell index 86aecfb..acf1aad 100755 --- a/bootstrap-haskell +++ b/bootstrap-haskell @@ -16,7 +16,7 @@ plat="$(uname -s)" arch=$(uname -m) -ghver="0.1.15" +ghver="0.1.14.1" base_url="https://downloads.haskell.org/~ghcup" case "${plat}" in diff --git a/stack.yaml b/stack.yaml index 86ac75b..c75b0cd 100644 --- a/stack.yaml +++ b/stack.yaml @@ -37,6 +37,7 @@ extra-deps: - streamly-posix-0.1.0.1@sha256:5d89b806281035d34020387ed99dde1ddab282c7ed66df3b7cd010b38fd3517b,2138 - strict-base-0.4.0.0@sha256:2ff4e43cb95eedf2995558d7fc34d19362846413dd39e6aa6a5b3ea8228fef9f,1248 - xor-0.0.1.0@sha256:f8362b4a68562b9afbcd727ff64c1a303970df3a032e0033d2f4c094c3501df3,2243 + - zip-1.7.1@sha256:0ce03d0fbffba47c1ab6fbb9166f8ba5373d828d78587df21b7e9d7bb150f929,3918 flags: http-io-streams: From e93ac62c81e58966014b9ccc752c183c32196419 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 7 Jun 2021 20:04:27 +0200 Subject: [PATCH 4/7] Add alpine 32 bit GHC-8.10.5 --- ghcup-0.0.4.yaml | 10 +++++----- ghcup-0.0.5.yaml | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ghcup-0.0.4.yaml b/ghcup-0.0.4.yaml index d67dcc9..05caa88 100644 --- a/ghcup-0.0.4.yaml +++ b/ghcup-0.0.4.yaml @@ -1538,11 +1538,11 @@ ghcupDownloads: unknown_versioning: *ghc-8105-32-deb9 Linux_UnknownLinux: unknown_versioning: *ghc-8105-32-deb9 - # Linux_Alpine: - # unknown_versioning: - # dlUri: https://downloads.haskell.org/ghcup/unofficial-bindists/ghc/8.10.5/ghc-8.10.5-i386-alpine-linux.tar.xz - # dlSubdir: ghc-8.10.5 - # dlHash: 9161a98bed763692101854d83af69c1316030cfe5ee6f6acde283d04ef139735 + Linux_Alpine: + unknown_versioning: + dlUri: https://downloads.haskell.org/~ghcup/unofficial-bindists/ghc/8.10.5/ghc-8.10.5-i386-alpine-linux.tar.xz + dlSubdir: ghc-8.10.5 + dlHash: 0e91abe61607f9375d4e252ee9c261e4856df396f60641bb1b880ab8a3a83ea7 A_ARM64: Linux_UnknownLinux: unknown_versioning: diff --git a/ghcup-0.0.5.yaml b/ghcup-0.0.5.yaml index a2959b7..a0731c5 100644 --- a/ghcup-0.0.5.yaml +++ b/ghcup-0.0.5.yaml @@ -1654,11 +1654,11 @@ ghcupDownloads: unknown_versioning: *ghc-8105-32-deb9 Linux_UnknownLinux: unknown_versioning: *ghc-8105-32-deb9 - # Linux_Alpine: - # unknown_versioning: - # dlUri: https://downloads.haskell.org/ghcup/unofficial-bindists/ghc/8.10.5/ghc-8.10.5-i386-alpine-linux.tar.xz - # dlSubdir: ghc-8.10.5 - # dlHash: 9161a98bed763692101854d83af69c1316030cfe5ee6f6acde283d04ef139735 + Linux_Alpine: + unknown_versioning: + dlUri: https://downloads.haskell.org/~ghcup/unofficial-bindists/ghc/8.10.5/ghc-8.10.5-i386-alpine-linux.tar.xz + dlSubdir: ghc-8.10.5 + dlHash: 0e91abe61607f9375d4e252ee9c261e4856df396f60641bb1b880ab8a3a83ea7 A_ARM64: Linux_UnknownLinux: unknown_versioning: From d584e7b21be04a05d9c267b59ce2c73b138cbfbd Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 7 Jun 2021 20:04:45 +0200 Subject: [PATCH 5/7] Update shimgen URL --- ghcup-0.0.5.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ghcup-0.0.5.yaml b/ghcup-0.0.5.yaml index a0731c5..375c8de 100644 --- a/ghcup-0.0.5.yaml +++ b/ghcup-0.0.5.yaml @@ -1,7 +1,7 @@ --- globalTools: ShimGen: - dlUri: https://downloads.haskell.org/~ghcup/tmp/gs.exe + dlUri: https://downloads.haskell.org/~ghcup/shimgen/gs.exe dlHash: 9ce8b7dad7ff4e5017dbd63d6f6f3d16412b889560cb6ccd3903dbcab0bf4f0d toolRequirements: GHC: From 810870e3a59a5f4903cc5199f8f2bb07364ff3fa Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 7 Jun 2021 20:04:55 +0200 Subject: [PATCH 6/7] Fix Validate --- app/ghcup-gen/Validate.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/ghcup-gen/Validate.hs b/app/ghcup-gen/Validate.hs index 6bd0535..3c468e1 100644 --- a/app/ghcup-gen/Validate.hs +++ b/app/ghcup-gen/Validate.hs @@ -208,7 +208,7 @@ validateTarballs (TarballFilter etool versionRegex) dls gt = do -- download/verify all tarballs let dlis = either (const []) (\tool -> nubOrd $ dls ^.. each %& indices (maybe (const True) (==) tool) %> each %& indices (matchTest versionRegex . T.unpack . prettyVer) % (viSourceDL % _Just `summing` viArch % each % each % each)) etool let gdlis = nubOrd $ gt ^.. each - let allDls = dlis ++ gdlis + let allDls = either (const gdlis) (const dlis) etool when (null allDls) $ $(logError) [i|no tarballs selected by filter|] *> addError forM_ allDls downloadAll From aa992c0e5de9bf8e8765da8bd676a5a019cf44aa Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 7 Jun 2021 20:09:18 +0200 Subject: [PATCH 7/7] PrettyShow --- lib/GHCup/Platform.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/GHCup/Platform.hs b/lib/GHCup/Platform.hs index 7ee3529..e930f45 100644 --- a/lib/GHCup/Platform.hs +++ b/lib/GHCup/Platform.hs @@ -44,6 +44,7 @@ import Prelude hiding ( abs import System.Info import System.Directory import System.OsRelease +import Text.PrettyPrint.HughesPJClass ( prettyShow ) import Text.Regex.Posix import qualified Data.Text as T @@ -108,7 +109,7 @@ getPlatform = do pure $ PlatformResult { _platform = FreeBSD, _distroVersion = ver } "mingw32" -> pure PlatformResult { _platform = Windows, _distroVersion = Nothing } what -> throwE $ NoCompatiblePlatform what - lift $ $(logDebug) [i|Identified Platform as: #{pfr}|] + lift $ $(logDebug) [i|Identified Platform as: #{prettyShow pfr}|] pure pfr where getMajorVersion = T.intercalate "." . take 2 . T.split (== '.')