`stack setup` failing on mac to compile a sanity check

Hi there,
I create this post because I’m experiencing a weird problem with stack setup.
I created a PR to the stack repo and it was suggested to me to expose the problem here to reach a wider audience.
I point you to the Issue for details. `stack setup` failed to compile a sanity check · Issue #5958 · commercialhaskell/stack · GitHub

We can also continue the discussion there, up to you.
Any help is appreciated
Cheers

How did you install the stack? Was it via ghcup? What is the ghc version? What is your llvm installation?

you should find everything in the PR, but to reply to your questions here as well:

  1. I installed stack through nix. This is my configuration and here is where stack is installed.
  2. The ghc version is ghc-9.2.5 and the resolver is lts-20.1
  3. I didn’t install llvm

This is the output btw:

benkios-MacBook-Pro:AdventOfCode benkio$ stack setup --verbose
Version 2.9.1, Git revision 409d56031b4240221d656db09b2ba476fe6bb5b1 x86_64 hpack-0.35.0
2022-11-27 00:02:09.655855: [debug] Checking for project config at: /Users/benkio/playground/GeneralExercises/AdventOfCode/stack.yaml
2022-11-27 00:02:09.656602: [debug] Loading project config file stack.yaml
2022-11-27 00:02:09.662728: [debug] (SQL) SELECT COUNT(*) FROM "last_performed" WHERE ("action"=?) AND ("timestamp">=?); [PersistInt64 1,PersistUTCTime 2022-11-26 00:02:09.662664 UTC]
2022-11-27 00:02:09.664357: [debug] Using package location completions from a lock file
2022-11-27 00:02:09.669358: [debug] Loaded snapshot from Pantry database.
2022-11-27 00:02:09.877675: [debug] Running hpack on /Users/benkio/playground/GeneralExercises/AdventOfCode/package.yaml
2022-11-27 00:02:09.889913: [debug] hpack output unchanged in /Users/benkio/playground/GeneralExercises/AdventOfCode/AdventOfCode.cabal
2022-11-27 00:02:09.890320: [debug] Prefetching git repos: []
2022-11-27 00:02:09.890376: [debug] []
2022-11-27 00:02:09.892387: [debug] Asking for a supported GHC version
2022-11-27 00:02:09.892616: [debug] Installed tools: 
 - ghc-9.2.5
2022-11-27 00:02:09.892713: [debug] Potential GHC builds: standard
2022-11-27 00:02:09.892751: [debug] Found already installed GHC builds: standard
2022-11-27 00:02:09.893755: [debug] Performing a sanity check on: /Users/benkio/.stack/programs/x86_64-osx/ghc-9.2.5/bin/ghc-9.2.5
2022-11-27 00:02:09.894071: [debug] Run process within /private/var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/stack-sanity-check-19f219522873c1b7/: /Users/benkio/.stack/programs/x86_64-osx/ghc-9.2.5/bin/ghc-9.2.5 /private/var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/stack-sanity-check-19f219522873c1b7/Main.hs -no-user-package-db
2022-11-27 00:02:10.279036: [debug] Process finished in 384823315000ms: /Users/benkio/.stack/programs/x86_64-osx/ghc-9.2.5/bin/ghc-9.2.5 /private/var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/stack-sanity-check-19f219522873c1b7/Main.hs -no-user-package-db
2022-11-27 00:02:10.279990: [error] The GHC located at /Users/benkio/.stack/programs/x86_64-osx/ghc-9.2.5/bin/ghc-9.2.5 failed to compile a sanity check. Please see:

    http://docs.haskellstack.org/en/stable/install_and_upgrade/

for more information. Exception was:
Received ExitFailure 1 when running
Raw command: /Users/benkio/.stack/programs/x86_64-osx/ghc-9.2.5/bin/ghc-9.2.5 /private/var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/stack-sanity-check-19f219522873c1b7/Main.hs -no-user-package-db
Run from: /private/var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/stack-sanity-check-19f219522873c1b7/
Standard output:

[1 of 1] Compiling Main             ( /private/var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/stack-sanity-check-19f219522873c1b7/Main.hs, /private/var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/stack-sanity-check-19f219522873c1b7/Main.o )
Standard error:


/var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/ghc58339_0/ghc_2.s:5:0: error:
    Unknown pseudo-op: .string
  |
5 |         .string "Main"
  | ^

/var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/ghc58339_0/ghc_2.s:5:0: error:
    Rest of line ignored. 1st junk character valued 34 (").
  |
5 |         .string "Main"
  | ^

/var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/ghc58339_0/ghc_2.s:16:0: error:
    Unknown pseudo-op: .string
   |
16 |         .string "main"
   | ^

/var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/ghc58339_0/ghc_2.s:16:0: error:
    Rest of line ignored. 1st junk character valued 34 (").
   |
16 |         .string "main"
   | ^

/var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/ghc58339_0/ghc_2.s:43:0: error:
    Unknown pseudo-op: .string
   |
43 |         .string "Hello World"
   | ^

/var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/ghc58339_0/ghc_2.s:43:0: error:
    Rest of line ignored. 1st junk character valued 34 (").
   |
43 |         .string "Hello World"
   | ^
`gcc' failed in phase `Assembler'. (Exit code: 1)

benkios-MacBook-Pro:AdventOfCode benkio$ 

Hm, sorry, I don’t know how to help you. I learned the hard way never to use nix.
If you’re open to try something else, native installation through ghcup works out of the box.

That’s strange since nix should provide reproducible builds more than other package managers.
However, the same exact configuration/project works fine in my NixOs machine and this use/corner case is a good opportunity to investigate why this is happening, especially because cabal build works fine!
Therefore, I’m not blocked and I can still use/work on the project regardless of stack not working here. I’m sure there are workarounds, but it’s not the point here :wink:

nix on Mac is a joke, especially on M1. Never since I got my macbook was something working properly via nix.

I’m afraid I can not support that claim. Nix has been working fairly well for us on

  • x86_64-linux
  • aarch64-Linux
  • x86_64-darwin
  • aarch64-darwin
    And even WSL.

nix has been quite helpful for quickly and reliably providing a mostly generic development environment across Intel and Apple Silicon macs. (It’s also proven very useful during the initial AArch64 NCG development).

Try something like the following on an Apple Silicon Mac. You should be getting a shell with GHC and cabal as well as an Apple silicon (aarch64-darwin) toolchain.

nix develop github:input-output-hk/devx#ghc8107 --no-write-lock-file --system aarch64-darwin --refresh

On an Intel or Apple Silicon Mac

nix develop github:input-output-hk/devx#ghc8107 --no-write-lock-file --system x86_64-darwin --refresh

should give you a GHC and cabal shell as well as toolchain for Intel (x86_64) development.

The biggest issues on Apple silicon macs is that they are near transparent capable of running AArch64 and x86_64 code. Hence if your toolchain is misconfigured at any point in the pipeline, you can end up with mixing both architectures and thus build issues.

What we see above is the assembler not understanding the assembly emitted by the compiler.

2 Likes

And just to be perfectly clear here: Ghcup is an excellent way to bring up a dev environment as well. Brew also works for some. I’m not trying to defend nix much. It has certainly its issues, I simply disagree with your assessment that “nix is a joke”.

1 Like

I have an intel, so you just suggest to run the command:
nix develop github:input-output-hk/devx#ghc8107 --no-write-lock-file --system x86_64-darwin --refresh
at the root of the project?
I was expecting a nix-shell command :thinking:

PS: if that works, what I might do to fix my configuration?

What does

/Users/benkio/.stack/programs/x86_64-osx/ghc-9.2.5/bin/ghc-9.2.5 --info

print. If you are on an Intel mac this is even more confusing. Can you also past the contents of:

/var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/ghc58339_0/ghc_2.s

When using stack and nix to provision the dev env, you usually want to pass —system-ghc, to prevent stack from trying to bring its own.

This is the output of the two commands

benkios-MacBook-Pro:~ benkio$ /Users/benkio/.stack/programs/x86_64-osx/ghc-9.2.5/bin/ghc-9.2.5 --info
 [("Project name","The Glorious Glasgow Haskell Compilation System")
 ,("GCC extra via C opts","")
 ,("C compiler command","gcc")
 ,("C compiler flags","")
 ,("C++ compiler flags","")
 ,("C compiler link flags","")
 ,("C compiler supports -no-pie","YES")
 ,("Haskell CPP command","gcc")
 ,("Haskell CPP flags","-E -undef -traditional")
 ,("ld command","ld")
 ,("ld flags","")
 ,("ld supports compact unwind","YES")
 ,("ld supports build-id","NO")
 ,("ld supports filelist","YES")
 ,("ld is GNU ld","NO")
 ,("Merge objects command","ld")
 ,("Merge objects flags","-r")
 ,("ar command","ar")
 ,("ar flags","qcls")
 ,("ar supports at file","NO")
 ,("ranlib command","ranlib")
 ,("otool command","otool")
 ,("install_name_tool command","install_name_tool")
 ,("touch command","touch")
 ,("dllwrap command","/bin/false")
 ,("windres command","/bin/false")
 ,("libtool command","libtool")
 ,("unlit command","/Users/benkio/.stack/programs/x86_64-osx/ghc-9.2.5/lib/ghc-9.2.5/lib/bin/unlit")
 ,("cross compiling","NO")
 ,("target platform string","x86_64-apple-darwin")
 ,("target os","OSDarwin")
 ,("target arch","ArchX86_64")
 ,("target word size","8")
 ,("target word big endian","NO")
 ,("target has GNU nonexec stack","NO")
 ,("target has .ident directive","YES")
 ,("target has subsections via symbols","YES")
 ,("target has RTS linker","YES")
 ,("Unregisterised","NO")
 ,("LLVM target","x86_64-apple-darwin")
 ,("LLVM llc command","llc")
 ,("LLVM opt command","opt")
 ,("LLVM clang command","clang")
 ,("Use interpreter","YES")
 ,("Support SMP","YES")
 ,("RTS ways","l debug thr thr_debug thr_l thr_p dyn debug_dyn thr_dyn thr_debug_dyn l_dyn thr_l_dyn thr_debug_p debug_p")
 ,("Tables next to code","YES")
 ,("Leading underscore","YES")
 ,("Use LibFFI","NO")
 ,("RTS expects libdw","NO")
 ,("Project version","9.2.5")
 ,("Project Git commit id","74ca6191fa0dbbe8cee3dc53741b8d59fbf16b09")
 ,("Booter version","8.10.7")
 ,("Stage","2")
 ,("Build platform","x86_64-apple-darwin")
 ,("Host platform","x86_64-apple-darwin")
 ,("Target platform","x86_64-apple-darwin")
 ,("Have interpreter","YES")
 ,("Object splitting supported","NO")
 ,("Have native code generator","YES")
 ,("Target default backend","NCG")
 ,("Support dynamic-too","YES")
 ,("Support parallel --make","YES")
 ,("Support reexported-modules","YES")
 ,("Support thinning and renaming package flags","YES")
 ,("Support Backpack","YES")
 ,("Requires unified installed package IDs","YES")
 ,("Uses package keys","YES")
 ,("Uses unit IDs","YES")
 ,("GHC Dynamic","YES")
 ,("GHC Profiled","NO")
 ,("Debug on","NO")
 ,("LibDir","/Users/benkio/.stack/programs/x86_64-osx/ghc-9.2.5/lib/ghc-9.2.5/lib")
 ,("Global Package DB","/Users/benkio/.stack/programs/x86_64-osx/ghc-9.2.5/lib/ghc-9.2.5/lib/package.conf.d")
 ]
benkios-MacBook-Pro:~ benkio$ cat /var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/ghc58339_0/ghc_2.s
cat: /var/folders/38/tqfffwwn65q8ydzr08fyl7m00000gn/T/ghc58339_0/ghc_2.s: No such file or directory
benkios-MacBook-Pro:~ benkio$