haskellPackages: when building with js backend, output jsexe directory alongside executable

This commit is contained in:
Alexandre Esteves
2025-04-06 23:28:01 +01:00
parent 5d9cbdc28e
commit a6aabc498c
@@ -514,6 +514,14 @@ let
intermediatesDir = "share/haskell/${ghc.version}/${pname}-${version}/dist";
# On old ghcjs, the jsexe directories are the output but on the js backend they seem to be treated as intermediates
jsexe = rec {
shouldUseNode = isGhcjs;
shouldAdd = stdenv.hostPlatform.isGhcjs && isExecutable;
shouldCopy = shouldAdd && !doInstallIntermediates;
shouldSymlink = shouldAdd && doInstallIntermediates;
};
# This is a script suitable for --test-wrapper of Setup.hs' test command
# (https://cabal.readthedocs.io/en/3.12/setup-commands.html#cmdoption-runhaskell-Setup.hs-test-test-wrapper).
# We use it to set some environment variables that the test suite may need,
@@ -820,7 +828,8 @@ lib.fix (
find $packageConfDir -maxdepth 0 -empty -delete;
''
}
${optionalString isGhcjs ''
${optionalString jsexe.shouldUseNode ''
for exeDir in "${binDir}/"*.jsexe; do
exe="''${exeDir%.jsexe}"
printWords '#!${nodejs}/bin/node' > "$exe"
@@ -831,6 +840,14 @@ lib.fix (
''}
${optionalString doCoverage "mkdir -p $out/share && cp -r dist/hpc $out/share"}
${optionalString jsexe.shouldCopy ''
for jsexeDir in dist/build/*/*.jsexe; do
bn=$(basename $jsexeDir)
exe="''${bn%.jsexe}"
cp -r dist/build/$exe/$exe.jsexe ${binDir}
done
''}
${optionalString enableSeparateDocOutput ''
for x in ${docdir "$doc"}"/html/src/"*.html; do
remove-references-to -t $out $x
@@ -849,6 +866,14 @@ lib.fix (
mkdir -p "$installIntermediatesDir"
cp -r dist/build "$installIntermediatesDir"
runHook postInstallIntermediates
${optionalString jsexe.shouldSymlink ''
for jsexeDir in $installIntermediatesDir/build/*/*.jsexe; do
bn=$(basename $jsexeDir)
exe="''${bn%.jsexe}"
(cd ${binDir} && ln -s $installIntermediatesDir/build/$exe/$exe.jsexe)
done
''}
'';
passthru = passthru // rec {