> Right now I think we only use the header files. Sometimes clang will use
> weird stuff in the header file directory like module.modulemap.

Got it.

> Eventually I want to see if there is a way to trick the clang include file
> manager to load those headers from memory so that I can include them in the
> libterra.a bundle rather than having to have them shipped as a separate
> entity, but that will take a lot of poking around.

That would be cool because right now I can bundle everything from
luapower into a fat exe[1], as long as the bundled lib can read its
assets from memory (or mmaped fd). Btw, if the idea is to make a
self-sufficient library (which is what I'm looking for too), then
those headers are not enough (you can't even access printf with those)
as you well know. You'd need to add more headers from the package that
was used to build clang, which are probably platform-dependent so you
can't have a single unified set, and may have licenses requiring
attribution (hopefully I'm wrong about this, IANAL).

So I was also thinking about the possibility of a lighter terra that
does not include clang at all, and can read ffi cdefs directly from
their in-memory representation[2] and translate them to LLVM IR
struct/function prototypes directly, and maybe even link them to
already-loaded ffi clib objects. This would allow reusing the existing
(and growing) body of already-sanitized headers from existing ffi
bindings, it would solve the problem of shipping the headers, and
would make a single set of headers available to both Lua and terra
runtimes. This idea can also be implemented in a horrible, practical
way:

local ffi_cdef = ffi.cdef
function ffi.cdef(s,...)
  terralib.includecstring(s)
  return ffi_cdef(s,...)
end

local ffi_load = ffi.load
function ffi.load(s,...)
  terralib.linklibrary(s)
  return ffi_load(s,...)
end


[1] luapower.com/bundle
[2] https://github.com/corsix/ffi-reflect
_______________________________________________
terralang mailing list
[email protected]
https://mailman.stanford.edu/mailman/listinfo/terralang

Reply via email to