[PATCH] proper support for GMP on macOS

18 views
Skip to first unread message

Qian Yun

unread,
Nov 7, 2023, 7:28:26 PM11/7/23
to fricas-devel
Recently I found that CI built macOS binaries do not work out-of-box:
it complains libzstd missing because SBCL from Homebrew is built with
core-compression support.

So I have changed to use upstream sbcl binary instead.

The situation for gmp support is similar to windows: we can not assume
libgmp.dylib is present on system.

So I changed CI to bundle gmp library, and changed code to load bundled
gmp library if there's no system gmp library.

- Qian

https://github.com/oldk1331/fricas/commit/dbc3a563caf892374782e808f790f5442620816f.patch

diff --git a/.github/workflows/macOS.yml b/.github/workflows/macOS.yml
index 8439f76e..d4737664 100644
--- a/.github/workflows/macOS.yml
+++ b/.github/workflows/macOS.yml
@@ -19,14 +19,17 @@ jobs:
- name: configure
run: |
mkdir ../build && cd ../build
- ../fricas/configure
--with-lisp=${GITHUB_WORKSPACE}/sbcl-${SBCL_VER}-x86-64-darwin/run-sbcl.sh
|| cat config.log
+ ../fricas/configure
--with-lisp=${GITHUB_WORKSPACE}/sbcl-${SBCL_VER}-x86-64-darwin/run-sbcl.sh
--enable-gmp || cat config.log
- name: make
run: cd ../build && make -j3
- name: make check
run: cd ../build && make check -j3
- name: Create artifact archives
run: |
- cd ../build && make dist-osx-dmg
+ cd ../build
+ make dist-macos
+ cp -v `brew list gmp | grep libgmp.10.dylib`
FriCAS.app/Contents/Resources/usr/local/lib/fricas/target/*/lib/
+ make dist-macos-dmg
mv FriCAS.dmg ../fricas/FriCAS-macOS-x86_64-${{ github.sha }}.dmg
- name: Upload macOS binary
uses: actions/upload-artifact@v3
diff --git a/Makefile.in b/Makefile.in
index 2961de19..c370d32b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -247,7 +247,7 @@ ${DIST_TARBALL}: out-of-source-check lastBuildDate
dist-help dist-lisp dist-doc

dist: ${DIST_TARBALL}

-dist-osx-dmg: out-of-source-check
+dist-macos: out-of-source-check
-rm -rf FriCAS.app FriCAS.dmg
${MKDIR_P} FriCAS.app/Contents/{MacOS,Resources}
${MAKE} DESTDIR=./FriCAS.app/Contents/Resources install-src
@@ -255,6 +255,8 @@ dist-osx-dmg: out-of-source-check
cp $(fricas_top_srcdir)/contrib/macos/Info.plist
./FriCAS.app/Contents/
cp $(fricas_top_srcdir)/contrib/macos/appIcon.icns
./FriCAS.app/Contents/Resources/
cc -framework CoreFoundation
$(fricas_top_srcdir)/contrib/macos/FriCAS.c -o
./FriCAS.app/Contents/MacOS/FriCAS
+
+dist-macos-dmg:
hdiutil create -srcfolder FriCAS.app FriCAS.dmg

clean-distdir:
diff --git a/src/lisp/num_gmp.lisp b/src/lisp/num_gmp.lisp
index f4a022ad..212e9d40 100644
--- a/src/lisp/num_gmp.lisp
+++ b/src/lisp/num_gmp.lisp
@@ -838,11 +838,16 @@
(sb-ext:lock-package "COMMON-LISP")))

(defun load-gmp-lib ()
- #-:WIN32 (ignore-errors (|quiet_load_alien| "libgmp.so") t)
- #+:WIN32 (if (ignore-errors (|quiet_load_alien| "libgmp-10.dll") t)
- t
- (ignore-errors (|quiet_load_alien|
- (BOOT::make-absolute-filename
"/lib/libgmp-10.dll")) t)))
+ (setq system-gmp-name #+:WIN32 "libgmp-10.dll"
+ #-:WIN32 "libgmp.so")
+ (setq bundled-gmp-name #+:WIN32 "/lib/libgmp-10.dll"
+ #+:DARWIN "/lib/libgmp.10.dylib"
+ #-(or :WIN32 :DARWIN) nil)
+ (if (ignore-errors (|quiet_load_alien| system-gmp-name) t)
+ t
+ (and bundled-gmp-name
+ (ignore-errors (|quiet_load_alien|
+ (BOOT::make-absolute-filename bundled-gmp-name)) t))))

(defun init-gmp(wrapper-lib)
(if (not *gmp-multiplication-initialized*)

Waldek Hebisch

unread,
Nov 8, 2023, 9:01:16 AM11/8/23
to fricas...@googlegroups.com
On Wed, Nov 08, 2023 at 08:28:22AM +0800, Qian Yun wrote:
> Recently I found that CI built macOS binaries do not work out-of-box:
> it complains libzstd missing because SBCL from Homebrew is built with
> core-compression support.
>
> So I have changed to use upstream sbcl binary instead.
>
> The situation for gmp support is similar to windows: we can not assume
> libgmp.dylib is present on system.
>
> So I changed CI to bundle gmp library, and changed code to load bundled
> gmp library if there's no system gmp library.

We alreay have '--with-gmp-lib=' configure option. This option was
added exactly to solve problem that you mention: we can not assume
that Mac OSX has GMP library in a fixed location. I am affraid that
your patch below would break '--with-gmp-lib=' for people who
need it. It would be better just to use '--with-gmp-lib=', so that
it works for everybody.

BTW: Probably it would be better to use '--with-gmp-lib=' also on
Windows, but I am not sure if anybody used '--with-gmp-lib=' on
Windows, while AFAIK it is used on Mac OSX.
> --
> You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/012796c4-3cc8-4480-b9df-5bc8579b3569%40gmail.com.

--
Waldek Hebisch

oldk1331

unread,
Nov 8, 2023, 9:40:56 AM11/8/23
to fricas-devel
'--with-gmp-lib=' configure option works on build machine, and this patch doesn't break it.

When binary is installed on user machine, you can't assume gmp is available in that path.

So the only way is to bundle gmp as fallback.

- Qian

Waldek Hebisch

unread,
Nov 8, 2023, 10:14:46 AM11/8/23
to fricas...@googlegroups.com
On Wed, Nov 08, 2023 at 10:40:36PM +0800, oldk1331 wrote:
> '--with-gmp-lib=' configure option works on build machine, and this patch
> doesn't break it.
>
> When binary is installed on user machine, you can't assume gmp is available
> in that path.
>
> So the only way is to bundle gmp as fallback.

Main use of '--with-gmp-lib=' is by package systems like Net BSD
portage (IIUC available on Mac OSX), Mac Ports and Homebrew.
Package system ensures that GMP is in place specified at
configure time.

If you want to distribute binary outside of package system, then
of course you need to bundle GMP. Since you bundle it you know
where it will live and can give that location to '--with-gmp-lib='.

You say that you do not break '--with-gmp-lib='. Maybe, but when
DARWIN is in features (which IIUC is true on Mac OSX) you use
different location. And '--with-gmp-lib=' works by replacing
'libgmp.so' by different name. So it is not clear to me how
it can work (on Mac OSX) after your change.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/CAGBJN93B6MW5n%3DjMRcUw%2BrA_7UmzmAA6p0MKh-gjEpC2_H4sTQ%40mail.gmail.com.

--
Waldek Hebisch

Qian Yun

unread,
Nov 8, 2023, 6:41:16 PM11/8/23
to fricas...@googlegroups.com


On 11/8/23 23:14, Waldek Hebisch wrote:
> On Wed, Nov 08, 2023 at 10:40:36PM +0800, oldk1331 wrote:
>> '--with-gmp-lib=' configure option works on build machine, and this patch
>> doesn't break it.
>>
>> When binary is installed on user machine, you can't assume gmp is available
>> in that path.
>>
>> So the only way is to bundle gmp as fallback.
>
> Main use of '--with-gmp-lib=' is by package systems like Net BSD
> portage (IIUC available on Mac OSX), Mac Ports and Homebrew.
> Package system ensures that GMP is in place specified at
> configure time.
>
> If you want to distribute binary outside of package system, then
> of course you need to bundle GMP. Since you bundle it you know
> where it will live and can give that location to '--with-gmp-lib='.

We bundle GMP to $FRICAS/lib. That is not a fixed path, we can not
give it to '--with-gmp-lib=' at configure phase.

> You say that you do not break '--with-gmp-lib='. Maybe, but when
> DARWIN is in features (which IIUC is true on Mac OSX) you use
> different location. And '--with-gmp-lib=' works by replacing
> 'libgmp.so' by different name. So it is not clear to me how
> it can work (on Mac OSX) after your change.
>

You see, from the patch:
(setq system-gmp-name #+:WIN32 "libgmp-10.dll"
#-:WIN32 "libgmp.so")
Here 'libgmp.so' will be replaced and it's valid on macOS.

- Qian

Waldek Hebisch

unread,
Nov 11, 2023, 8:26:17 AM11/11/23
to fricas...@googlegroups.com
OK, please go on with the patch.

--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages