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

hsc2hs is broken when using JS backend from cross channel #1157

Open
aidatorajiro opened this issue Nov 17, 2024 · 2 comments
Open

hsc2hs is broken when using JS backend from cross channel #1157

aidatorajiro opened this issue Nov 17, 2024 · 2 comments

Comments

@aidatorajiro
Copy link

aidatorajiro commented Nov 17, 2024

What went wrong

Cabal fails clock-0.8.4 build.

Failed to build clock-0.8.4.                                                                                                                                 
Build log (                                                                                                                                                  
/home/*****/.cabal/logs/ghc-9.10.0.20240413/clock-0.8.4-af09122070b54a220a89abd377b3272fa8d08c9df858d129e2c223a1460da6bd.log                               
):                                                                                                                                                           
Configuring library for clock-0.8.4...                                                                                                                       
Preprocessing library for clock-0.8.4...                                                                                                                     
Error: [Cabal-1008]                                                                                                                                          
The program 'hsc2hs' is required but the version of /home/*****/.ghcup/ghc/javascript-unknown-ghcjs-9.10.0.20240413/bin/hsc2hs-ghc-9.10.0.20240413 could no
t be determined.                                                                                                                                             
                                                                                                                                                             
Error: [Cabal-7125]                                                                                                                                          
Failed to build clock-0.8.4 (which is required by exe:***** from *****). See the build log above for details.    

Way to reproduce

  1. Install ghcup and follow User Guide to install GHC JS cross 9.10.0.20240413
  2. Create a cabal project that requires clock.
  3. run cabal build --with-ghc=javascript-unknown-ghcjs-ghc-9.10.0.20240413 --with-ghc-pkg=javascript-unknown-ghcjs-ghc-pkg-9.10.0.20240413

Software versions

  • OS: Fedora release 41 / Arch Linux 2024-11-17 / Ubuntu 22.04 LTS
  • GHCup 0.1.30
  • cabal 3.12.1.0
  • ghc javascript-unknown-ghcjs-9.10.0.20240413 (via cross channel ghcup config add-release-channel https://raw.githubusercontent.com/haskell/ghcup-metadata/develop/ghcup-cross-0.0.8.yaml)

cause of the problem

The shell script file ~/.ghcup/ghc/javascript-unknown-ghcjs-9.10.0.20240413/bin/hsc2hs-ghc-9.10.0.20240413 has the wrong executable path.

quick solution for the problem

Adding javascript-unknown-ghcjs prefix to $executablename in ~/.ghcup/ghc/javascript-unknown-ghcjs-9.10.0.20240413/bin/hsc2hs-ghc-9.10.0.20240413 fixes the build issue.

Replace ~/.ghcup/ghc/javascript-unknown-ghcjs-9.10.0.20240413/bin/hsc2hs-ghc-9.10.0.20240413 with the following script.

#!/bin/bash

GHCVER=9.10.0.20240413
ARCHID=javascript-unknown-ghcjs

exedir="$HOME/.ghcup/ghc/$ARCHID-$GHCVER/lib/$ARCHID-ghc-$GHCVER/bin"
exeprog="./$ARCHID-hsc2hs-ghc-$GHCVER"
executablename="$HOME/.ghcup/ghc/$ARCHID-$GHCVER/lib/$ARCHID-ghc-$GHCVER/bin/./$ARCHID-hsc2hs-ghc-$GHCVER"
bindir="$HOME/.ghcup/ghc/$ARCHID-$GHCVER/bin"
libdir="$HOME/.ghcup/ghc/$ARCHID-$GHCVER/lib/$ARCHID-ghc-$GHCVER/lib"
docdir="$HOME/.ghcup/ghc/$ARCHID-$GHCVER/share/doc/$ARCHID-ghc-$GHCVER"
includedir="$HOME/.ghcup/ghc/$ARCHID-$GHCVER/include"

HSC2HS_C=" -Qunused-arguments"

HSC2HS_L=" "

tflag="--template=$libdir/template-hsc.h"
Iflag="-I$includedir/include/"

for f in ${HSC2HS_C}; do
  cflags="${cflags} --cflag=$f"
done

for f in ${HSC2HS_L}; do
  lflags="${lflags} --lflag=$f"
done

HSC2HS_EXTRA="$cflags $lflags"

read_response() {
    response_file=$1
    if [ -f "$response_file" ]; then
        while read -r arg; do
            case "$arg" in
                -t*)          tflag=;;
                --template=*) tflag=;;
                @*)           read_response "${arg#"@"}" ;;
                --)           break;;
            esac
        done < "$response_file"
    fi
}

for arg do
    case "$arg" in
        -t*)          tflag=;;
        --template=*) tflag=;;
        @*)           read_response "${arg#"@"}" ;;
        --)           break;;
    esac
done

exec "$executablename" ${tflag:+"$tflag"} $HSC2HS_EXTRA ${1+"$@"} "$Iflag"
@aidatorajiro
Copy link
Author

aidatorajiro commented Nov 17, 2024

Note: instead of replacing the script, simply appending --with-hsc2hs=javascript-unknown-ghcjs-hsc2hs-9.10.0.20240413 to cabal build (along with --with-ghc=javascript-unknown-ghcjs-ghc-9.10.0.20240413 --with-ghc-pkg=javascript-unknown-ghcjs-ghc-pkg-9.10.0.20240413) also fixes build.

@hasufell
Copy link
Member

This is expected. You have to tell cabal exactly what toolchain to use.

That's a bit cumbersome and could be documented.

It would be good if you could tell cabal a prefix it will then prepend to all tools. I thought there is a ticket for it, but I can't find it. Feel free to create one.

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

2 participants