diff --git a/.gitignore b/.gitignore index e94452f..5d97109 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ lisp-scripts/compile-file-system-p.lisp tmp bin/asgl gecode +*.cxx *.o gr1/gr1 gr1/gr1.c diff --git a/ecl-1.16.2-libffi-3.3-abi.patch b/ecl-1.16.2-libffi-3.3-abi.patch new file mode 100644 index 0000000..807687b --- /dev/null +++ b/ecl-1.16.2-libffi-3.3-abi.patch @@ -0,0 +1,15 @@ +diff --git a/src/c/ffi.d b/src/c/ffi.d +index 8861303e..8a959c23 100644 +--- a/src/c/ffi.d ++++ b/src/c/ffi.d +@@ -145,8 +145,8 @@ static struct { + #elif defined(X86_WIN64) + {@':win64', FFI_WIN64}, + #elif defined(X86_ANY) || defined(X86) || defined(X86_64) +- {@':cdecl', FFI_SYSV}, +- {@':sysv', FFI_SYSV}, ++ {@':cdecl', FFI_UNIX64}, ++ {@':sysv', FFI_UNIX64}, + {@':unix64', FFI_UNIX64}, + #endif + }; \ No newline at end of file diff --git a/ecl-cpp.nix b/ecl-cpp.nix new file mode 100644 index 0000000..280641f --- /dev/null +++ b/ecl-cpp.nix @@ -0,0 +1,97 @@ +{ + lib, + stdenv, + fetchurl, + fetchpatch, + libtool, + autoconf, + automake, + gmp, + mpfr, + libffi, + makeWrapper, + noUnicode ? false, + gcc, + threadSupport ? false, + useBoehmgc ? true, + boehmgc, +}: + +assert useBoehmgc -> boehmgc != null; + +let + s = # Generated upstream information + rec { + baseName = "ecl"; + version = "16.1.2"; + name = "${baseName}-${version}"; + url = "https://common-lisp.net/project/ecl/static/files/release/ecl-16.1.2.tgz"; + sha256 = "16ab8qs3awvdxy8xs8jy82v8r04x4wr70l9l2j45vgag18d2nj1d"; + }; + buildInputs = [ + libtool + autoconf + automake + makeWrapper + ]; + propagatedBuildInputs = + [ + libffi + gmp + mpfr + gcc + ] + ++ lib.optionals useBoehmgc [ + # replaces ecl's own gc which other packages can depend on, thus propagated + boehmgc + ]; +in +stdenv.mkDerivation { + inherit (s) name version; + inherit buildInputs propagatedBuildInputs; + + src = fetchurl { inherit (s) url sha256; }; + + configureFlags = [ + (if threadSupport then "--enable-threads" else "--disable-threads") + "--with-gmp-prefix=${gmp.dev}" + "--with-cxx" + "--with-libffi-prefix=${libffi.dev}" + ] ++ (lib.optional (!noUnicode) "--enable-unicode"); + + patches = [ + (fetchpatch { + # Avoid infinite loop, see https://gitlab.com/embeddable-common-lisp/ecl/issues/43 (fixed upstream) + name = "avoid-infinite-loop.patch"; + url = "https://gitlab.com/embeddable-common-lisp/ecl/commit/caba1989f40ef917e7486f41b9cd5c7e3c5c2d79.patch"; + sha256 = "07vw91psbc9gdn8grql46ra8lq3bgkzg5v480chnbryna4sv6lbb"; + }) + (fetchpatch { + # Fix getcwd with long pathnames + # Rebased version of + # https://gitlab.com/embeddable-common-lisp/ecl/commit/ac5f011f57a85a38627af154bc3ee7580e7fecd4.patch + name = "getcwd.patch"; + url = "https://git.sagemath.org/sage.git/plain/build/pkgs/ecl/patches/16.1.2-getcwd.patch?id=07d6c37d18811e2b377a9689790a7c5e24da16ba"; + sha256 = "1fbi8gn7rv8nqff5mpaijsrch3k3z7qc5cn4h1vl8qrr8xwqlqhb"; + }) + ./ecl-1.16.2-libffi-3.3-abi.patch + ]; + + hardeningDisable = [ "format" ]; + + postInstall = '' + sed -e 's/@[-a-zA-Z_]*@//g' -i $out/bin/ecl-config + wrapProgram "$out/bin/ecl" \ + --prefix PATH ':' "${gcc}/bin" \ + --prefix NIX_LDFLAGS ' ' "-L${gmp.lib or gmp.out or gmp}/lib" \ + --prefix NIX_LDFLAGS ' ' "-L${libffi.lib or libffi.out or libffi}/lib" + ''; + + meta = { + inherit (s) version; + description = "Lisp implementation aiming to be small, fast and easy to embed"; + license = lib.licenses.mit; + maintainers = [ lib.maintainers.raskin ]; + platforms = lib.platforms.unix; + }; +} diff --git a/gecode.nix b/gecode.nix new file mode 100644 index 0000000..a3c8eec --- /dev/null +++ b/gecode.nix @@ -0,0 +1,48 @@ +{ + lib, + stdenv, + fetchurl, + fetchpatch, + perl, +}: + +stdenv.mkDerivation rec { + pname = "gecode"; + version = "4.3.3"; + + src = fetchurl { + url = "https://github.com/Gecode/gecode/archive/refs/tags/release-${version}.tar.gz"; + sha256 = "sha256-EOmQqEtfBH/J4w7wtcFhrVuU7F0NWJO9Qfn4b0QHZaw="; + }; + + patches = [ + # (import ./fix-const-weights-clang-patch.nix fetchpatch) + ]; + + postPatch = '' + substituteInPlace gecode/flatzinc/lexer.yy.cpp \ + --replace "register " "" + ''; + + nativeBuildInputs = [ perl ]; + + preConfigure = "patchShebangs configure"; + + configureFlags = [ + "--disable-gist" + "--disable-qt" + "--disable-examples" + "--disable-flatzinc" + "--disable-float-vars" + ]; + + env.CXXFLAGS = lib.optionalString stdenv.cc.isClang "-std=c++14"; + + meta = with lib; { + license = licenses.mit; + homepage = "https://www.gecode.org"; + description = "Toolkit for developing constraint-based systems"; + platforms = platforms.all; + maintainers = [ maintainers.manveru ]; + }; +} diff --git a/gemset.nix b/gemset.nix new file mode 100644 index 0000000..738180f --- /dev/null +++ b/gemset.nix @@ -0,0 +1,117 @@ +{ + aruba = { + dependencies = ["childprocess" "cucumber" "rspec-expectations"]; + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "0hlq03shd7cl72n7nark8dm5gdrsjpcqkxd2qrkcjzd35nkqqlbw"; + type = "gem"; + }; + version = "0.6.2"; + }; + builder = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "14fii7ab8qszrvsvhz6z2z3i4dw0h41a62fjr2h1j8m41vbrmyv2"; + type = "gem"; + }; + version = "3.2.2"; + }; + childprocess = { + dependencies = ["ffi"]; + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "0cxzh17vjlmpqfcas4815x50dc1gzfwgbs51zzpd4chrl6ak4n4v"; + type = "gem"; + }; + version = "0.5.5"; + }; + cucumber = { + dependencies = ["builder" "diff-lcs" "gherkin" "multi_json" "multi_test"]; + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "170a0yclrc1i9m5wjgwzga3ipb5mbapiha8jcg0g2gjnmzvd77nr"; + type = "gem"; + }; + version = "1.3.19"; + }; + diff-lcs = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "1vf9civd41bnqi6brr5d9jifdw73j9khc6fkhfl1f8r9cpkdvlx1"; + type = "gem"; + }; + version = "1.2.5"; + }; + ffi = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "0ph098bv92rn5wl6rn2hwb4ng24v4187sz8pa0bpi9jfh50im879"; + type = "gem"; + }; + version = "1.9.8"; + }; + gherkin = { + dependencies = ["multi_json"]; + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "1mxfgw15pii1jmq00xxbyp77v71mh3bp99ndgwzfwkxvbcisha25"; + type = "gem"; + }; + version = "2.12.2"; + }; + multi_json = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "1mg3hp17ch8bkf3ndj40s50yjs0vrqbfh3aq5r02jkpjkh23wgxl"; + type = "gem"; + }; + version = "1.11.0"; + }; + multi_test = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "1sx356q81plr67hg16jfwz9hcqvnk03bd9n75pmdw8pfxjfy1yxd"; + type = "gem"; + }; + version = "0.1.2"; + }; + rspec-expectations = { + dependencies = ["diff-lcs" "rspec-support"]; + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "08ba5hprb3kf849yylkxm9dd9lfazh7gapiqxy5lapwqxbqpa3ky"; + type = "gem"; + }; + version = "3.2.0"; + }; + rspec-support = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "194zry5195ls2hni7r9824vqb5d3qfg4jb15fgj8glfy0rvw3zxl"; + type = "gem"; + }; + version = "3.2.2"; + }; +} diff --git a/nix-build.sh b/nix-build.sh new file mode 100755 index 0000000..f90b6a3 --- /dev/null +++ b/nix-build.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -euxo pipefail + +# git add . +# git commit -m wip || true + +git clean -fxd + +nix-shell \ + --pure --run 'bash steps.sh' diff --git a/nix-test.sh b/nix-test.sh new file mode 100755 index 0000000..92f41d3 --- /dev/null +++ b/nix-test.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -euxo pipefail + +make data/iccma15_solutions data/iccma15_testcases + +nix-shell \ + --pure --run 'ASGL_HOME=`pwd` make test' diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..0ccda03 --- /dev/null +++ b/shell.nix @@ -0,0 +1,31 @@ +{ + pkgs ? import { }, +}: + +let + ecl_cpp = pkgs.callPackage ./ecl-cpp.nix { }; + gecode = pkgs.callPackage ./gecode.nix { }; + cucumber-aruba-from-gemfile = pkgs.bundlerEnv { + name = "cucumber-aruba-for-asgl"; + inherit (pkgs.ruby); + gemdir = ./.; + }; +in + +pkgs.mkShell { + buildInputs = [ + pkgs.which + # For building + pkgs.autoconf + ecl_cpp + gecode + pkgs.ragel + # For tests + cucumber-aruba-from-gemfile + pkgs.ruby + pkgs.perl + ]; + shellHook = '' + echo "Welcome to the development environment!" + ''; +} diff --git a/steps.sh b/steps.sh new file mode 100644 index 0000000..1a2b5ec --- /dev/null +++ b/steps.sh @@ -0,0 +1,14 @@ +set -euxo pipefail + +echo hello + +autoconf configure.ac > configure +chmod +x configure + +./configure --without-gist + +./scripts/generate-make-mk.sh + +make + +./bin/asgl