]> git.eshelyaron.com Git - sweep.git/commitdiff
Load libswipl ahead of sweep-module if it's an ELF scratch/no-ld-preload-on-emacs-29
authorEshel Yaron <me@eshelyaron.com>
Thu, 13 Oct 2022 08:38:52 +0000 (11:38 +0300)
committerEshel Yaron <me@eshelyaron.com>
Thu, 13 Oct 2022 08:38:52 +0000 (11:38 +0300)
sweeprolog.el

index 71117ef6fdf58050254ed0065901c19c40fff43a..a3e43792b39b63bc805de0b92c5e08f2a6acc367 100644 (file)
@@ -103,12 +103,22 @@ This makes the first invocation of \\[cycle-spacing] in
 (defcustom sweeprolog-swipl-path nil
   "Path to the swipl executable.
 When non-nil, this is used by the embedded SWI-Prolog runtime to
-locate its \"home\" directory.  Otherwise, the `executable-find'
-is used to find a the swipl executable."
+locate its \"home\" directory.  Otherwise, `executable-find' is
+used to find the swipl executable."
   :package-version '((sweeprolog . "0.1.1"))
   :type 'string
   :group 'sweeprolog)
 
+(defcustom sweeprolog-libswipl-path nil
+  "Path to the libswipl shared object.
+On Linux and other ELF-based platforms, `sweep' first loads
+libswipl before loading `sweep-module'.  When this option is
+nil (the default), libswipl is located automatically, otherwise
+the value of this option is used as its path."
+  :package-version '((sweeprolog . "0.6.1"))
+  :type 'string
+  :group 'sweeprolog)
+
 (defcustom sweeprolog-messages-buffer-name "*sweep Messages*"
   "The name of the buffer to use for logging Prolog messages."
   :package-version '((sweeprolog . "0.1.1"))
@@ -205,6 +215,36 @@ clause."
 (defun sweeprolog--ensure-module ()
   "Locate and load `sweep-module', unless already loaded."
   (unless (featurep 'sweep-module)
+    (when-let ((exec-format (car
+                             (save-match-data
+                               (split-string
+                                (shell-command-to-string
+                                 (concat
+                                  (shell-quote-argument
+                                   (or sweeprolog-swipl-path (executable-find "swipl")))
+                                  " -q"
+                                  " -g 'current_prolog_flag(executable_format, X), writeln(X)'"
+                                  " -t halt"))
+                                "\n"
+                                t)))))
+      (let ((libswipl-path (or sweeprolog-libswipl-path
+                               (car
+                                (save-match-data
+                                  (split-string
+                                   (shell-command-to-string
+                                    (concat
+                                     (shell-quote-argument
+                                      (or sweeprolog-swipl-path (executable-find "swipl")))
+                                     " -q"
+                                     " -g 'current_prolog_flag(libswipl, X), writeln(X)'"
+                                     " -t halt"))
+                                   "\n"))))))
+        (condition-case _
+            (load libswipl-path)
+          (file-error (user-error
+                       (concat "Failed to load `libswipl'. "
+                               "Make sure SWI-Prolog is installed "
+                               "and up to date"))))))
     (let ((sweep-module-path (car
                               (save-match-data
                                 (split-string