Installing SWI-Prolog on Mac OS X with xpce support via homebrew

These are the steps I took to get a version of SWI-prolog built using homebrew with xpce support, so ‘edit’, etc works.

Install XQuartz, the X11 server:

brew install --cask xquartz

Turn developer mode on so we can edit the swi-prolog formula:

brew developer on

Download the developer formulae:

brew tap homebrew/core

Allow installing modified formula:

export HOMEBREW_NO_INSTALL_FROM_API=1

Edit the swi-prolog formula:

brew edit swi-prolog

Add the following to the “depends_on” section:

depends_on "freetype"
depends_on "libx11"

Change ‘args’ to allow X packages:

args = ["-DSWIPL_PACKAGES_JAVA=OFF", "-DSWIPL_PACKAGES_X=ON", "-DCMAKE_INSTALL_RPATH=#{loader_path}"]

Exit the editor, saving the changes. Install swi-prolog from source, optionally adding “–head” to get the latest source.

brew install swi-prolog --build-from-source --head

Run XQuartz from the Mac OS Applications, then start swipl with DISPLAY set to point to it:

DISPLAY=:0 swipl
2 Likes

Ideally, the formulas get updated. Having the GUI there by default seems ideal. As a variant is better than not at all. Any Homebrew users who can get this arranged?

I tried following the instructions very carefully. But all that happens is that it runs swipl in the little xterm window.

I am trying to get swipl running with the xpce like I had on my old Mac. On my new Mac all I seem to be able to do is run swipl in a term window.

Or I download the binary, but that doesn’t have “file” or “edit” drop down menus like on my old Mac.

Is there anyway to fix this? What am I doing wrong.

Thanks.

Mike

Which versions, what MacOS version? Did you download the .dmg file from www.swi-prolog.org? Opening SWI-Prolog, either from the .dmg or after installing should open a window with a menu, even if Xquartz is not installed. With Xquartz installed, the built-in editor should work.

I am a Homebrew user and compiles swi-prolog from source via GIT.
I have made a test to install SWI-Prolog exactly following your recipe,
and surprisingly for me, who usually easily fails to follow such instruction,
it is successful with the following brutal final step:

% brew link --overwrite swi-prolog          
Linking /usr/local/Cellar/swi-prolog/9.2.4... 7 symlinks created.
% 

As far as I have tested, the installed swipl program with homebrew seems equivalent
in any aspects to the one via GIT.

Thanks for giving chance to see a formula of swi-prolog of homebrew, though
I have reinstalled the GIT version without trouble.

I tried it both ways. I used the .dmg and got something that looks like the old swi-prolog, but it doesn’t have any menu buttons like “file” or “edit” or “run”. It only has a “swi-prolog” menu which has nothing in it but “hide swi-prolog”, “hide others”.

Then I tried building it in home-brew which just runs it in a xterm window (same as running in terminal).

I am running Mac OS Sonoma on an Apple M3 Max. I use to use the “file” “edit” and “run” buttons a lot so this will be a big switch for me if I can’t get them back.

Thanks for all the help.

To be precise, this is what it looks like when I use the .dmg file.


This is the .dmg that I downloaded:
SWI-Prolog 9.2.4-1 for MacOSX 10.14 (Mojave) and later on x86_64 and arm64

Looks much better than swi-prolog which I installed via homebrew. I thought if I were familiar
with X-window configuration on macOS, I could have enjoyed such window version.
In fact, in stead of learning toward such X-window version, I chosen gnu emacs and
ediprolog mode, with which I should be satisfied, though fairly frequently on debugging swi-prolog codes the emacs goes crazy (neither C-c nor C-g acceptable).

That is not good. I have little clue what is wrong. Works fine for me on Mac OS Sonoma, be it on a Macbook air with M1. Anyone else having trouble? Note that this has nothing to do with xpce. The console you see has been created by @CapelliC using Qt. Some of the menu operations, like Edit do use xpce. Showing the console itself is unrelated though.

I have little clue. Could be some environment variable that is blocking things? Notably look for SWI related variables or DYLD related stuff. I’d try to open the app from a terminal window using open or go into the app and run swipl-win. Possibly that shows a hint. Another option might be that there is something wrong in your ~/.config/swi-prolog/init.pl (ok if it does not exist).

You can get the same thing if you install Qt. It is a bit complicated process though. Might be easy if Homebrew supports Qt.

There is no ~/.config/swi-prolog/init.pl

If I run “open SWI-Prolog.app” from terminal I get the same behavior.

I thought it might be some Mac Privacy Settings, but nothing I do there seems to help.

I did install SWI-prolog twice (once from binary and once from homebrew).
But it was broken before that:

Here is the printenv (is something important missing)?

__CFBundleIdentifier=com.apple.Terminal
TMPDIR=/var/folders/rc/pqtb7zms7bd_4jqwx1yckmrm0000gn/T/
XPC_FLAGS=0x0
TERM=xterm-256color
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.VeH0kipgYq/Listeners
XPC_SERVICE_NAME=0
TERM_PROGRAM=Apple_Terminal
TERM_PROGRAM_VERSION=453
TERM_SESSION_ID=968AF0DA-71BC-4418-883F-8578109624BC
SHELL=/bin/zsh
HOME=/Users/mikebarley
LOGNAME=mikebarley
USER=mikebarley
PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
SHLVL=1
PWD=/Users/mikebarley/.config/swi-prolog
OLDPWD=/Users/mikebarley/.config
HOMEBREW_PREFIX=/opt/homebrew
HOMEBREW_CELLAR=/opt/homebrew/Cellar
HOMEBREW_REPOSITORY=/opt/homebrew
MANPATH=/opt/homebrew/share/man::
INFOPATH=/opt/homebrew/share/info:
HOMEBREW_NO_INSTALL_FROM_API=1
EDITOR=/usr/bin/nano
LANG=en_NZ.UTF-8
_=/usr/bin/printenv
mikebarley@Mikes-MacBook-Pro swi-prolog %

Thanks for all the help!

Environment looks clean.

Does it print any messages to the terminal where you run open?

As you have a Prolog prompt, is there anything suspicious if you run

?- check_installation.

By default it should complain about JPL and swipl-win not being in PATH.

Another thing to try is to run

?- init_win_menus.

This should normally be executed at startup time. If it works when called later we may be facing some timing issue. If it still does not add menus you can trace through it and see whether you can find what is wrong.

check_installation looked OK.

But, init_win_menus fixed it!!!

As soon as I typed it in all the menus appear!!!

Thanks heaps and stacks!!

Mike

Great. Possibly you can put that in ~/.config/swi-prolog/init.pl with a short delay, e.g.

 :- initialization sleep(0.1), init_win_menus.

May or may not work … I’m afraid your M3 is too fast :slight_smile:

@CapelliC, do you have any idea for a real fix?

Recently I noticed that in such emergency situations, the following two Emacs functions
almost always surely makes me avoid forcing to kill Emacs.app.

( GNU Emacs 29.1 (build 1, x86_64-apple-darwin21.6.0, Carbon Version 165 AppKit 2113.6) of 2023-08-08)
M-x kill-process  (attched to the current buffer)
M-x ediprolog-toplevel