#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
+ #include <string.h>
#include <sys/socket.h>
#include <event2/listener.h>
`}
in "C" `{
+
+// Protect callbacks for compatibility with light FFI
+#ifdef Connection_decr_ref
+
// Callback forwarded to 'Connection.write_callback'
static void c_write_cb(struct bufferevent *bev, Connection ctx) {
Connection_write_callback(ctx);
{
ConnectionFactory_accept_connection(ctx, listener, fd, address, socklen);
}
+#endif
+
`}
# Structure to hold information and state for a Libevent dispatch loop.
import nitni
import ffi
import naive_interpreter
+import pkgconfig
import debugger_socket # To linearize `ToolContext::init`
redef class ToolContext
n_extern_code_block.is_c) then return false
for mparam in mpropdef.msignature.mparameters do
- var mtype = mparam.mtype
- if not mtype.is_cprimitive then
+ if not mparam.mtype.is_cprimitive then
return false
end
end
+ var return_mtype = mpropdef.msignature.return_mtype
+ if return_mtype != null and not return_mtype.is_cprimitive then
+ return false
+ end
+
return true
end
end
var srcs = [for file in ccu.files do new ExternCFile(file, ""): ExternFile]
srcs.add_all mmodule.ffi_files
- if mmodule.pkgconfigs.not_empty then
- fatal(v, "NOT YET IMPLEMENTED annotation `pkgconfig`")
- return false
- end
-
+ # Compiler options specific to this module
var ldflags = mmodule.ldflags[""].join(" ")
- # TODO pkgconfig
+
+ # Protect pkg-config
+ var pkgconfigs = mmodule.pkgconfigs
+ var pkg_command = ""
+ if not pkgconfigs.is_empty then
+ var cmd = "which pkg-config >/dev/null"
+ if system(cmd) != 0 then
+ v.fatal "FFI Error: Command `pkg-config` not found. Please install it"
+ return false
+ end
+
+ for p in pkgconfigs do
+ cmd = "pkg-config --exists '{p}'"
+ if system(cmd) != 0 then
+ v.fatal "FFI Error: package {p} is not found by `pkg-config`. Please install it."
+ return false
+ end
+ end
+
+ pkg_command = "`pkg-config --cflags --libs {pkgconfigs.join(" ")}`"
+ end
# Compile each source file to an object file (or equivalent)
var object_files = new Array[String]
end
# Link everything in a shared library
- # TODO customize the compiler
- var cmd = "{v.c_compiler} -Wall -shared -o {foreign_code_lib_path} {object_files.join(" ")} {ldflags}"
- if sys.system(cmd) != 0 then
+ var cmd = "{v.c_compiler} -Wall -shared -o {foreign_code_lib_path} {object_files.join(" ")} {ldflags} {pkg_command}"
+ if system(cmd) != 0 then
v.fatal "FFI Error: Failed to link native code using `{cmd}`"
return false
end