Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to compile with a GHC bindist in a Nix shell on macOS #1336

Closed
jkachmar opened this issue May 19, 2020 · 2 comments
Closed

Fails to compile with a GHC bindist in a Nix shell on macOS #1336

jkachmar opened this issue May 19, 2020 · 2 comments

Comments

@jkachmar
Copy link
Contributor

jkachmar commented May 19, 2020

Describe the bug
rules_haskell compilation fails when using a GHC bindist within a Nix shell on macOS.

To Reproduce

  1. On a macOS machine, clone this repository
  2. Enter into the Nix shell via nix-shell
  3. Run bazel build //...
  4. Observe that compilation fails with the following error message
Starting local Bazel server and connecting to it...
INFO: Analyzed 6 targets (31 packages loaded, 1247 targets configured).
INFO: Found 6 targets...
ERROR: /Users/jkachmar/src/bazel-test/BUILD.bazel:21:1: HaskellLinkDynamicLibrary libHSexample-lib-ghc8.6.5.dylib failed (Exit 1) ghc_wrapper failed: error executing command bazel-out/host/bin/external/rules_haskell/haskell/ghc_wrapper bazel-out/darwin-fastbuild/bin/compile_flags_example_lib_HaskellLinkDynamicLibrary ... (remaining 1 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
ld: library not found for -liconv
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
`cc_wrapper-python' failed in phase `Linker'. (Exit code: 1)

Expected behavior
The project should compile without errors.

Environment

  • OS name + version: macOS 10.14.6 (Mojave)
  • Bazel version: 2.1.0
  • Version of the rules: 0.12

Additional context
It seems like @Profpatsch has run into something like this before (cf. #884 (comment)).

@aherrmann
Copy link
Member

Using the GHC bindist within a Nix shell is not supported. If you are using rules_haskell within a Nix shell then you should use the Nix provided CC and GHC toolchain as well. See also #718 for the same kind of issue on Linux. Is there any reason why you're not using a Nix provided GHC toolchain?

What seems to be happening is that Bazel's autoconfigured CC toolchain (which the reproduction is using) will pick up the clang instance provided by the Nix shell. That clang does not look for libraries like libiconv in standard system locations. So, linking against it will fail.

@hanshoglund
Copy link
Contributor

Like @aherrmann explained this is not a supported use case.

If you install Bazel via Nix you must use a Nix-provided toolchain as explained here.

I will close this, but new tickets and PRs on how to improve the documentation are always welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants