]> git.eshelyaron.com Git - sweep.git/commitdiff
Load libswipl ahead of sweep-module if it's an ELF V8.5.18-sweep-0.6.1
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:53:02 +0000 (11:53 +0300)
sweeprolog.el

index 71117ef6fdf58050254ed0065901c19c40fff43a..bc23c25537b6f7ff7854e333add98b798885b8a3 100644 (file)
@@ -6,7 +6,7 @@
 ;; Maintainer: Eshel Yaron <~eshel/dev@lists.sr.ht>
 ;; Keywords: prolog languages extensions
 ;; URL: https://git.sr.ht/~eshel/sweep
-;; Package-Version: 0.6.0
+;; Package-Version: 0.6.1
 ;; Package-Requires: ((emacs "28"))
 
 ;; This file is NOT part of GNU Emacs.
@@ -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,37 @@ 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)))))
+      (when (string= exec-format "elf")
+        (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