]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Test] Support cffi-lua as FFI fallback for Lua 5.4
authorVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 5 Dec 2025 16:18:20 +0000 (16:18 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 5 Dec 2025 16:18:20 +0000 (16:18 +0000)
Unit tests now try LuaJIT's ffi first, falling back to cffi-lua for
standard Lua 5.4. CI installs cffi-lua via luarocks for Fedora builds.

12 files changed:
.github/workflows/ci_rspamd.yml
test/lua/rspamd_test_helper.lua
test/lua/unit/addr.lua
test/lua/unit/base32.lua
test/lua/unit/base64.lua
test/lua/unit/fpconv.lua
test/lua/unit/rfc2047.lua
test/lua/unit/rspamd_util.lua
test/lua/unit/selectors.negative.lua
test/lua/unit/smtp_addr.lua
test/lua/unit/url.lua
test/lua/unit/utf.lua

index 4fc2a69d60f1afd3bb5021d17dc50bf069ba9323..87bd6a0a35203629e0ae9aa697151a5266522658 100644 (file)
@@ -41,6 +41,11 @@ jobs:
         if: runner.arch == 'ARM64'
         run: echo "HYPERSCAN_ALTROOT=-DHYPERSCAN_ROOT_DIR=/vectorscan" >> "$GITHUB_ENV"
 
+      - name: Install Lua FFI for non-LuaJIT builds
+        if: inputs.enable_luajit == 'OFF'
+        run: |
+          sudo luarocks install cffi-lua
+
       - name: Run cmake
         run: |
           mkdir ${GITHUB_WORKSPACE}/build
index 5373448319c70856bd8c94ebd3778dfaf3cdcec9..f96564f0742ec22b37b7a7dd52d65786a9cdbdfd 100644 (file)
@@ -1,10 +1,16 @@
-local ffi = require "ffi"
+-- Load FFI: try LuaJIT's built-in ffi first, then cffi-lua for standard Lua
+local ok, ffi = pcall(require, "ffi")
+if not ok then
+  ffi = require("cffi")
+end
 local cfg = rspamd_config
 
 ffi.cdef[[
 void rspamd_url_init (const char *tld_file);
 ]]
 local exports = {}
+-- Export ffi so tests can use it without their own require
+exports.ffi = ffi
 
 local function default_tld_file()
   local test_dir = string.gsub(debug.getinfo(1).source, "^@(.+/)[^/]+$", "%1")
index 6da72d316bc9a0589c0d59adc6b6803a82b2513b..89cc02b0b503fbdb35ced895721c76dd75cee469 100644 (file)
@@ -1,7 +1,10 @@
 -- inet addr tests
 
 context("Inet addr check functions", function()
-  local ffi = require("ffi")
+  local ok, ffi = pcall(require, "ffi")
+  if not ok then
+    ffi = require("cffi")
+  end
 
   ffi.cdef[[
   typedef struct rspamd_inet_addr_s rspamd_inet_addr_t;
index eb582f5ed1896bb34f86792fda086fcefadfe9bd..550c1cfb864a1d6e1b9b66e7c5cb2671e87bfc78 100644 (file)
@@ -1,7 +1,10 @@
 -- Test zbase32 encoding/decoding
 
 context("Base32 encodning", function()
-  local ffi = require("ffi")
+  local ok, ffi = pcall(require, "ffi")
+  if not ok then
+    ffi = require("cffi")
+  end
   ffi.cdef[[
     void ottery_rand_bytes(void *buf, size_t n);
     unsigned ottery_rand_unsigned(void);
index 02948e2d970fd572fe3768bf12ea456a952766b7..a48c23ce241f745c5c2af3d5e22e6488603089a0 100644 (file)
@@ -1,5 +1,8 @@
 context("Base64 encoding", function()
-  local ffi = require("ffi")
+  local ok, ffi = pcall(require, "ffi")
+  if not ok then
+    ffi = require("cffi")
+  end
   local util = require("rspamd_util")
   local logger = require "rspamd_logger"
   ffi.cdef[[
index e64626f6466675d429f679ea5d9cea7520165be0..6858b192a809af0086f1904a6277f065443a814f 100644 (file)
@@ -1,7 +1,10 @@
 -- fpconv tests
 
 context("Fpconv printf functions", function()
-  local ffi = require("ffi")
+  local ok, ffi = pcall(require, "ffi")
+  if not ok then
+    ffi = require("cffi")
+  end
   local niter_fuzz = 100000
   local function small_double()
     return math.random()
index 658f2020e40a74a2d4f0595eb9cac0c7f0b7d347..7f341fa363b91e548728505a943797f6a7a48045 100644 (file)
@@ -25,7 +25,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ]]--
 
 context("RFC2047 decoding", function()
-  local ffi = require("ffi")
+  local ok, ffi = pcall(require, "ffi")
+  if not ok then
+    ffi = require("cffi")
+  end
 
   ffi.cdef[[
     const char * rspamd_mime_header_decode (void *pool, const char *in, size_t inlen);
index 56f13d6da389c9682eb987919664d26afca99347..db7a0af3f197166306175848f66937e7a2eef03c 100644 (file)
@@ -90,7 +90,10 @@ context("Rspamd util for lua - check generic functions", function()
 end)
 
 context("Rspamd string utility", function()
-    local ffi = require 'ffi'
+    local ok, ffi = pcall(require, "ffi")
+    if not ok then
+      ffi = require("cffi")
+    end
 
     ffi.cdef[[
 char ** rspamd_string_len_split (const char *in, size_t len,
index 4262400667c9a9a932cb48f3eae4f892ac834980..84f95c0c4fe6a58618936db08c48d2f1fd4b9f0e 100644 (file)
@@ -3,7 +3,10 @@ context("Selectors test", function()
   local rspamd_task = require "rspamd_task"
   local logger = require "rspamd_logger"
   local lua_selectors = require "lua_selectors"
-  local ffi = require "ffi"
+  local ok, ffi = pcall(require, "ffi")
+  if not ok then
+    ffi = require("cffi")
+  end
   local cfg = rspamd_config
 
   local task
index 16f59d07cb62f9ceaf8a1d3f415ccf6315d82609..afccd0a750743ab1a65500dfd524283961400bd3 100644 (file)
@@ -2,7 +2,10 @@
 
 context("SMTP address check functions", function()
   local logger = require("rspamd_logger")
-  local ffi = require("ffi")
+  local ok, ffi = pcall(require, "ffi")
+  if not ok then
+    ffi = require("cffi")
+  end
   local util = require("rspamd_util")
   local fun = require "fun"
   ffi.cdef [[
index e25005eca7bcc200cc9baee3ffc609687bf7d652..d5c3ad42dfd4ae9ba25d4cd8b2a94354ad0b386e 100644 (file)
@@ -7,7 +7,10 @@ context("URL check functions", function()
   local lua_util = require("lua_util")
   local logger = require("rspamd_logger")
   local test_helper = require("rspamd_test_helper")
-  local ffi = require("ffi")
+  local ok, ffi = pcall(require, "ffi")
+  if not ok then
+    ffi = require("cffi")
+  end
 
   ffi.cdef [[
   void rspamd_normalize_path_inplace(char *path, size_t len, size_t *nlen);
index 799a3301418ed5e712bc0ed3d9322df316fdbebc..a4ea451b567c24ab3bdcacf009e88750a5bc6574 100644 (file)
@@ -1,7 +1,10 @@
 -- Test utf routines
 
 context("UTF8 check functions", function()
-  local ffi = require("ffi")
+  local ok, ffi = pcall(require, "ffi")
+  if not ok then
+    ffi = require("cffi")
+  end
   ffi.cdef [[
     unsigned int rspamd_str_lc_utf8 (char *str, unsigned int size);
     unsigned int rspamd_str_lc (char *str, unsigned int size);