From d3bc7df435bc9cb6126da5fe2fea92fb790f9d9f Mon Sep 17 00:00:00 2001 From: Samuel Evans-Powell Date: Sat, 11 May 2024 22:19:01 +0800 Subject: [PATCH 1/9] 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. --- test/default.nix | 1 + test/js-template-haskell/default.nix | 27 +++++++++++++++++++ .../js-template-haskell.cabal | 16 +++++++++++ test/js-template-haskell/src/MyLib.hs | 8 ++++++ 4 files changed, 52 insertions(+) create mode 100644 test/js-template-haskell/default.nix create mode 100644 test/js-template-haskell/js-template-haskell.cabal create mode 100644 test/js-template-haskell/src/MyLib.hs diff --git a/test/default.nix b/test/default.nix index abccf8f7b3..066d3a5aad 100644 --- a/test/default.nix +++ b/test/default.nix @@ -221,6 +221,7 @@ let cabal-project-nix-path = callTest ./cabal-project-nix-path {}; plugin = callTest ./plugin {}; supported-languages = callTest ./supported-langauges {}; + js-template-haskell = callTest ./js-template-haskell {}; unit = unitTests; }; diff --git a/test/js-template-haskell/default.nix b/test/js-template-haskell/default.nix new file mode 100644 index 0000000000..03bf9c48f7 --- /dev/null +++ b/test/js-template-haskell/default.nix @@ -0,0 +1,27 @@ +# Test building TH code that needs DLLs when cross compiling for windows +{ stdenv, lib, project', haskellLib, recurseIntoAttrs, testSrc, compiler-nix-name, ... }: + +with lib; + +let + project = project' { + inherit compiler-nix-name; + src = testSrc "js-template-haskell"; + modules = [ + # Fix node: createProcess: posix_spawnp: does not exist (No such file or directory) + # ({ pkgs,... }: { + # packages.js-template-haskell.components.library.build-tools = [ pkgs.pkgsBuildHost.nodejs ]; + # }) + ]; + }; + + packages = project.hsPkgs; + +in recurseIntoAttrs { + ifdInputs = { + inherit (project) plan-nix; + }; + + build = packages.js-template-haskell.components.library; + build-profiled = packages.js-template-haskell.components.library.profiled; +} diff --git a/test/js-template-haskell/js-template-haskell.cabal b/test/js-template-haskell/js-template-haskell.cabal new file mode 100644 index 0000000000..9f9ef76d90 --- /dev/null +++ b/test/js-template-haskell/js-template-haskell.cabal @@ -0,0 +1,16 @@ +cabal-version: 3.0 +name: js-template-haskell +version: 0.1.0.0 +category: Repro +build-type: Simple + +common warnings + ghc-options: -Wall + +library + import: warnings + exposed-modules: MyLib + build-depends: base ^>=4.19.1.0 + , uri-bytestring + hs-source-dirs: src + default-language: Haskell2010 diff --git a/test/js-template-haskell/src/MyLib.hs b/test/js-template-haskell/src/MyLib.hs new file mode 100644 index 0000000000..564b5e992d --- /dev/null +++ b/test/js-template-haskell/src/MyLib.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE QuasiQuotes #-} + +module MyLib (someFunc) where + +import URI.ByteString.QQ + +someFunc :: IO () +someFunc = putStrLn $ show [uri|https://www.example.com/|] From 617e50e0412b5b3075e430a754b58c02506e9286 Mon Sep 17 00:00:00 2001 From: Samuel Evans-Powell Date: Sun, 12 May 2024 08:56:16 +0800 Subject: [PATCH 2/9] Remove unnecesary base constraint --- test/js-template-haskell/js-template-haskell.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/js-template-haskell/js-template-haskell.cabal b/test/js-template-haskell/js-template-haskell.cabal index 9f9ef76d90..26d6878c91 100644 --- a/test/js-template-haskell/js-template-haskell.cabal +++ b/test/js-template-haskell/js-template-haskell.cabal @@ -10,7 +10,7 @@ common warnings library import: warnings exposed-modules: MyLib - build-depends: base ^>=4.19.1.0 + build-depends: base , uri-bytestring hs-source-dirs: src default-language: Haskell2010 From 6ab325fec1563ba3fd84353a324d771217fa021f Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Wed, 15 May 2024 13:06:42 +1200 Subject: [PATCH 3/9] GHC JS backend fixes --- builder/comp-builder.nix | 3 ++- builder/hspkg-builder.nix | 6 ++++-- modules/component-driver.nix | 2 +- overlays/ghc-packages.nix | 2 +- test/js-template-haskell/default.nix | 7 +------ .../js-template-haskell.cabal | 5 +++++ test/js-template-haskell/src/MyLib.hs | 7 ++++--- test/js-template-haskell/test/Main.hs | 17 +++++++++++++++++ 8 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 test/js-template-haskell/test/Main.hs diff --git a/builder/comp-builder.nix b/builder/comp-builder.nix index 0a8b191180..946856a84b 100644 --- a/builder/comp-builder.nix +++ b/builder/comp-builder.nix @@ -418,7 +418,8 @@ let nativeBuildInputs = [ghc buildPackages.removeReferencesTo] - ++ executableToolDepends; + ++ executableToolDepends + ++ (lib.optional stdenv.hostPlatform.isGhcjs buildPackages.nodejs); outputs = ["out"] ++ (lib.optional keepConfigFiles "configFiles") diff --git a/builder/hspkg-builder.nix b/builder/hspkg-builder.nix index 88ede9942d..7a24ebea2f 100644 --- a/builder/hspkg-builder.nix +++ b/builder/hspkg-builder.nix @@ -31,11 +31,13 @@ let cabalFile = if package-description-override == null || bundledSrc != null then null else package-description-override; - defaultSetupSrc = if stdenv.hostPlatform.isGhcjs then ./Setup.ghcjs.hs else ./Setup.hs; + # New GHC JS backend run emcc itself without the need for custom Setup.hs + oldGhcjs = stdenv.hostPlatform.isGhcjs && builtins.compareVersions ghc.version "9.10" < 0; + defaultSetupSrc = if oldGhcjs then ./Setup.ghcjs.hs else ./Setup.hs; setup = if package.buildType == "Simple" then - 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) + if oldGhcjs then buildPackages.haskell-nix.nix-tools-unchecked.exes.default-setup-ghcjs // { exeName = "default-setup-ghcjs"; } else diff --git a/modules/component-driver.nix b/modules/component-driver.nix index e4b91411f5..d2b43a8383 100644 --- a/modules/component-driver.nix +++ b/modules/component-driver.nix @@ -24,7 +24,7 @@ in options.reinstallableLibGhc = lib.mkOption { type = lib.types.bool; - default = true; + default = !pkgs.stdenv.hostPlatform.isGhcjs; description = "Is lib:ghc reinstallable?"; }; options.setup-depends = lib.mkOption { diff --git a/overlays/ghc-packages.nix b/overlays/ghc-packages.nix index d3c04aab5c..0a67af3123 100644 --- a/overlays/ghc-packages.nix +++ b/overlays/ghc-packages.nix @@ -73,7 +73,7 @@ let iserv = "utils/iserv"; } // final.lib.optionalAttrs ((!final.stdenv.hostPlatform.isGhcjs || builtins.compareVersions ghcVersion "9.6" < 0) && builtins.compareVersions ghcVersion "9.8" < 0) { libiserv = "libraries/libiserv"; - } // final.lib.optionalAttrs (!final.stdenv.hostPlatform.isGhcjs) { + } // final.lib.optionalAttrs (!final.stdenv.hostPlatform.isGhcjs || builtins.compareVersions ghcVersion "9" > 0) { ghc = "compiler"; ghc-boot = "libraries/ghc-boot"; } // ( diff --git a/test/js-template-haskell/default.nix b/test/js-template-haskell/default.nix index 03bf9c48f7..ee2d1da4ab 100644 --- a/test/js-template-haskell/default.nix +++ b/test/js-template-haskell/default.nix @@ -7,12 +7,6 @@ let project = project' { inherit compiler-nix-name; src = testSrc "js-template-haskell"; - modules = [ - # Fix node: createProcess: posix_spawnp: does not exist (No such file or directory) - # ({ pkgs,... }: { - # packages.js-template-haskell.components.library.build-tools = [ pkgs.pkgsBuildHost.nodejs ]; - # }) - ]; }; packages = project.hsPkgs; @@ -24,4 +18,5 @@ in recurseIntoAttrs { build = packages.js-template-haskell.components.library; build-profiled = packages.js-template-haskell.components.library.profiled; + check = packages.js-template-haskell.checks.test; } diff --git a/test/js-template-haskell/js-template-haskell.cabal b/test/js-template-haskell/js-template-haskell.cabal index 26d6878c91..581a25d00d 100644 --- a/test/js-template-haskell/js-template-haskell.cabal +++ b/test/js-template-haskell/js-template-haskell.cabal @@ -14,3 +14,8 @@ library , uri-bytestring hs-source-dirs: src default-language: Haskell2010 + +test-suite test + type: exitcode-stdio-1.0 + main-is: test/Main.hs + build-depends: base, js-template-haskell diff --git a/test/js-template-haskell/src/MyLib.hs b/test/js-template-haskell/src/MyLib.hs index 564b5e992d..6ddb945f5a 100644 --- a/test/js-template-haskell/src/MyLib.hs +++ b/test/js-template-haskell/src/MyLib.hs @@ -1,8 +1,9 @@ {-# LANGUAGE QuasiQuotes #-} -module MyLib (someFunc) where +module MyLib (someUri) where import URI.ByteString.QQ -someFunc :: IO () -someFunc = putStrLn $ show [uri|https://www.example.com/|] +someUri :: String +someUri = show [uri|https://www.example.com/|] + diff --git a/test/js-template-haskell/test/Main.hs b/test/js-template-haskell/test/Main.hs new file mode 100644 index 0000000000..ee4d65ab3c --- /dev/null +++ b/test/js-template-haskell/test/Main.hs @@ -0,0 +1,17 @@ +module Main where + +import Control.Monad (unless) +import System.Exit (exitFailure) + +import MyLib (someUri) + +expected, actual :: String +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}" +actual = someUri + +main :: IO () +main = + unless (expected == actual) $ do + putStrLn $ "Unexpected TH result : " <> actual + exitFailure + From b5a3eba21064aaf04be28aa56c52719ceb17e349 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Thu, 16 May 2024 15:23:32 +1200 Subject: [PATCH 4/9] Workarounds for ghc 9.10 --- test/c-ffi/default.nix | 2 +- test/js-template-haskell/js-template-haskell.cabal | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/test/c-ffi/default.nix b/test/c-ffi/default.nix index f03ac119fe..2f8d741805 100644 --- a/test/c-ffi/default.nix +++ b/test/c-ffi/default.nix @@ -57,7 +57,7 @@ in recurseIntoAttrs { meta = rec { platforms = lib.platforms.all; - broken = stdenv.hostPlatform.isGhcjs && __compareVersions buildPackages.haskell-nix.compiler.${compiler-nix-name}.version "9.6.1" >= 0; + broken = stdenv.hostPlatform.isGhcjs && __compareVersions buildPackages.haskell-nix.compiler.${compiler-nix-name}.version "9.10.1" >= 0; disabled = broken; }; diff --git a/test/js-template-haskell/js-template-haskell.cabal b/test/js-template-haskell/js-template-haskell.cabal index 581a25d00d..550b546918 100644 --- a/test/js-template-haskell/js-template-haskell.cabal +++ b/test/js-template-haskell/js-template-haskell.cabal @@ -19,3 +19,6 @@ test-suite test type: exitcode-stdio-1.0 main-is: test/Main.hs build-depends: base, js-template-haskell + if arch(javascript) && impl(ghc >=9.10.1) + ghc-options: -ddisable-js-c-sources + From b054dc329ff00a78e95239db564b776c0c5018c0 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Thu, 16 May 2024 21:14:26 +1200 Subject: [PATCH 5/9] Disable c-ffi test for js backend --- test/c-ffi/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/c-ffi/default.nix b/test/c-ffi/default.nix index 2f8d741805..f03ac119fe 100644 --- a/test/c-ffi/default.nix +++ b/test/c-ffi/default.nix @@ -57,7 +57,7 @@ in recurseIntoAttrs { meta = rec { platforms = lib.platforms.all; - broken = stdenv.hostPlatform.isGhcjs && __compareVersions buildPackages.haskell-nix.compiler.${compiler-nix-name}.version "9.10.1" >= 0; + broken = stdenv.hostPlatform.isGhcjs && __compareVersions buildPackages.haskell-nix.compiler.${compiler-nix-name}.version "9.6.1" >= 0; disabled = broken; }; From 15973d3bcaa0d860f2aadc5d6428af32f18b2545 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Fri, 17 May 2024 00:11:45 +1200 Subject: [PATCH 6/9] Disable broken tests --- test/js-template-haskell/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/js-template-haskell/default.nix b/test/js-template-haskell/default.nix index ee2d1da4ab..4a1ca1e228 100644 --- a/test/js-template-haskell/default.nix +++ b/test/js-template-haskell/default.nix @@ -16,7 +16,11 @@ in recurseIntoAttrs { inherit (project) plan-nix; }; + meta.disable = haskellLib.isCrossHost && stdenv.hostPlatform.isAarch64; + build = packages.js-template-haskell.components.library; - build-profiled = packages.js-template-haskell.components.library.profiled; check = packages.js-template-haskell.checks.test; +} // optionalAttrs (!stdenv.hostPlatform.isGhcjs) { + build-profiled = packages.js-template-haskell.components.library.profiled; + check = packages.js-template-haskell.checks.test.profiled; } From b441ab24684140ce88c4dfc10c139b0293202e7b Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Fri, 17 May 2024 10:16:14 +1200 Subject: [PATCH 7/9] Add .profiled and .dwarft checks --- lib/check.nix | 5 ++++- test/js-template-haskell/default.nix | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/check.nix b/lib/check.nix index 19682ca836..505aa92ac9 100644 --- a/lib/check.nix +++ b/lib/check.nix @@ -1,5 +1,5 @@ { stdenv, lib, haskellLib, buildPackages }: -drv: +let self = drv: let component = drv.config; @@ -28,6 +28,8 @@ in stdenv.mkDerivation (( passthru = { inherit (drv) identifier config configFiles executableToolDepends cleanSrc env exeName; + profiled = self drv.profiled; + dwarf = self drv.dwarf; }; inherit (drv) meta LANG LC_ALL buildInputs; @@ -63,3 +65,4 @@ in stdenv.mkDerivation (( } // lib.optionalAttrs (drv ? LOCALE_ARCHIVE) { inherit (drv) LOCALE_ARCHIVE; } ) +in self \ No newline at end of file diff --git a/test/js-template-haskell/default.nix b/test/js-template-haskell/default.nix index 4a1ca1e228..cf2a63cf95 100644 --- a/test/js-template-haskell/default.nix +++ b/test/js-template-haskell/default.nix @@ -16,11 +16,11 @@ in recurseIntoAttrs { inherit (project) plan-nix; }; - meta.disable = haskellLib.isCrossHost && stdenv.hostPlatform.isAarch64; + meta.disabled = haskellLib.isCrossHost && stdenv.hostPlatform.isAarch64; build = packages.js-template-haskell.components.library; check = packages.js-template-haskell.checks.test; } // optionalAttrs (!stdenv.hostPlatform.isGhcjs) { build-profiled = packages.js-template-haskell.components.library.profiled; - check = packages.js-template-haskell.checks.test.profiled; + check-profiled = packages.js-template-haskell.checks.test.profiled; } From a13deb130203cd65a62e5a77f51138ed7ae57ffe Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Fri, 17 May 2024 13:14:36 +1200 Subject: [PATCH 8/9] Add .profiled and .dwarft checks --- lib/check.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/check.nix b/lib/check.nix index 505aa92ac9..81a0047dd1 100644 --- a/lib/check.nix +++ b/lib/check.nix @@ -64,5 +64,5 @@ in stdenv.mkDerivation (( inherit (component) preCheck postCheck; } // lib.optionalAttrs (drv ? LOCALE_ARCHIVE) { inherit (drv) LOCALE_ARCHIVE; } -) +); in self \ No newline at end of file From 3203a09bba968044f0fbec18defd5b52c66c0646 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Fri, 17 May 2024 14:28:22 +1200 Subject: [PATCH 9/9] Exclude test for musl on aarch64 --- test/js-template-haskell/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/js-template-haskell/default.nix b/test/js-template-haskell/default.nix index cf2a63cf95..81d518f2c6 100644 --- a/test/js-template-haskell/default.nix +++ b/test/js-template-haskell/default.nix @@ -16,7 +16,7 @@ in recurseIntoAttrs { inherit (project) plan-nix; }; - meta.disabled = haskellLib.isCrossHost && stdenv.hostPlatform.isAarch64; + meta.disabled = stdenv.buildPlatform != stdenv.hostPlatform && stdenv.hostPlatform.isAarch64; build = packages.js-template-haskell.components.library; check = packages.js-template-haskell.checks.test;