From 5cc70a7b6bbdc9c2ae3e7e849fa80f155ea735d4 Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Wed, 18 Sep 2019 21:44:55 -0500 Subject: [PATCH 1/4] terra: touchups Signed-off-by: Austin Seipp --- pkgs/development/compilers/terra/default.nix | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkgs/development/compilers/terra/default.nix b/pkgs/development/compilers/terra/default.nix index dea6df1b7aa4..c4e697f2f1ed 100644 --- a/pkgs/development/compilers/terra/default.nix +++ b/pkgs/development/compilers/terra/default.nix @@ -1,4 +1,6 @@ -{ stdenv, fetchFromGitHub, fetchurl, llvmPackages, ncurses, lua }: +{ stdenv, fetchurl, fetchFromGitHub +, llvmPackages, ncurses, lua +}: let luajitArchive = "LuaJIT-2.0.5.tar.gz"; @@ -49,9 +51,9 @@ stdenv.mkDerivation rec { meta = with stdenv.lib; { description = "A low-level counterpart to Lua"; - homepage = http://terralang.org/; - platforms = platforms.x86_64; - maintainers = with maintainers; [ jb55 ]; - license = licenses.mit; + homepage = http://terralang.org/; + platforms = platforms.x86_64; + maintainers = with maintainers; [ jb55 thoughtpolice ]; + license = licenses.mit; }; } From 3288d3670feaec0d1d9cc2d95fca6a76301474db Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Wed, 18 Sep 2019 21:44:55 -0500 Subject: [PATCH 2/4] terra: patch to use NIX_CFLAGS_COMPILE for includes Terra heavily depends on its ability to interface with C APIs, but without scanning NIX_CFLAGS_COMPILE, it's awkward and annoying to set up imports correctly (by scanning and adding the flags yourself) in every single project. Luckily most of the Clang initialization is hidden away, but the Lua code for the Terra library handles all the high-level stuff, so we patch it in there. This allows simple examples like: C = terralib.includec("zlib.h") to work instantly, provided `zlib` is a Nix dependency. Signed-off-by: Austin Seipp --- pkgs/development/compilers/terra/default.nix | 2 ++ .../compilers/terra/nix-cflags.patch | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 pkgs/development/compilers/terra/nix-cflags.patch diff --git a/pkgs/development/compilers/terra/default.nix b/pkgs/development/compilers/terra/default.nix index c4e697f2f1ed..371009af5ff2 100644 --- a/pkgs/development/compilers/terra/default.nix +++ b/pkgs/development/compilers/terra/default.nix @@ -23,6 +23,8 @@ stdenv.mkDerivation rec { outputs = [ "bin" "dev" "out" "static" ]; + patches = [ ./nix-cflags.patch ]; + postPatch = '' substituteInPlace Makefile --replace \ '-lcurses' '-lncurses' diff --git a/pkgs/development/compilers/terra/nix-cflags.patch b/pkgs/development/compilers/terra/nix-cflags.patch new file mode 100644 index 000000000000..be9b6a61088d --- /dev/null +++ b/pkgs/development/compilers/terra/nix-cflags.patch @@ -0,0 +1,19 @@ +diff --git a/src/terralib.lua b/src/terralib.lua +index 351238d..f26591b 100644 +--- a/src/terralib.lua ++++ b/src/terralib.lua +@@ -3395,6 +3395,14 @@ function terra.includecstring(code,cargs,target) + args:insert("-internal-isystem") + args:insert(path) + end ++ ++ -- NOTE(aseipp): include relevant Nix header files ++ local nix_cflags = os.getenv('NIX_CFLAGS_COMPILE') ++ if nix_cflags ~= nil then ++ for w in nix_cflags:gmatch("%S+") do ++ args:insert(w) ++ end ++ end + + if cargs then + args:insertall(cargs) From 52d3655c3d5fcb83b6dbb054b272007270849bb3 Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Wed, 18 Sep 2019 22:13:18 -0500 Subject: [PATCH 3/4] terra: 1.0.0-beta1 -> 1.0.0pre1175_ef6a75f Signed-off-by: Austin Seipp --- pkgs/development/compilers/terra/default.nix | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pkgs/development/compilers/terra/default.nix b/pkgs/development/compilers/terra/default.nix index 371009af5ff2..edab1cb0df2b 100644 --- a/pkgs/development/compilers/terra/default.nix +++ b/pkgs/development/compilers/terra/default.nix @@ -5,22 +5,24 @@ let luajitArchive = "LuaJIT-2.0.5.tar.gz"; luajitSrc = fetchurl { - url = "http://luajit.org/download/${luajitArchive}"; + url = "http://luajit.org/download/${luajitArchive}"; sha256 = "0yg9q4q6v028bgh85317ykc9whgxgysp76qzaqgq55y6jy11yjw7"; }; in stdenv.mkDerivation rec { - pname = "terra-git"; - version = "1.0.0-beta1"; + pname = "terra"; + version = "1.0.0pre1175_${builtins.substring 0 7 src.rev}"; src = fetchFromGitHub { - owner = "zdevito"; - repo = "terra"; - rev = "release-${version}"; - sha256 = "1blv3mbmlwb6fxkck6487ck4qq67cbwq6s1zlp86hy2wckgf8q2c"; + owner = "zdevito"; + repo = "terra"; + rev = "ef6a75ffee15a30f3c74f4e6943851cfbc0fec3d"; + sha256 = "0aky17vbv3d9zng34hp17p9zb00dbzwhvzsdjzrrqvk9lmyvix0s"; }; + hardeningDisable = [ "fortify" ]; + outputs = [ "bin" "dev" "out" "static" ]; patches = [ ./nix-cflags.patch ]; From d5e1d57ceeb06f9d4b465453116c5911264310cd Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Thu, 19 Sep 2019 00:26:48 -0500 Subject: [PATCH 4/4] terra: include libc headers by default, run tests Signed-off-by: Austin Seipp --- pkgs/development/compilers/terra/default.nix | 19 ++++++++++++------- .../compilers/terra/nix-cflags.patch | 7 +++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pkgs/development/compilers/terra/default.nix b/pkgs/development/compilers/terra/default.nix index edab1cb0df2b..6d87d4bbd496 100644 --- a/pkgs/development/compilers/terra/default.nix +++ b/pkgs/development/compilers/terra/default.nix @@ -9,7 +9,6 @@ let sha256 = "0yg9q4q6v028bgh85317ykc9whgxgysp76qzaqgq55y6jy11yjw7"; }; in - stdenv.mkDerivation rec { pname = "terra"; version = "1.0.0pre1175_${builtins.substring 0 7 src.rev}"; @@ -21,15 +20,21 @@ stdenv.mkDerivation rec { sha256 = "0aky17vbv3d9zng34hp17p9zb00dbzwhvzsdjzrrqvk9lmyvix0s"; }; - hardeningDisable = [ "fortify" ]; + nativeBuildInputs = [ lua ]; + buildInputs = with llvmPackages; [ llvm clang-unwrapped ncurses ]; + doCheck = true; + enableParallelBuilding = true; + hardeningDisable = [ "fortify" ]; outputs = [ "bin" "dev" "out" "static" ]; patches = [ ./nix-cflags.patch ]; - postPatch = '' - substituteInPlace Makefile --replace \ - '-lcurses' '-lncurses' + substituteInPlace Makefile \ + --replace '-lcurses' '-lncurses' + + substituteInPlace src/terralib.lua \ + --subst-var-by NIX_LIBC_INCLUDE ${stdenv.cc.libc.dev}/include ''; preBuild = '' @@ -42,6 +47,8 @@ stdenv.mkDerivation rec { cp ${luajitSrc} build/${luajitArchive} ''; + checkPhase = "(cd tests && ../terra run)"; + installPhase = '' install -Dm755 -t $bin/bin release/bin/terra install -Dm755 -t $out/lib release/lib/terra${stdenv.hostPlatform.extensions.sharedLibrary} @@ -51,8 +58,6 @@ stdenv.mkDerivation rec { cp -rv release/include/terra $dev/include ''; - buildInputs = with llvmPackages; [ lua llvm clang-unwrapped ncurses ]; - meta = with stdenv.lib; { description = "A low-level counterpart to Lua"; homepage = http://terralang.org/; diff --git a/pkgs/development/compilers/terra/nix-cflags.patch b/pkgs/development/compilers/terra/nix-cflags.patch index be9b6a61088d..339ae23cef65 100644 --- a/pkgs/development/compilers/terra/nix-cflags.patch +++ b/pkgs/development/compilers/terra/nix-cflags.patch @@ -1,13 +1,16 @@ diff --git a/src/terralib.lua b/src/terralib.lua -index 351238d..f26591b 100644 +index 351238d..e638c90 100644 --- a/src/terralib.lua +++ b/src/terralib.lua -@@ -3395,6 +3395,14 @@ function terra.includecstring(code,cargs,target) +@@ -3395,6 +3395,17 @@ function terra.includecstring(code,cargs,target) args:insert("-internal-isystem") args:insert(path) end + + -- NOTE(aseipp): include relevant Nix header files ++ args:insert("-isystem") ++ args:insert("@NIX_LIBC_INCLUDE@") ++ + local nix_cflags = os.getenv('NIX_CFLAGS_COMPILE') + if nix_cflags ~= nil then + for w in nix_cflags:gmatch("%S+") do