Search code examples
haskellbazel

Using Haskell with Bazel


Windows 10 (x64)

I want to use Haskell with Bazel (2.0.0). I did on my Windows 10 (x64) machine the following steps:

git clone https://github.com/tweag/rules_haskell/
cd rules_haskell
cd tutorial
bazel build //...

Which results in the following output:

INFO: Call stack for the definition of repository 'rules_haskell_ghc_windows_amd64' which is a _ghc_bindist (rule definition at C:/users/verte/_bazel_verte/idi6e53f/external/rules_haskell/haskell/ghc_bindist.bzl:289:16):
 - C:/users/verte/_bazel_verte/idi6e53f/external/rules_haskell/haskell/ghc_bindist.bzl:409:5
 - C:/users/verte/_bazel_verte/idi6e53f/external/rules_haskell/haskell/ghc_bindist.bzl:445:9
 - C:/users/verte/_bazel_verte/idi6e53f/external/rules_haskell/haskell/toolchain.bzl:320:5
 - D:/dev/rules_haskell/tutorial/WORKSPACE:22:1
ERROR: An error occurred during the fetch of repository 'rules_haskell_ghc_windows_amd64':
   Traceback (most recent call last):
        File "C:/users/verte/_bazel_verte/idi6e53f/external/rules_haskell/haskell/ghc_bindist.bzl", line 194
                _find_python(ctx)
        File "C:/users/verte/_bazel_verte/idi6e53f/external/rules_haskell/haskell/ghc_bindist.bzl", line 461, in _find_python
                repository_ctx.execute(<1 more arguments>)
Argument 0 of execute is neither a path nor a string.
ERROR: D:/dev/rules_haskell/tutorial/lib/BUILD.bazel:6:1: //lib:booleans depends on @rules_haskell_ghc_windows_amd64//:toolchain-impl in repository @rules_haskell_ghc_windows_amd64 which failed to fetch. no such package '@rules_haskell_ghc_windows_amd64//': Traceback (most recent call last):
        File "C:/users/verte/_bazel_verte/idi6e53f/external/rules_haskell/haskell/ghc_bindist.bzl", line 194
                _find_python(ctx)
        File "C:/users/verte/_bazel_verte/idi6e53f/external/rules_haskell/haskell/ghc_bindist.bzl", line 461, in _find_python
                repository_ctx.execute(<1 more arguments>)
Argument 0 of execute is neither a path nor a string.
ERROR: Analysis of target '//lib:booleans' failed; build aborted: no such package '@rules_haskell_ghc_windows_amd64//': Traceback (most recent call last):
        File "C:/users/verte/_bazel_verte/idi6e53f/external/rules_haskell/haskell/ghc_bindist.bzl", line 194
                _find_python(ctx)
        File "C:/users/verte/_bazel_verte/idi6e53f/external/rules_haskell/haskell/ghc_bindist.bzl", line 461, in _find_python
                repository_ctx.execute(<1 more arguments>)
Argument 0 of execute is neither a path nor a string.
INFO: Elapsed time: 11.900s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (27 packages loaded, 44 targets configured)

I have installed msys2 and python3 (Vesion 3.7.6) as descriped here.

It seems that the error occurs in in _find_python. My path variable ($Env:Path) contains the path of python.exe.

Is anyone successful with building the tutorial on Windows 10?

It seems that this azure-pipeline can build Haskell rules on Windows:

It seems that there are two steps needed to get this working:

Step 1 (Powershell):

Write-Host "Enable long path behavior"
# See https://learn.microsoft.com/en-us/windows/desktop/fileio/naming-a-file#maximum-path-length-limitation
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1 displayName: "Enable da long paths"

Step 2 (bash):

# Remove 'C:\Program Files ' (ending on space) from PATH.
# See https://github.com/bazelbuild/bazel/issues/10481
export PATH="$(sed 's,:/c/Program Files $,,' <<<"$PATH")"
echo "PATH='$PATH'"

I do not know how this can be reproduced on a (local) Windows 10 machine

Ubuntu 18.04

git clone https://github.com/tweag/rules_haskell/
cd rules_haskell
cd tutorial
bazel build //...

Which results in the following output:

INFO: Analyzed 3 targets (0 packages loaded, 0 targets configured).
INFO: Found 3 targets...
ERROR: /home/newton/dev/rules_haskell/tutorial/lib/BUILD.bazel:6:1: HaskellLinkDynamicLibrary lib/libHSlibZSbooleans-ghc8.6.5.so failed (Exit 1) ghc_wrapper failed: error executing command bazel-out/host/bin/external/rules_haskell/haskell/ghc_wrapper bazel-out/k8-fastbuild/bin/lib/compile_flags_booleans_HaskellLinkDynamicLibrary ... (remaining 1 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
/usr/bin/ld.gold: error: cannot find -lgmp
collect2: error: ld returned 1 exit status
`cc_wrapper-python' failed in phase `Linker'. (Exit code: 1)
INFO: Elapsed time: 0.554s, Critical Path: 0.37s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

Building the tutorial using Ubuntu (Bazel version 2.0.0) instead of Windows does also not work for me. Any hints?


Solution

  • Solution for Ubuntu 18.04

    The build problems on Ubuntu were solved by installing the following packages:

    sudo apt-get install build-essential libffi-dev libgmp-dev libtinfo5 libtinfo-dev python python3
    

    Windows 10 x64

    There is a problem when you have installed Visual Studio 2019. By overriding cc_toolchain it can be fixed:

    bazel run --crosstool_top=@rules_haskell_ghc_windows_amd64//:cc_toolchain //:HelloHaskell