]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Allow to detect torch support from Lua
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 7 Aug 2017 07:14:04 +0000 (08:14 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 7 Aug 2017 07:14:04 +0000 (08:14 +0100)
CMakeLists.txt
config.h.in
src/lua/lua_config.c

index c5f874375b78f569042a619c8cd2057535a96826..82498acdfda9ca0150ab4b08da594484a0a126db 100644 (file)
@@ -1267,6 +1267,7 @@ IF(ENABLE_TORCH MATCHES "ON")
                ADD_SUBDIRECTORY(contrib/torch/paths)
                ADD_SUBDIRECTORY(contrib/torch/torch7)
                ADD_SUBDIRECTORY(contrib/torch/nn)
+               SET(WITH_TORCH 1)
        ELSE()
                MESSAGE(FATAL_ERROR "Cannot enable torch without luajit")
        ENDIF()
index 8e89c04ff9c6a86a4e6f611e16fde8c27718c38b..29a2a458145b126e7bd5ad05bf3a8fd6f7f0d504 100644 (file)
 #cmakedefine WITH_SNOWBALL       1
 #cmakedefine WITH_SQLITE         1
 #cmakedefine WITH_SYSTEM_HIREDIS 1
+#cmakedefine WITH_TORCH          1
 
 #cmakedefine DISABLE_PTHREAD_MUTEX 1
 
index b01b0c5a095b452a1328bf87098738db3ed75bf3..79dd11e762f892e5710bd5988cac2a0d4e79297c 100644 (file)
@@ -639,6 +639,14 @@ LUA_FUNCTION_DEF (config, set_peak_cb);
  */
 LUA_FUNCTION_DEF (config, get_cpu_flags);
 
+/***
+ * @method rspamd_config:has_torch()
+ * Returns true if Rspamd is compiled with torch support and the runtime CPU
+ * supports sse4.2 required for torch.
+ * @return {boolean} true if torch is compiled and supported
+ */
+LUA_FUNCTION_DEF (config, has_torch);
+
 static const struct luaL_reg configlib_m[] = {
        LUA_INTERFACE_DEF (config, get_module_opt),
        LUA_INTERFACE_DEF (config, get_mempool),
@@ -686,6 +694,7 @@ static const struct luaL_reg configlib_m[] = {
        LUA_INTERFACE_DEF (config, add_example),
        LUA_INTERFACE_DEF (config, set_peak_cb),
        LUA_INTERFACE_DEF (config, get_cpu_flags),
+       LUA_INTERFACE_DEF (config, get_cpu_flags),
        {"__tostring", rspamd_lua_class_tostring},
        {"__newindex", lua_config_newindex},
        {NULL, NULL}
@@ -2869,6 +2878,33 @@ lua_config_get_cpu_flags (lua_State *L)
        return 1;
 }
 
+static gint
+lua_config_has_torch (lua_State *L)
+{
+       struct rspamd_config *cfg = lua_check_config (L, 1);
+       struct rspamd_cryptobox_library_ctx *crypto_ctx;
+
+       if (cfg != NULL) {
+               crypto_ctx = cfg->libs_ctx->crypto_ctx;
+#ifndef WITH_TORCH
+               lua_pushboolean (L, false);
+               (void)crypto_ctx;
+#else
+               if (crypto_ctx->cpu_config & CPUID_SSE42) {
+                       lua_pushboolean (L, true);
+               }
+               else {
+                       lua_pushboolean (L, false);
+               }
+#endif
+       }
+       else {
+               return luaL_error (L, "invalid arguments");
+       }
+
+       return 1;
+}
+
 static gint
 lua_monitored_alive (lua_State *L)
 {