From 1d1cc98e410b473a45ffd6289705d383b7adae74 Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Wed, 9 Sep 2026 05:53:13 +0200 Subject: [PATCH] merged more files from master --- .gitignore | 15 +++++------ doc/gf-developers.t2t | 61 +++++++++++++++++++++++++++---------------- flake.lock | 43 ++++++++++++++++++++++++++++++ flake.nix | 50 +++++++++++++++++++++++++++++++++++ nix/expose-all.patch | 12 +++++++++ 5 files changed, 150 insertions(+), 31 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/expose-all.patch diff --git a/.gitignore b/.gitignore index 678397df2..93d660fcc 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ *.jar *.gfo *.pgf -*.ngf debian/.debhelper debian/debhelper-build-stamp debian/gf @@ -47,8 +46,6 @@ src/runtime/c/sg/.dirstamp src/runtime/c/stamp-h1 src/runtime/java/.libs/ src/runtime/python/build/ -src/runtime/python/**/__pycache__/ -src/runtime/python/**/.pytest_cache/ .cabal-sandbox cabal.sandbox.config .stack-work @@ -56,12 +53,6 @@ DATA_DIR stack*.yaml.lock -# Generated source files -src/compiler/api/GF/Grammar/Lexer.hs -src/compiler/api/GF/Grammar/Parser.hs -src/compiler/api/PackageInfo_gf.hs -src/compiler/api/Paths_gf.hs - # Output files for test suite *.out gf-tests.html @@ -82,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/doc/gf-developers.t2t b/doc/gf-developers.t2t index c20afda52..aafe6d3f2 100644 --- a/doc/gf-developers.t2t +++ b/doc/gf-developers.t2t @@ -150,11 +150,9 @@ Open a terminal, go to the top directory (``gf-core``), and type the following c $ stack install ``` -It will install GF and all necessary tools and libraries to do that. - - === Alternative: use Cabal === -You can also install GF using Cabal, if you prefer Cabal to Stack. In that case, you may need to install some prerequisites yourself. + +If you prefer Cabal, then you just need to manually choose a suitable GHC to build GF. We recommend GHC 9.6.7, see other supported options in [gf.cabal https://github.com/GrammaticalFramework/gf-core/blob/master/gf.cabal#L14]. The actual installation process is similar to Stack: open a terminal, go to the top directory (``gf-core``), and type the following command. @@ -162,7 +160,13 @@ The actual installation process is similar to Stack: open a terminal, go to the $ cabal install ``` -//The old (potentially outdated) instructions for Cabal are moved to a [separate page ../doc/gf-developers-old-cabal.html]. If you run into trouble with ``cabal install``, you may want to take a look.// +=== Nix === + +As of 3.12, GF can also be installed via Nix. You can install GF from github with the following command: + +``` +nix profile install github:GrammaticalFramework/gf-core#gf +``` == Compiling GF with C runtime system support == @@ -197,7 +201,7 @@ Depending on what you want to do with the C runtime, you can follow one or more === Use the C runtime from another programming language ===[bindings] -% **If you just want to use the C runtime from Python, Java, or Haskell, you don't need to change your GF installation.** +% **If you just want to use the C runtime from Python or Haskell, you don't need to change your GF installation.** - **What —** This is the most common use case for the C runtime: compile @@ -230,20 +234,13 @@ modes (use the ``help`` command in the shell for details). (Re)compiling your GF with these flags will also give you Haskell bindings to the C runtime, as a library called ``PGF2``, -but if you want Python or Java bindings, you need to do [the previous step #bindings]. +but if you want Python bindings, you need to do [the previous step #bindings]. % ``PGF2``: a module to import in Haskell programs, providing a binding to the C run-time system. - **How —** -If you use cabal, run the following command: -``` -cabal install -fc-runtime -``` - -from the top directory (``gf-core``). - -If you use stack, uncomment the following lines in the ``stack.yaml`` file: +Add (or uncomment) the following lines in the ``stack.yaml`` file: ``` flags: @@ -254,6 +251,32 @@ extra-lib-dirs: ``` and then run ``stack install`` from the top directory (``gf-core``). +Run the newly built executable with the flag ``-cshell``, and you should see the following welcome message: + +``` +$ gf -cshell + + * * * + * * + * * + * + * + * * * * * * * + * * * + * * * * * * + * * * + * * * + +This is GF version 3.12.0. +Built on ... +Git info: ... + +Flags: interrupt server c-runtime +License: see help -license. + +This shell uses the C run-time system. See help for available commands. +> +``` //If you get an "``error while loading shared libraries``" when trying to run GF with C runtime, remember to declare your ``LD_LIBRARY_PATH``.// //Add ``export LD_LIBRARY_PATH="/usr/local/lib"`` to either your ``.bashrc`` or ``.profile``. You should now be able to start GF with C runtime.// @@ -266,14 +289,8 @@ With this feature, ``gf -server`` mode is extended with new requests to call the system, e.g. ``c-parse``, ``c-linearize`` and ``c-translate``. - **How —** -If you use cabal, run the following command: -``` -cabal install -fc-runtime -fserver -``` -from the top directory. - -If you use stack, add the following lines in the ``stack.yaml`` file: +Add the following lines in the ``stack.yaml`` file: ``` flags: diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..232e59372 --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1704290814, + "narHash": "sha256-LWvKHp7kGxk/GEtlrGYV68qIvPHkU9iToomNFGagixU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "70bdadeb94ffc8806c0570eb5c2695ad29f0e421", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "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 000000000..ccacc15b0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,50 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; + systems.url = "github:nix-systems/default"; + }; + + nixConfig = { + # extra-trusted-public-keys = + # "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="; + # extra-substituters = "https://devenv.cachix.org"; + }; + + outputs = { self, nixpkgs, 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 { + 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 = [ ]; + }); + }); + }; +} diff --git a/nix/expose-all.patch b/nix/expose-all.patch new file mode 100644 index 000000000..bca529157 --- /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