Skip to content

Commit 093ab6c

Browse files
Add reproduction case for failing quasiquoting when using JS backend (#2199)
* Add reproduction case for failing quasiquoting when using JS backend - The JS backend is failing with ghc-9.8.2 due to missing "nodejs" executable and "ghci" package. - Uncommenting the code in "modules" of "test/js-template-haskell/default.nix" will fix the nodejs issue. - Unsure how to fix the "ghci" issue. * Remove unnecesary base constraint * GHC JS backend fixes * Workarounds for ghc 9.10 * Disable c-ffi test for js backend * Disable broken tests * Add .profiled and .dwarft checks * Add .profiled and .dwarft checks * Exclude test for musl on aarch64 --------- Co-authored-by: Samuel Evans-Powell <[email protected]>
1 parent 236e79c commit 093ab6c

File tree

10 files changed

+90
-7
lines changed

10 files changed

+90
-7
lines changed

builder/comp-builder.nix

+2-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,8 @@ let
418418

419419
nativeBuildInputs =
420420
[ghc buildPackages.removeReferencesTo]
421-
++ executableToolDepends;
421+
++ executableToolDepends
422+
++ (lib.optional stdenv.hostPlatform.isGhcjs buildPackages.nodejs);
422423

423424
outputs = ["out"]
424425
++ (lib.optional keepConfigFiles "configFiles")

builder/hspkg-builder.nix

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ let
3131

3232
cabalFile = if package-description-override == null || bundledSrc != null then null else package-description-override;
3333

34-
defaultSetupSrc = if stdenv.hostPlatform.isGhcjs then ./Setup.ghcjs.hs else ./Setup.hs;
34+
# New GHC JS backend run emcc itself without the need for custom Setup.hs
35+
oldGhcjs = stdenv.hostPlatform.isGhcjs && builtins.compareVersions ghc.version "9.10" < 0;
36+
defaultSetupSrc = if oldGhcjs then ./Setup.ghcjs.hs else ./Setup.hs;
3537

3638
setup = if package.buildType == "Simple"
3739
then
38-
if stdenv.targetPlatform.isGhcjs # TODO probably should be hostPlatform, but only HsColour used to build ghc will change (updating will require rebuilding all the ghcjs versions)
40+
if oldGhcjs
3941
then
4042
buildPackages.haskell-nix.nix-tools-unchecked.exes.default-setup-ghcjs // { exeName = "default-setup-ghcjs"; }
4143
else

lib/check.nix

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{ stdenv, lib, haskellLib, buildPackages }:
2-
drv:
2+
let self = drv:
33

44
let
55
component = drv.config;
@@ -28,6 +28,8 @@ in stdenv.mkDerivation ((
2828

2929
passthru = {
3030
inherit (drv) identifier config configFiles executableToolDepends cleanSrc env exeName;
31+
profiled = self drv.profiled;
32+
dwarf = self drv.dwarf;
3133
};
3234

3335
inherit (drv) meta LANG LC_ALL buildInputs;
@@ -62,4 +64,5 @@ in stdenv.mkDerivation ((
6264
inherit (component) preCheck postCheck;
6365
}
6466
// lib.optionalAttrs (drv ? LOCALE_ARCHIVE) { inherit (drv) LOCALE_ARCHIVE; }
65-
)
67+
);
68+
in self

modules/component-driver.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ in
2424

2525
options.reinstallableLibGhc = lib.mkOption {
2626
type = lib.types.bool;
27-
default = true;
27+
default = !pkgs.stdenv.hostPlatform.isGhcjs;
2828
description = "Is lib:ghc reinstallable?";
2929
};
3030
options.setup-depends = lib.mkOption {

overlays/ghc-packages.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ let
7373
iserv = "utils/iserv";
7474
} // final.lib.optionalAttrs ((!final.stdenv.hostPlatform.isGhcjs || builtins.compareVersions ghcVersion "9.6" < 0) && builtins.compareVersions ghcVersion "9.8" < 0) {
7575
libiserv = "libraries/libiserv";
76-
} // final.lib.optionalAttrs (!final.stdenv.hostPlatform.isGhcjs) {
76+
} // final.lib.optionalAttrs (!final.stdenv.hostPlatform.isGhcjs || builtins.compareVersions ghcVersion "9" > 0) {
7777
ghc = "compiler";
7878
ghc-boot = "libraries/ghc-boot";
7979
} // (

test/default.nix

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ let
221221
cabal-project-nix-path = callTest ./cabal-project-nix-path {};
222222
plugin = callTest ./plugin {};
223223
supported-languages = callTest ./supported-langauges {};
224+
js-template-haskell = callTest ./js-template-haskell {};
224225
unit = unitTests;
225226
};
226227

test/js-template-haskell/default.nix

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Test building TH code that needs DLLs when cross compiling for windows
2+
{ stdenv, lib, project', haskellLib, recurseIntoAttrs, testSrc, compiler-nix-name, ... }:
3+
4+
with lib;
5+
6+
let
7+
project = project' {
8+
inherit compiler-nix-name;
9+
src = testSrc "js-template-haskell";
10+
};
11+
12+
packages = project.hsPkgs;
13+
14+
in recurseIntoAttrs {
15+
ifdInputs = {
16+
inherit (project) plan-nix;
17+
};
18+
19+
meta.disabled = stdenv.buildPlatform != stdenv.hostPlatform && stdenv.hostPlatform.isAarch64;
20+
21+
build = packages.js-template-haskell.components.library;
22+
check = packages.js-template-haskell.checks.test;
23+
} // optionalAttrs (!stdenv.hostPlatform.isGhcjs) {
24+
build-profiled = packages.js-template-haskell.components.library.profiled;
25+
check-profiled = packages.js-template-haskell.checks.test.profiled;
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
cabal-version: 3.0
2+
name: js-template-haskell
3+
version: 0.1.0.0
4+
category: Repro
5+
build-type: Simple
6+
7+
common warnings
8+
ghc-options: -Wall
9+
10+
library
11+
import: warnings
12+
exposed-modules: MyLib
13+
build-depends: base
14+
, uri-bytestring
15+
hs-source-dirs: src
16+
default-language: Haskell2010
17+
18+
test-suite test
19+
type: exitcode-stdio-1.0
20+
main-is: test/Main.hs
21+
build-depends: base, js-template-haskell
22+
if arch(javascript) && impl(ghc >=9.10.1)
23+
ghc-options: -ddisable-js-c-sources
24+

test/js-template-haskell/src/MyLib.hs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{-# LANGUAGE QuasiQuotes #-}
2+
3+
module MyLib (someUri) where
4+
5+
import URI.ByteString.QQ
6+
7+
someUri :: String
8+
someUri = show [uri|https://www.example.com/|]
9+

test/js-template-haskell/test/Main.hs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Main where
2+
3+
import Control.Monad (unless)
4+
import System.Exit (exitFailure)
5+
6+
import MyLib (someUri)
7+
8+
expected, actual :: String
9+
expected = "URI {uriScheme = Scheme {schemeBS = \"https\"}, uriAuthority = Just (Authority {authorityUserInfo = Nothing, authorityHost = Host {hostBS = \"www.example.com\"}, authorityPort = Nothing}), uriPath = \"/\", uriQuery = Query {queryPairs = []}, uriFragment = Nothing}"
10+
actual = someUri
11+
12+
main :: IO ()
13+
main =
14+
unless (expected == actual) $ do
15+
putStrLn $ "Unexpected TH result : " <> actual
16+
exitFailure
17+

0 commit comments

Comments
 (0)