[PATCH] Load bundled GMP library on Windows if not present

6 views
Skip to first unread message

Qian Yun

unread,
Sep 23, 2023, 6:04:08 AM9/23/23
to fricas-devel
Unlike Linux, GMP library is not present on Windows system by default,
and it is common practice for applications to ship their dependencies.
So I made following changes to make it easier for FriCAS to use GMP
on Windows.

First, this patch bundles libgmp-10.dll (mingw64 version) in our
Windows CI binary.

Second, this patch changes loading logic on Windows to:
try system version of libgmp-10.dll first, (if user has installed
msys2 for example), if fails, try to load our bundled GMP version
instead.

- Qian

diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml
index 24974593..ae576313 100644
--- a/.github/workflows/windows.yml
+++ b/.github/workflows/windows.yml
@@ -35,6 +35,7 @@ jobs:
run: |
rm ../build/target/x86_64-w64-mingw32/bin/fricas
mv ../build/target/x86_64-w64-mingw32 FriCAS-windows-x86_64
+ cp /mingw64/bin/libgmp-10.dll FriCAS-windows-x86_64/lib/
zip -r FriCAS-windows-x86_64-${{ github.sha }}.zip
FriCAS-windows-x86_64
- name: Upload Windows binary
uses: actions/upload-artifact@v3
diff --git a/src/lisp/num_gmp.lisp b/src/lisp/num_gmp.lisp
index 371d91cf..b58001e0 100644
--- a/src/lisp/num_gmp.lisp
+++ b/src/lisp/num_gmp.lisp
@@ -824,12 +824,16 @@
(symbol-function 'orig-isqrt))
(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)))
+
(defun init-gmp(wrapper-lib)
(if (not *gmp-multiplication-initialized*)
- (if (ignore-errors (|quiet_load_alien|
- #-:WIN32 "libgmp.so"
- #+:WIN32 "libgmp-10.dll"
- ) t)
+ (if (load-gmp-lib)
(if (ignore-errors
(|quiet_load_alien| wrapper-lib) t)
(progn

Waldek Hebisch

unread,
Sep 23, 2023, 6:39:35 AM9/23/23
to fricas...@googlegroups.com
On Sat, Sep 23, 2023 at 06:04:03PM +0800, Qian Yun wrote:
> Unlike Linux, GMP library is not present on Windows system by default,
> and it is common practice for applications to ship their dependencies.
> So I made following changes to make it easier for FriCAS to use GMP
> on Windows.
>
> First, this patch bundles libgmp-10.dll (mingw64 version) in our
> Windows CI binary.
>
> Second, this patch changes loading logic on Windows to:
> try system version of libgmp-10.dll first, (if user has installed
> msys2 for example), if fails, try to load our bundled GMP version
> instead.

Look OK, please commit.

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