diff --git a/.gitignore b/.gitignore index b698d53ab4..93d660fcc2 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,9 @@ doc/icfp-2012.html download/*.html gf-book/index.html src/www/gf-web-api.html +.devenv +.direnv +result +.vscode +.envrc +.pre-commit-config.yaml \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..76296d9859 --- /dev/null +++ b/flake.lock @@ -0,0 +1,252 @@ +{ + "nodes": { + "devenv": { + "inputs": { + "flake-compat": "flake-compat", + "nix": "nix", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + }, + "locked": { + "lastModified": 1700140236, + "narHash": "sha256-OpukFO0rRG2hJzD+pCQq+nSWuT9dBL6DSvADQaUlmFg=", + "owner": "cachix", + "repo": "devenv", + "rev": "525d60c44de848a6b2dd468f6efddff078eb2af2", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "devenv", + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "lowdown-src": { + "flake": false, + "locked": { + "lastModified": 1633514407, + "narHash": "sha256-Dw32tiMjdK9t3ETl5fzGrutQTzh2rufgZV4A/BbxuD4=", + "owner": "kristapsdz", + "repo": "lowdown", + "rev": "d2c2b44ff6c27b936ec27358a2653caaef8f73b8", + "type": "github" + }, + "original": { + "owner": "kristapsdz", + "repo": "lowdown", + "type": "github" + } + }, + "nix": { + "inputs": { + "lowdown-src": "lowdown-src", + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "nixpkgs-regression": "nixpkgs-regression" + }, + "locked": { + "lastModified": 1676545802, + "narHash": "sha256-EK4rZ+Hd5hsvXnzSzk2ikhStJnD63odF7SzsQ8CuSPU=", + "owner": "domenkozar", + "repo": "nix", + "rev": "7c91803598ffbcfe4a55c44ac6d49b2cf07a527f", + "type": "github" + }, + "original": { + "owner": "domenkozar", + "ref": "relaxed-flakes", + "repo": "nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1678875422, + "narHash": "sha256-T3o6NcQPwXjxJMn2shz86Chch4ljXgZn746c2caGxd8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "126f49a01de5b7e35a43fd43f891ecf6d3a51459", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-regression": { + "locked": { + "lastModified": 1643052045, + "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1699994397, + "narHash": "sha256-xxNeIcMNMXH2EA9IAX6Cny+50mvY22LhIBiGZV363gc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d4b5a67bbe9ef750bd2fdffd4cad400dd5553af8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": [ + "devenv", + "flake-compat" + ], + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1688056373, + "narHash": "sha256-2+SDlNRTKsgo3LBRiMUcoEUb6sDViRNQhzJquZ4koOI=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "5843cf069272d92b60c3ed9e55b7a8989c01d4c7", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "nixpkgs": "nixpkgs_2", + "systems": "systems_2" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..682cf866ba --- /dev/null +++ b/flake.nix @@ -0,0 +1,110 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; + systems.url = "github:nix-systems/default"; + devenv.url = "github:cachix/devenv"; + }; + + nixConfig = { + extra-trusted-public-keys = + "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="; + extra-substituters = "https://devenv.cachix.org"; + }; + + outputs = { self, nixpkgs, devenv, systems, ... }@inputs: + let forEachSystem = nixpkgs.lib.genAttrs (import systems); + in { + packages = forEachSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + haskellPackages = pkgs.haskell.packages.ghc925.override { + overrides = self: _super: { + cgi = pkgs.haskell.lib.unmarkBroken (pkgs.haskell.lib.dontCheck + (self.callHackage "cgi" "3001.5.0.1" { })); + }; + }; + + in { + devenv-up = self.devShells.${system}.default.config.procfileScript; + gf = pkgs.haskell.lib.overrideCabal + (haskellPackages.callCabal2nixWithOptions "gf" self "--flag=-server" + { }) (_old: { + # Fix utf8 encoding problems + patches = [ + # Already applied in master + # ( + # pkgs.fetchpatch { + # url = "https://github.com/anka-213/gf-core/commit/6f1ca05fddbcbc860898ddf10a557b513dfafc18.patch"; + # sha256 = "17vn3hncxm1dwbgpfmrl6gk6wljz3r28j191lpv5zx741pmzgbnm"; + # } + # ) + ./nix/expose-all.patch + ./nix/revert-new-cabal-madness.patch + ]; + jailbreak = true; + # executableSystemDepends = [ + # (pkgs.ncurses.override { enableStatic = true; }) + # ]; + # executableHaskellDepends = [ ]; + }); + }); + + devShells = forEachSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + + in with pkgs.darwin.apple_sdk.frameworks; + let + darwinPkgs = + + if pkgs.stdenv.isDarwin then [ Cocoa pkgs.clang ] else [ ]; + in { + + default = devenv.lib.mkShell { + inherit inputs pkgs; + modules = [{ + # https://devenv.sh/basics/ + env.GREET = "devenv"; + + # https://devenv.sh/packages/ + packages = [ pkgs.git pkgs.llvm ] ++ darwinPkgs; + + # https://devenv.sh/scripts/ + scripts.hello.exec = "echo hello from $GREET"; + + enterShell = '' + hello + git --version + ''; + + languages.haskell = { + enable = true; + # HLS fails to build on darwin and 9.2.5 + languageServer = null; + package = pkgs.haskell.compiler.ghc925; + }; + + # https://devenv.sh/pre-commit-hooks/ + pre-commit.hooks = { + # lint shell scripts + shellcheck.enable = true; + markdownlint.enable = true; + # lint nix + nixfmt.enable = true; + deadnix.enable = true; + nil.enable = true; + # statix.enable = true; + # format haskell + # ormolu.enable = true; + # cabal-fmt.enable = true; + # lint haskell + # hlint.enable = true; + }; + # https://devenv.sh/processes/ + # processes.ping.exec = "ping example.com"; + + # See full reference at https://devenv.sh/reference/options/ + }]; + }; + }); + }; +} diff --git a/gf.cabal b/gf.cabal index 21093ae0be..b5a895f2b3 100644 --- a/gf.cabal +++ b/gf.cabal @@ -73,7 +73,7 @@ library build-depends: -- GHC 8.0.2 to GHC 8.10.4 array >= 0.5.1 && < 0.6, - base >= 4.9.1 && < 4.17, + base >= 4.9.1 && < 4.18, bytestring >= 0.10.8 && < 0.12, containers >= 0.5.7 && < 0.7, exceptions >= 0.8.3 && < 0.11, diff --git a/nix/expose-all.patch b/nix/expose-all.patch new file mode 100644 index 0000000000..bca5291577 --- /dev/null +++ b/nix/expose-all.patch @@ -0,0 +1,12 @@ +diff --git a/gf.cabal b/gf.cabal +index 0076e7638..8d3fe4b49 100644 +--- a/gf.cabal ++++ b/gf.cabal +@@ -168,7 +168,6 @@ Library + GF.Text.Lexing + GF.Grammar.Canonical + +- other-modules: + GF.Main + GF.Compiler + GF.Interactive \ No newline at end of file diff --git a/nix/revert-new-cabal-madness.patch b/nix/revert-new-cabal-madness.patch new file mode 100644 index 0000000000..1a1a40db9d --- /dev/null +++ b/nix/revert-new-cabal-madness.patch @@ -0,0 +1,193 @@ +commit 45e5473fcd5707af93646d9a116867a4d4e3e9c9 +Author: Andreas Källberg +Date: Mon Oct 10 14:57:12 2022 +0200 + + Revert "workaround for the Nix madness" + + This reverts commit 1294269cd60f3db7b056135104615625baeb528c. + + There are easier workarounds, like using + + cabal v1-build + + etc. instead of just `cabal build` + + These changes also broke a whole bunch of other stuff + +diff --git a/README.md b/README.md +index ba35795a4..79e6ab68f 100644 +--- a/README.md ++++ b/README.md +@@ -38,21 +38,6 @@ or: + ``` + stack install + ``` +-Note that if you are unlucky to have Cabal 3.0 or later, then it uses +-the so-called Nix style commands. Using those for GF development is +-a pain. Every time when you change something in the source code, Cabal +-will generate a new folder for GF to look for the GF libraries and +-the GF cloud. Either reinstall everything with every change in the +-compiler, or be sane and stop using cabal-install. Instead you can do: +-``` +-runghc Setup.hs configure +-runghc Setup.hs build +-sudo runghc Setup.hs install +-``` +-The script will install the GF dependencies globally. The only solution +-to the Nix madness that I found is radical: +- +- "No person, no problem" (Нет человека – нет проблемы). + + For more information, including links to precompiled binaries, see the [download page](https://www.grammaticalframework.org/download/index.html). + +diff --git a/Setup.hs b/Setup.hs +index 58dc3e0c6..f8309cc00 100644 +--- a/Setup.hs ++++ b/Setup.hs +@@ -4,68 +4,42 @@ import Distribution.Simple.LocalBuildInfo(LocalBuildInfo(..),absoluteInstallDirs + import Distribution.Simple.Setup(BuildFlags(..),Flag(..),InstallFlags(..),CopyDest(..),CopyFlags(..),SDistFlags(..)) + import Distribution.PackageDescription(PackageDescription(..),emptyHookedBuildInfo) + import Distribution.Simple.BuildPaths(exeExtension) +-import System.Directory + import System.FilePath((),(<.>)) +-import System.Process +-import Control.Monad(forM_,unless) +-import Control.Exception(bracket_) +-import Data.Char(isSpace) + + import WebSetup + ++-- | Notice about RGL not built anymore ++noRGLmsg :: IO () ++noRGLmsg = putStrLn "Notice: the RGL is not built as part of GF anymore. See https://github.com/GrammaticalFramework/gf-rgl" ++ + main :: IO () + main = defaultMainWithHooks simpleUserHooks +- { preConf = gfPreConf +- , preBuild = gfPreBuild ++ { preBuild = gfPreBuild + , postBuild = gfPostBuild + , preInst = gfPreInst + , postInst = gfPostInst + , postCopy = gfPostCopy + } + where +- gfPreConf args flags = do +- pkgs <- fmap (map (dropWhile isSpace) . tail . lines) +- (readProcess "ghc-pkg" ["list"] "") +- forM_ dependencies $ \pkg -> do +- let name = takeWhile (/='/') (drop 36 pkg) +- unless (name `elem` pkgs) $ do +- let fname = name <.> ".tar.gz" +- callProcess "wget" [pkg,"-O",fname] +- callProcess "tar" ["-xzf",fname] +- removeFile fname +- bracket_ (setCurrentDirectory name) (setCurrentDirectory ".." >> removeDirectoryRecursive name) $ do +- exists <- doesFileExist "Setup.hs" +- unless exists $ do +- writeFile "Setup.hs" (unlines [ +- "import Distribution.Simple", +- "main = defaultMain" +- ]) +- let to_descr = reverse . +- (++) (reverse ".cabal") . +- drop 1 . +- dropWhile (/='-') . +- reverse +- callProcess "wget" [to_descr pkg, "-O", to_descr name] +- callProcess "runghc" ["Setup.hs","configure"] +- callProcess "runghc" ["Setup.hs","build"] +- callProcess "sudo" ["runghc","Setup.hs","install"] +- +- preConf simpleUserHooks args flags +- +- gfPreBuild args = gfPre args . buildDistPref +- gfPreInst args = gfPre args . installDistPref ++ gfPreBuild args = gfPre args . buildDistPref ++ gfPreInst args = gfPre args . installDistPref + + gfPre args distFlag = do + return emptyHookedBuildInfo + + gfPostBuild args flags pkg lbi = do ++ -- noRGLmsg + let gf = default_gf lbi + buildWeb gf flags (pkg,lbi) + + gfPostInst args flags pkg lbi = do ++ -- noRGLmsg ++ saveInstallPath args flags (pkg,lbi) + installWeb (pkg,lbi) + + gfPostCopy args flags pkg lbi = do ++ -- noRGLmsg ++ saveCopyPath args flags (pkg,lbi) + copyWeb flags (pkg,lbi) + + -- `cabal sdist` will not make a proper dist archive, for that see `make sdist` +@@ -73,16 +47,27 @@ main = defaultMainWithHooks simpleUserHooks + gfSDist pkg lbi hooks flags = do + return () + +-dependencies = [ +- "https://hackage.haskell.org/package/utf8-string-1.0.2/utf8-string-1.0.2.tar.gz", +- "https://hackage.haskell.org/package/json-0.10/json-0.10.tar.gz", +- "https://hackage.haskell.org/package/network-bsd-2.8.1.0/network-bsd-2.8.1.0.tar.gz", +- "https://hackage.haskell.org/package/httpd-shed-0.4.1.1/httpd-shed-0.4.1.1.tar.gz", +- "https://hackage.haskell.org/package/exceptions-0.10.5/exceptions-0.10.5.tar.gz", +- "https://hackage.haskell.org/package/stringsearch-0.3.6.6/stringsearch-0.3.6.6.tar.gz", +- "https://hackage.haskell.org/package/multipart-0.2.1/multipart-0.2.1.tar.gz", +- "https://hackage.haskell.org/package/cgi-3001.5.0.0/cgi-3001.5.0.0.tar.gz" +- ] ++saveInstallPath :: [String] -> InstallFlags -> (PackageDescription, LocalBuildInfo) -> IO () ++saveInstallPath args flags bi = do ++ let ++ dest = NoCopyDest ++ dir = datadir (uncurry absoluteInstallDirs bi dest) ++ writeFile dataDirFile dir ++ ++saveCopyPath :: [String] -> CopyFlags -> (PackageDescription, LocalBuildInfo) -> IO () ++saveCopyPath args flags bi = do ++ let ++ dest = case copyDest flags of ++ NoFlag -> NoCopyDest ++ Flag d -> d ++ dir = datadir (uncurry absoluteInstallDirs bi dest) ++ writeFile dataDirFile dir ++ ++-- | Name of file where installation's data directory is recording ++-- This is a last-resort way in which the seprate RGL build script ++-- can determine where to put the compiled RGL files ++dataDirFile :: String ++dataDirFile = "DATA_DIR" + + -- | Get path to locally-built gf + default_gf :: LocalBuildInfo -> FilePath +diff --git a/gf.cabal b/gf.cabal +index a055b86be..d00a5b935 100644 +--- a/gf.cabal ++++ b/gf.cabal +@@ -2,7 +2,7 @@ name: gf + version: 3.11.0-git + + cabal-version: 1.22 +-build-type: Simple ++build-type: Custom + license: OtherLicense + license-file: LICENSE + category: Natural Language Processing, Compiler +@@ -44,6 +44,14 @@ data-files: + www/translator/*.css + www/translator/*.js + ++custom-setup ++ setup-depends: ++ base >= 4.9.1 && < 4.16, ++ Cabal >= 1.22.0.0, ++ directory >= 1.3.0 && < 1.4, ++ filepath >= 1.4.1 && < 1.5, ++ process >= 1.0.1.1 && < 1.7 ++ + source-repository head + type: git + location: https://github.com/GrammaticalFramework/gf-core.git \ No newline at end of file diff --git a/src/runtime/haskell/Data/Binary/Builder.hs b/src/runtime/haskell/Data/Binary/Builder.hs index 5f8983c0c4..8dc46f816a 100644 --- a/src/runtime/haskell/Data/Binary/Builder.hs +++ b/src/runtime/haskell/Data/Binary/Builder.hs @@ -74,13 +74,16 @@ import qualified Data.ByteString.Internal as S #endif #if defined(__GLASGOW_HASKELL__) && !defined(__HADDOCK__) -import GHC.Base(Int(..),uncheckedShiftRL# ) +import GHC.Base(Int(..),uncheckedShiftRL#,) import GHC.Word (Word32(..),Word16(..),Word64(..)) #if MIN_VERSION_base(4,16,0) import GHC.Exts (wordToWord16#, word16ToWord#, wordToWord32#, word32ToWord#) #endif -#if WORD_SIZE_IN_BITS < 64 && __GLASGOW_HASKELL__ >= 608 +#if WORD_SIZE_IN_BITS < 64 && __GLASGOW_HASKELL__ >= 608 +import GHC.Word (uncheckedShiftRL64#) +#endif +#if __GLASGOW_HASKELL__ >= 900 import GHC.Word (uncheckedShiftRL64#) #endif #endif @@ -433,7 +436,11 @@ foreign import ccall unsafe "stg_uncheckedShiftRL64" #endif #else +#if __GLASGOW_HASKELL__ <= 810 shiftr_w64 (W64# w) (I# i) = W64# (w `uncheckedShiftRL#` i) +#else +shiftr_w64 (W64# w) (I# i) = W64# (w `uncheckedShiftRL64#` i) +#endif #endif #else diff --git a/src/runtime/haskell/Data/Binary/Get.hs b/src/runtime/haskell/Data/Binary/Get.hs index 8faf249a93..a33c5c5a3a 100644 --- a/src/runtime/haskell/Data/Binary/Get.hs +++ b/src/runtime/haskell/Data/Binary/Get.hs @@ -104,6 +104,9 @@ import GHC.Word #if MIN_VERSION_base(4,16,0) import GHC.Exts (wordToWord16#, word16ToWord#, wordToWord32#, word32ToWord#) #endif +#if __GLASGOW_HASKELL__ >= 900 +import GHC.Word (uncheckedShiftL64#) +#endif #endif -- Control.Monad.Fail import will become redundant in GHC 8.8+ @@ -553,7 +556,12 @@ foreign import ccall unsafe "stg_uncheckedShiftL64" #endif #else +#if __GLASGOW_HASKELL__ <= 810 shiftl_w64 (W64# w) (I# i) = W64# (w `uncheckedShiftL#` i) +#else +shiftl_w64 (W64# w) (I# i) = W64# (w `uncheckedShiftL64#` i) +#endif + #endif #else diff --git a/src/runtime/haskell/pgf.cabal b/src/runtime/haskell/pgf.cabal index cb5841a1c2..404d3bc07f 100644 --- a/src/runtime/haskell/pgf.cabal +++ b/src/runtime/haskell/pgf.cabal @@ -9,16 +9,16 @@ synopsis: Grammatical Framework description: A library for interpreting the Portable Grammar Format (PGF) homepage: https://www.grammaticalframework.org/ bug-reports: https://github.com/GrammaticalFramework/gf-core/issues -tested-with: GHC==7.10.3, GHC==8.0.2, GHC==8.10.4 +tested-with: GHC==7.10.3, GHC==8.0.2, GHC==8.10.4, GHC==9.4.5 library default-language: Haskell2010 build-depends: - array >= 0.5.1 && < 0.6, - base >= 4.9.1 && < 4.16, - bytestring >= 0.10.8 && < 0.11, - containers >= 0.5.7 && < 0.7, - ghc-prim >= 0.5.0 && < 0.7, + array >= 0.5.1 && < 0.7, + base >= 4.9.1 && < 5.0, + bytestring >= 0.10.8 && < 0.12, + containers >= 0.5.7 && < 0.8, + ghc-prim >= 0.5.0 && < 0.10, mtl >= 2.2.1 && < 2.3, pretty >= 1.1.3 && < 1.2, random >= 1.1 && < 1.3,