summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorAustin Seipp <aseipp@pobox.com>2019-09-18 21:44:55 -0500
committerAustin Seipp <aseipp@pobox.com>2019-09-18 21:45:34 -0500
commit3288d3670feaec0d1d9cc2d95fca6a76301474db (patch)
tree08121e756b4384061326c97e6c686f73793e3d70 /pkgs
parent5cc70a7b6bbdc9c2ae3e7e849fa80f155ea735d4 (diff)
downloadnixpkgs-3288d3670feaec0d1d9cc2d95fca6a76301474db.tar
nixpkgs-3288d3670feaec0d1d9cc2d95fca6a76301474db.tar.gz
nixpkgs-3288d3670feaec0d1d9cc2d95fca6a76301474db.tar.bz2
nixpkgs-3288d3670feaec0d1d9cc2d95fca6a76301474db.tar.lz
nixpkgs-3288d3670feaec0d1d9cc2d95fca6a76301474db.tar.xz
nixpkgs-3288d3670feaec0d1d9cc2d95fca6a76301474db.tar.zst
nixpkgs-3288d3670feaec0d1d9cc2d95fca6a76301474db.zip
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 <aseipp@pobox.com>
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/development/compilers/terra/default.nix2
-rw-r--r--pkgs/development/compilers/terra/nix-cflags.patch19
2 files changed, 21 insertions, 0 deletions
diff --git a/pkgs/development/compilers/terra/default.nix b/pkgs/development/compilers/terra/default.nix
index c4e697f2f1e..371009af5ff 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 00000000000..be9b6a61088
--- /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)