diff --git a/src/test/regress/copy.py b/src/test/regress/copy.py
new file mode 100644
index 0000000000000000000000000000000000000000..9996e64474649855606a8968cf2f3129e792042f
--- /dev/null
+++ b/src/test/regress/copy.py
@@ -0,0 +1,9 @@
+#! /usr/bin/env python3
+
+import sys
+import shutil
+
+if len(sys.argv) == 3:
+  shutil.copy(sys.argv[1], sys.argv[2])
+else:
+  raise Exception("this homemade copy program accepts two arguments")
diff --git a/src/test/regress/meson.build b/src/test/regress/meson.build
index 5a9be73531e9c38595d7aabbd1b17d0d94c2a8fd..df010b7dc02bf46cfb2bc8c1a2df47fd83f1b598 100644
--- a/src/test/regress/meson.build
+++ b/src/test/regress/meson.build
@@ -43,23 +43,19 @@ regress_module = shared_module('regress',
 )
 test_install_libs += regress_module
 
-# Get some extra C modules from contrib/spi but mark them as not to be
-# installed.
-# FIXME: avoid the duplication.
-
-autoinc_regress = shared_module('autoinc',
-  ['../../../contrib/spi/autoinc.c'],
-  kwargs: pg_test_mod_args,
+autoinc_regress = custom_target('autoinc',
+  command: ['copy.py', autoinc.full_path(), meson.current_build_dir()],
+  output: fs.name(autoinc.full_path()),
+  depends: [autoinc],
+  build_by_default: true,
 )
-test_install_libs += autoinc_regress
 
-refint_regress = shared_module('refint',
-  ['../../../contrib/spi/refint.c'],
-  c_args: refint_cflags,
-  kwargs: pg_test_mod_args,
+refint_regress = custom_target('refint',
+  command: ['copy.py', refint.full_path(), meson.current_build_dir()],
+  output: fs.name(refint.full_path()),
+  depends: [refint],
+  build_by_default: true,
 )
-test_install_libs += refint_regress
-
 
 tests += {
   'name': 'regress',
