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

Stack fails to build on Mac when src/ has two nested dirs named the same way as executable #5636

Open
Martinsos opened this issue Nov 11, 2021 · 2 comments

Comments

@Martinsos
Copy link

Martinsos commented Nov 11, 2021

Steps to reproduce

Create a project that has executable named "foo" and also has module Foo.Foo.Bar in src/ that executable calls.

I created a minimal example to reproduce it here: https://github.com/wasp-lang/wasp/tree/mac-build-error/waspc .
To try it out, check out https://github.com/wasp-lang/wasp, branch mac-build-error and then run stack build on Mac machine.

We confirmed this to happen on two different Macs + Github CI for Mac.

Ways to fix it: rename executable to something else, or remove one of the two directories that have the same name as executable.

Expected

I expect project to compile, and it does on Linux, but it does not on Mac.

Actual

What actually happened.

If you suspect that a stack command misbehaved, please include the output of that command in --verbose mode.
If the output is larger than a page please paste the output in a Gist.

$ stack build
Building all executables for `waspc' once. After a successful build of all of them, only specified executables will be rebuilt.
waspc> configure (lib + exe)
Configuring waspc-0.2.2.2...
waspc> build (lib + exe)
Preprocessing library for waspc-0.2.2.2..
Building library for waspc-0.2.2.2..
[1 of 2] Compiling Paths_waspc
[2 of 2] Compiling Wasp.Wasp.Hi
Preprocessing executable 'wasp' for waspc-0.2.2.2..
Building executable 'wasp' for waspc-0.2.2.2..
[1 of 2] Compiling Main
[2 of 2] Compiling Paths_waspc
Linking .stack-work/dist/x86_64-osx/Cabal-3.2.1.0/build/wasp/wasp ...
ld: can't open output file for writing: .stack-work/dist/x86_64-osx/Cabal-3.2.1.0/build/wasp/wasp, errno=21
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)

--  While building package waspc-0.2.2.2 (scroll up to its section to see the error) using:
      /Users/matija/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_3.2.1.0_ghc-8.10.7 --builddir=.stack-work/dist/x86_64-osx/Cabal-3.2.1.0 build lib:waspc exe:wasp --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1

$ stack build --verbose
...
2021-11-11 19:18:19.774230: [info] Preprocessing library for waspc-0.0.0.1..
2021-11-11 19:18:19.774365: [info] Building library for waspc-0.0.0.1..
2021-11-11 19:18:20.387682: [info] Preprocessing executable 'wasp' for waspc-0.0.0.1..
2021-11-11 19:18:20.387790: [info] Building executable 'wasp' for waspc-0.0.0.1..
2021-11-11 19:18:20.876276: [info] Linking .stack-work/dist/x86_64-osx/Cabal-3.2.1.0/build/wasp/wasp ...
2021-11-11 19:18:21.280408: [warn] ld: can't open output file for writing: .stack-work/dist/x86_64-osx/Cabal-3.2.1.0/build/wasp/wasp, errno=21
2021-11-11 19:18:21.285690: [warn] clang: error: linker command failed with exit code 1 (use -v to see invocation)
2021-11-11 19:18:21.287545: [warn] gcc' failed in phase Linker'. (Exit code: 1)
2021-11-11 19:18:21.319877: [debug] Start: getPackageFiles /Users/matija/git/wasp-lang/wasp/waspc/waspc.cabal
2021-11-11 19:18:21.322401: [debug] Failed to decode module interface: /Users/matija/git/wasp-lang/wasp/waspc/.stack-work/dist/x86_64-osx/Cabal-3.2.1.0/build/Paths_waspc.hi Decoding failure: Invalid magic: e49ceb0f
2021-11-11 19:18:21.322555: [debug] Failed to decode module interface: /Users/matija/git/wasp-lang/wasp/waspc/.stack-work/dist/x86_64-osx/Cabal-3.2.1.0/build/Wasp/Wasp/Hi.hi Decoding failure: Invalid magic: e49ceb0f
2021-11-11 19:18:21.323939: [debug] Failed to decode module interface: /Users/matija/git/wasp-lang/wasp/waspc/.stack-work/dist/x86_64-osx/Cabal-3.2.1.0/build/wasp/wasp-tmp/Paths_waspc.hi Decoding failure: Invalid magic: e49ceb0f
2021-11-11 19:18:21.324095: [debug] Failed to decode module interface: /Users/matija/git/wasp-lang/wasp/waspc/.stack-work/dist/x86_64-osx/Cabal-3.2.1.0/build/wasp/wasp-tmp/Main.hi Decoding failure: Invalid magic: e49ceb0f
2021-11-11 19:18:21.324205: [debug] Finished in 4ms: getPackageFiles /Users/matija/git/wasp-lang/wasp/waspc/waspc.cabal
2021-11-11 19:18:21.325389: [error]
--  While building package waspc-0.0.0.1 (scroll up to its section to see the error) using:
      /Users/matija/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_3.2.1.0_ghc-8.10.7 --builddir=.stack-work/dist/x86_64-osx/Cabal-3.2.1.0 build lib:waspc exe:wasp --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1

Stack version

$ stack --version
Version 2.5.1, Git revision d6ab861544918185236cf826cb2028abb266d6d5 x86_64 hpack-0.33.0

Method of installation

homebrew

@brandon-leapyear
Copy link
Contributor

brandon-leapyear commented Apr 7, 2022

This is an old work account. Please reference @brandonchinn178 for all future communication


Related: #3918

@mpilgrem
Copy link
Member

mpilgrem commented Feb 17, 2024

@Martinsos, thanks for reporting. As @brandon-leapyear has indicated, I think this arises because the file system on macOs is case-insensitive and there is no distinction made between:

  • .stack-work/dist/.../build/foo/foo (the executable foo for the package)
  • .stack-work/dist/.../build/Foo/Foo (the directory for the build artefacts for module Foo.Foo.Something)

The problem is not limited to macOS. On Linux (case-sensitive) with executable Foo, there is no distinction between:

  • .stack-work/dist/.../build/Foo/Foo (the executable Foo for the package)
  • .stack-work/dist/.../build/Foo/Foo (the directory for the build artefacts for modules Foo.Foo.Something)

It seems to me to be a feature/bug of Cabal (the library). This Cabal issue (from 2016) appears to be related: haskell/cabal#3545.

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