LoginSignup
0
0

ghcup

Last updated at Posted at 2023-03-12

インストール

linux(ubuntu LTS-22.04の例)

最新の方法は公式参照の事

sudo apt update
sudo apt install build-essential curl libffi-dev libffi8ubuntu1 libgmp-dev libgmp10 libncurses-dev libncurses5 libtinfo5
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

Windows(powershellからinstall)

Set-ExecutionPolicy Bypass -Scope Process -Force;[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; try { Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing))) -ArgumentList $true } catch { Write-Error $_ }

※問題が出る場合、セキュリティソフトを一時的に停止して再実行の事

HLS,stack,MSys2をインストール

image.png

環境変数を反映する為、powershellへ入り直し

デバッガのインストール

linux

global-projectのresolverをsystem-ghcのバージョンに合わせる

※2024/03/25時点でghc=9.4.8(=lts-21.22),resolver=lts-22.13(合ってなかった)

/home/xxx/.stack/global-project/stack.yaml
# This is the implicit global project's config file, which is only used when
# 'stack' is run outside of a real project. Settings here do _not_ act as
# defaults for all projects. To change Stack's default settings, edit
# '/home/ueki5/.stack/config.yaml' instead.
#
# For more information about Stack's configuration, see
# http://docs.haskellstack.org/en/stable/yaml_configuration/
#
packages: []
resolver: lts-21.22

stack設定を変更(プロジェクト毎にghcをインストールせず、system-ghcを使用する)

stack config set install-ghc false --global
stack config set system-ghc true --global

デバッガをインストール

sudo apt install zlib1g-dev
stack install haskell-dap ghci-dap haskell-debug-adapter

Windows

chcp 65001
stack config set install-ghc false --global
stack config set system-ghc true --global
stack install haskell-dap ghci-dap haskell-debug-adapter --resolver lts-21.22

※注意点
・必ずchcpする事(haskellあるある)
・ghcはstackではインストールしない(必ずghcupでインストールする)
・ghcはグローバルにインストールされたものを使用
・resolverはghcupでインストールされたもの(ghcup listで確認)に合わせる
※resolverはyamlで指定した方がいいかも

以下のディレクトリをpathにいれる

C:\Users\{ユーザ名}\AppData\Roaming\local\bin
/home/{ユーザ名}/.local/bin

プロジェクト作成~実行まで(stack)

プロジェクト作成(リゾルバはインストール済みのものを指定する事)

stack new my-project --resolver lts-21.22
cd my-project
stack build
stack run

vscodeでプロジェクトを開き、以下の拡張機能をインストール

・Haskell
・Haskell GHCi Debug Adapter Phoityne

hie.yamlをプロジェクトルートに置く

hie.yaml
    cradle:
      stack:

launch.jsonを作成(haskell-debug-adapter)

haskell(stack)のstartupを修正

変更前:"startup": "${workspaceFolder}/test/Spec.hs",

変更後:"startup": "${workspaceFolder}/app/Main.hs",

F5でdebug開始

※注意事項
hlsの新しいバージョンのインストールを要求されたらインストールしておく。
リゾルバで指定したghcのバージョンと食い違う場合があるが、なぜか最新をインストールしようとする。
outputで確認すると、起動されるのは適正なバージョンのようなので、使用に問題はなさそう。

モジュールの追加

インストール(モジュール名は適宜変更してください)

stack install optparse-applicative

package.yamlへエントリの追加

package.yaml
    dependencies:
    - base >= 4.7 && < 5
    - optparse-applicative >= 0.17.0.0

GHCup使い方いろいろ

list available ghc/cabal versions

ghcup list

install the recommended GHC version

ghcup install ghc

install a specific GHC version

ghcup install ghc 9.2.5

set the currently "active" GHC version

ghcup set ghc 9.2.5

install cabal-install

ghcup install cabal

update ghcup itself

ghcup upgrade

uninstall stack(バージョン指定が必要)

ghcup rm stack 2.9.1

global設定 stackルートを取得

stack {path} --stack-root

⇒C:\Users\ueki0\AppData\Roaming\stack\config.yaml
C:\Users\ueki0.stack\configure.yaml
C:\Users\ueki0\AppData\Roaming\stack\config.yaml

既存のプロジェクトにリゾルバを設定

stack init --resolver {resolver}.

Cabal

プロジェクトの作成

※cabalのプロジェクトではhie.yamlは不要でした。
mkdir {hoge}
cd {hoge}
cabal init -i
Should I generate a simple project with sensible defaults? [default: y] n
What does the package build:

  1. Executable
  2. Library
  3. Library and Executable
    Your choice? 3
    What is the main module of the executable:
    1. Main.hs (does not yet exist, but will be created)
    2. Main.lhs (does not yet exist, but will be created)
    3. Other (specify)
      Your choice? [default: Main.hs (does not yet exist, but will be created)] 1
      Please choose version of the Cabal specification to use:
    1. 1.10 (legacy)
    2. 2.0 (+ support for Backpack, internal sub-libs, '^>=' operator)
    3. 2.2 (+ support for 'common', 'elif', redundant commas, SPDX)
    4. 2.4 (+ support for '**' globbing)
      Your choice? [default: 1.10 (legacy)] 4
      Package name? [default: start-haskell]
      Package version? [default: 0.1.0.0]
      Please choose a license:
    5. GPL-2.0-only
    6. GPL-3.0-only
    7. LGPL-2.1-only
    8. LGPL-3.0-only
    9. AGPL-3.0-only
    10. BSD-2-Clause
    1. BSD-3-Clause
    2. MIT
    3. ISC
  1. MPL-2.0
  2. Apache-2.0
  3. LicenseRef-PublicDomain
  4. NONE
  5. Other (specify)
    Your choice? [default: BSD-3-Clause]
    Author name? [default: autotaker]
    Maintainer email? [default: xxxxxx@xxxxx.com]
    Project homepage URL? https://github.com/autotaker/start-haskell
    Project synopsis? my favorite cabal project example
    Project category:
    1. (none)
    2. Codec
    3. Concurrency
    4. Control
    5. Data
    6. Database
    7. Development
    8. Distribution
    9. Game
  1. Graphics
  2. Language
  3. Math
  4. Network
  5. Sound
  6. System
  7. Testing
  8. Text
  9. Web
  10. Other (specify)
    Your choice? [default: (none)]
    Application (Main.hs) directory:
    1. (none)
    2. src-exe
    3. app
    4. Other (specify)
      Your choice? [default: (none)] 3
      Library source directory:
    1. (none)
    2. src
    3. lib
    4. src-lib
    5. Other (specify)
      Your choice? [default: (none)] 2
      Should I generate a test suite for the library? [default: y] y
      Test directory:
    1. test
    2. Other (specify)
      Your choice? [default: test] 1
      What base language is the package written in:
    1. Haskell2010
    2. Haskell98
    3. Other (specify)
      Your choice? [default: Haskell2010]
      Add informative comments to each field in the cabal file (y/n)? [default: n] n

Guessing dependencies...

Generating LICENSE...
Generating Setup.hs...
Generating CHANGELOG.md...
Generating src/MyLib.hs...
Generating app/Main.hs...
Generating test/MyLibTest.hs...
Generating start-haskell.cabal...

You may want to edit the .cabal file and add a Description field.

Cabalプロジェクトでデバッグ

launch.jsonの作成

launch.jsonの修正(haskell(cabal))

cabal replから--repl-no-loadの指定を削除

その他

stack設定

/home/ueki5/.stack/global-project/stack.yaml
# This is the implicit global project's config file, which is only used when
# 'stack' is run outside of a real project. Settings here do _not_ act as
# defaults for all projects. To change Stack's default settings, edit
# '/home/ueki5/.stack/config.yaml' instead.
#
# For more information about Stack's configuration, see
# http://docs.haskellstack.org/en/stable/yaml_configuration/
#
packages: []
resolver: lts-21.22
/home/ueki5/.stack/config.yaml
# This file contains default non-project-specific settings for Stack, used
# in all projects. For more information about Stack's configuration, see
# http://docs.haskellstack.org/en/stable/yaml_configuration/

# The following parameters are used by 'stack new' to automatically fill fields
# in the Cabal file. We recommend uncommenting them and filling them out if
# you intend to use 'stack new'.
# See https://docs.haskellstack.org/en/stable/yaml_configuration/#templates
templates:
  params:
#    author-name:
#    author-email:
#    copyright:
#    github-username:

# The following parameter specifies Stack's output styles; STYLES is a
# colon-delimited sequence of key=value, where 'key' is a style name and
# 'value' is a semicolon-delimited list of 'ANSI' SGR (Select Graphic
# Rendition) control codes (in decimal). Use 'stack ls stack-colors --basic'
# to see the current sequence.
# stack-colors: STYLES
install-ghc: false
system-ghc: true
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0