Closed11

Haskell環境構築

shuntakashuntaka
shuntakashuntaka

brewで入れちゃったけどghcupの方が良さそう(結果的にbrewで入れたものはuninstallしました)

curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
実行結果
Welcome to Haskell!

This script can download and install the following binaries:
  * ghcup - The Haskell toolchain installer
  * ghc   - The Glasgow Haskell Compiler
  * cabal - The Cabal build tool for managing Haskell software
  * stack - A cross-platform program for developing Haskell projects (similar to cabal)
  * hls   - (optional) A language server for developers to integrate with their editor/IDE

ghcup installs only into the following directory,
which can be removed anytime:
  /Users/shuntaka/.ghcup

Press ENTER to proceed or ctrl-c to abort.
Note that this script can be re-run at any given time.

mason経由で入れるのでN

Do you want to install haskell-language-server (HLS)?
HLS is a language-server that provides IDE-like functionality
and can integrate with different editors, such as Vim, Emacs, VS Code, Atom, ...
Also see https://haskell-language-server.readthedocs.io/en/stable/

[Y] Yes  [N] No  [?] Help (default is "N").

stackがghcupのghcバージョンを使用するか。よくわからないのでY。

Do you want to enable better integration of stack with GHCup?
This means that stack won't install its own GHC versions, but uses GHCup's.
For more information see:
  https://docs.haskellstack.org/en/stable/yaml_configuration/#ghc-installation-customisation-experimental
If you want to keep stacks vanilla behavior, answer 'No'.

[Y] Yes  [N] No  [?] Help (default is "Y").

これでインストールが始まる

Enterを押す

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  105M  100  105M    0     0  4933k      0  0:00:21  0:00:21 --:--:-- 4625k
[ Info  ] downloading: https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-0.0.8.yaml as file /Users/shuntaka/.ghcup/cache/ghcup-0.0.8.yaml
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  424k  100  424k    0     0  1691k      0 --:--:-- --:--:-- --:--:-- 1697k
[ Info  ] Upgrading GHCup...
[ Warn  ] No GHCup update available

System requirements
  Note: On OS X, in the course of running ghcup you will be given a dialog box to install the command line tools. Accept and the requirements will be installed for you. You will then need to run the command again.
On Darwin M1 you might also need a working llvm installed (e.g. via brew) and have the toolchain exposed in PATH.
Press ENTER to proceed or ctrl-c to abort.
Installation may take a while.

brewで入れたのが気がかりだけどうまくいっている気がする

これで良さそう

$ which stack
/Users/shuntaka/.ghcup/bin/stack

shuntakashuntaka

TODO
Neovim側で:Masonで、haskell-language-serverを選択

haskell-language-server入ったっぽい

shuntakashuntaka
stack new book

stack buildすると、最新のコンパイラを落としてきてよくわからないことになるので、以下の記述が必要

stack.yaml
+resolver: lts-20.11
+compiler: ghc-9.4.8
shuntakashuntaka

ghcup tuiはこの状態。基本的にrecommendにしている(25/01/06時点)

古いやつ(※ 24/06/24時点)
shuntakashuntaka

haskell-tools.nvim周りは未調査だけど、これはある程度言語触らないと必要が生まれないから一旦Closeしよう

shuntakashuntaka
エラー内容
$ CC=/usr/bin/clang
$ cabal build
Build profile: -w ghc-9.4.8 -O1
In order, the following will be built (use -v for more details):
 - clock-0.8.4 (lib) (requires build)
 - extra-1.7.16 (lib) (requires build)
 - filepattern-0.1.3 (lib) (requires build)
 - shake-0.19.8 (lib) (requires build)
 - nvfetcher-0.7.0.0 (lib) (first run)
 - nvfetcher-0.7.0.0 (test:tests) (first run)
 - nvfetcher-0.7.0.0 (exe:nvfetcher) (first run)
Starting     clock-0.8.4 (lib)
Building     clock-0.8.4 (lib)
Failed to build clock-0.8.4.
Build log ( /Users/shuntaka/.cabal/logs/ghc-9.4.8/clck-0.8.4-bef4d7da.log ):
Configuring library for clock-0.8.4...
Preprocessing library for clock-0.8.4...
compiling dist/build/System/Clock_hsc_make.c failed (exit code 1)
rsp file was: "dist/build/System/hsc2hscall43387-0.rsp"
command was: /etc/profiles/per-user/shuntaka/bin/gcc -c dist/build/System/Clock_hsc_make.c -o dist/build/System/Clock_hsc_make.o --target=arm64-apple-darwin -Wl,-no_fixup_chains -D__GLASGOW_HASKELL__=904 -Ddarwin_BUILD_OS=1 -Daarch64_BUILD_ARCH=1 -Ddarwin_HOST_OS=1 -Daarch64_HOST_ARCH=1 -Icbits -Idist/build/cbits -Idist/build/autogen -Idist/build/global-autogen -include dist/build/autogen/cabal_macros.h -I/Users/shuntaka/.ghcup/ghc/9.4.8/lib/ghc-9.4.8/lib/../lib/aarch64-osx-ghc-9.4.8/base-4.17.2.1/include -I/Users/shuntaka/.ghcup/ghc/9.4.8/lib/ghc-9.4.8/lib/../lib/aarch64-osx-ghc-9.4.8/ghc-bignum-1.3/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ffi -I/Users/shuntaka/.ghcup/ghc/9.4.8/lib/ghc-9.4.8/lib/../lib/aarch64-osx-ghc-9.4.8/rts-1.0.2/include -I/Users/shuntaka/.ghcup/ghc/9.4.8/include/
error: gcc: error: unrecognized command-line option '--target=arm64-apple-darwin'
Error: [Cabal-7125]
Failed to build clock-0.8.4 (which is required by test:tests from nvfetcher-0.7.0.0 and exe:nvfetcher from nvfetcher-0.7.0.0). See the build log above for details.

macでnvfetcherをビルドする際に、GNU gccが優先されてしまい、ハマったので、メモ。
https://github.com/berberman/nvfetcher/tree/bdb14eab6fe9cefc29efe01e60c3a3f616d6b62a

cabal build --with-gcc=/usr/bin/clang --with-ld=/etc/profiles/per-user/shuntaka/bin/ld

と思ったら、オプションなくても成功するなぁ、、

このスクラップは2025/01/08にクローズされました