forked from mirrors/nixpkgs
3288d3670f
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>
20 lines
564 B
Diff
20 lines
564 B
Diff
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)
|