Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MS-Windows support ? #11

Closed
ghost opened this issue Apr 24, 2022 · 17 comments
Closed

Add MS-Windows support ? #11

ghost opened this issue Apr 24, 2022 · 17 comments

Comments

@ghost
Copy link

ghost commented Apr 24, 2022

For ms-windows I tried using msys2 to compile the module , and it turns out not hard to do.

All I need todo is first install package mingw-w64-x86_64-xapian-core and change the xapian-lite.so to xapian-lite.dll in Makefile.

Can you change the Makefile so it produce a .dll file in ms-windows instead of a .so file? This and the msys2 dependency is all it need to make xeft work on windows.

@casouri
Copy link
Owner

casouri commented Apr 25, 2022

Thanks. I modified Makefile and it should produce dll on windows now, could you verify?

@ghost
Copy link
Author

ghost commented Apr 26, 2022

Yes it works , thank you ! 👍

@ghost ghost closed this as completed Apr 26, 2022
@mcrosson
Copy link

any chance i can bump this ticket and @pRot0ta1p for knowing if youre running emacs inside msys2 or natively using the windows builds of emacs form the main site.

I cannot seem to get the latest code to build/run correctly per the information here. I will create a new ticket if pRot0ta1p can let me know more detail on how they are using the setup (inside msys2 or not)

@ghost
Copy link
Author

ghost commented Aug 24, 2022

I use emacs inside msys2, but I think the promlem is with the Makefile, try apply this patch to Makefile and make sure the compiled .dll file is inside your load-path , when asked about make PREFIX input nothing so the compiled .dll file will be at the same directory as xeft.el.

diff --git a/Makefile b/Makefile
index d890d78..c627f5d 100644
--- a/Makefile
+++ b/Makefile
@@ -7,17 +7,17 @@ LDFLAGS=-L$(PREFIX)/lib
 LDLIBS=-lxapian
 
 # Dylib extensions.
-ifeq ($(OS),Windows_NT)
-	SOEXT = dll
-endif
 ifeq ($(shell uname),Darwin)
 	SOEXT = dylib
 else
 	SOEXT = so
 endif
+ifeq ($(OS),Windows_NT)
+	SOEXT = dll
+endif
 
 xapian-lite.$(SOEXT): module/xapian-lite.cc
 	$(CXX) $< -o $@ -shared $(CXXFLAGS) $(LDFLAGS) $(LDLIBS)
 
 clean:
-	rm -f *.so *.o
+	rm -f *.so *.o *.dll

@ghost ghost reopened this Aug 24, 2022
@casouri
Copy link
Owner

casouri commented Aug 24, 2022

Hmmm, could you explain what does this change fix?

@ghost
Copy link
Author

ghost commented Aug 24, 2022

The goal is to produce a dll file on windows, the catch with msys2 is that it is also a unix environment, so

 ifeq ($(shell uname),Darwin)
 	SOEXT = dylib
 else
 	SOEXT = so
 endif

will cause SOEXT = so in msys2, this will compile a xapian-lite.so without error but emacs in mingw64 is a native win64 application ( the official win distribution of emacs is compiled with mingw64 toolchain) and only recognize the native dll file, so to fix this, I moved the ifeq Windows_NT part behind so SOEXT will be dll.

@mcrosson
Copy link

@pRot0ta1p Thank you for the clarity. I had come up with a similar process but I'm getting an error on GPL compatibility.

@casouri The patch will fixup the build for msys2 so the dll is properly generated and found by emacs when loading xeft.

For both of y'all: I'm getting a gpl compatibility error (below) when loading xeft inside msys2 or with the native windows build of emacs. I'm not sure if its because I didn't pull the 11.x g++ or not and I'm 100% not sure how to get msys2 to install concurrent versions of g++ so I can use an older version.

The error: Module is not GPL compatible: "/home/kemonine/.emacs.d/xeft/xapian-lite.dll

Full build process:

export PATH=/mingw64/bin/:${PATH} # setup g++ binary discovery for make
pacman -Syyu # upgrade to latest software
# some of the below packages may be unneeded
pacman -S --needed mingw-w64-x86_64-xapian-core git base-devel mingw-w64-x86_64-toolchain # install needed tools
mkdir ~/.emacs.d
cd ~/.emacs.d
git clone https://github.com/casouri/xeft.git /opt/xeft 
cd xeft
g++ -o xapian-lite.dll -shared -fPIC -I/mingw64/include -L/mingw64/include -lxapian -lWs2_32 -municode # build xeft
# add activation for xeft to init.el
# launch emacs then xeft with "M-x  xeft [RET]"

Emacs init.el:

(add-to-list 'load-path "~/.emacs.d/xeft")
(require 'xeft)
; xeft-database
; xeft-directory
; xeft-default-extension
; xeft-recursive

@mcrosson
Copy link

I have also tried the below changes to the code to try to force-export the plugin_is_GPL_compatible but I still receive the compatibility error.

nano -w module/xapian-lite.cc
    Change: int plugin_is_GPL_compatible;
    To: __declspec(dllexport) int plugin_is_GPL_compatible;
    
    Change:
        int
        emacs_module_init(struct emacs_runtime *ert)
    To:
        int __declspec(dllexport)
        emacs_module_init(struct emacs_runtime *ert)

@ghost
Copy link
Author

ghost commented Aug 25, 2022

I'm not sure if its because I didn't pull the 11.x g++ or not and I'm 100% not sure how to get msys2 to install concurrent versions of g++ so I can use an older version.

I don't think Msys2 can have concurrent version fo g++, its rolling release-ish kinda like archlinux.
Though I don't think older version of gcc is the problem either, the build proccess work back then.

In terms of your build proccess, I don't quite understand why you need to export PATH variable and call g++ manually instead of just invoke make. As long as you use the MinGW x64 environmet provided by msys2 (the blue icon one) there is no need to export PATH.

@mcrosson
Copy link

mysy2 mingw x64 (blue icon)

well that is a new way of launching mysy2. I'll try that and report back soon. Thank you for the tip.

@mcrosson
Copy link

mcrosson commented Aug 25, 2022

With the patch at #11 (comment) I can run the below procedure to compile and use xeft inside msys2. The compiled dll won't work outside msys2 and trying to compile statically had a compile error. Not sure if this is worth exploring, I wouldn't mind using native emacs on Windows with xeft ;)

If you install the mingw-w64-x86_64-emacs package you can invoke runemacs from within the mysy2 mingw x64 (blue icon) flavor of msys2 with a native ui.

# run mysy2 to install needed software
pacman -Syyu # upgrade to latest software
# some of the below packages may be unneeded
pacman -S --needed mingw-w64-x86_64-xapian-core git base-devel mingw-w64-x86_64-toolchain # install needed tools
# run mysy2 mingw x64 (blue icon) for build -- THIS IS CRITICAL
mkdir ~/.emacs.d
cd ~/.emacs.d
git clone https://github.com/casouri/xeft.git
cd xeft
make
# add activation for xeft to init.el
# launch emacs then xeft with "M-x  xeft [RET]"

@mcrosson
Copy link

You can also auto run the msys2 mingw emacs directly from a windows shortcut (these can be pinned to the taskbar) using the below.

C:\msys64\usr\bin\mintty.exe -w hide /bin/env MSYSTEM=MINGW64 /bin/bash -l -i -c /mingw64/bin/runemacs.exe

It'll launch using the ~/.emacs.d directory in your msys2 home directory and once it launches it'll have full access to C:. You can even use chemacs2 or similar with profiles stored in C: that are auto loaded by chemacs2 profiles.

@casouri
Copy link
Owner

casouri commented Aug 28, 2022

Ah, yes, duh. I fixed the makefile. IIUC that's the only thing that needs fixing right?

@ghost
Copy link
Author

ghost commented Aug 28, 2022

Yes, issue solved confirmed , thank you.

@ghost ghost closed this as completed Aug 28, 2022
@mcrosson
Copy link

Ah, yes, duh. I fixed the makefile. IIUC that's the only thing that needs fixing right?

the instructions i added to the ticket may be good for windows userts ; or at least knowing to use the flavor of mingw noted above and the msys2 package thatll get you a native emacs ui ; these ended up being really important things for me to start using xeft.

Good stuff too btw ; this does what I wanted 💯

@ghost
Copy link
Author

ghost commented Aug 28, 2022

I'll draft a PR on the windows instruction stuff later, I run emacs master branch in msys2 on windows as daily.

@panmengguan
Copy link

With the patch at #11 (comment) I can run the below procedure to compile and use xeft inside msys2. The compiled dll won't work outside msys2 and trying to compile statically had a compile error. Not sure if this is worth exploring, I wouldn't mind using native emacs on Windows with xeft ;)

If you install the mingw-w64-x86_64-emacs package you can invoke runemacs from within the mysy2 mingw x64 (blue icon) flavor of msys2 with a native ui.

# run mysy2 to install needed software
pacman -Syyu # upgrade to latest software
# some of the below packages may be unneeded
pacman -S --needed mingw-w64-x86_64-xapian-core git base-devel mingw-w64-x86_64-toolchain # install needed tools
# run mysy2 mingw x64 (blue icon) for build -- THIS IS CRITICAL
mkdir ~/.emacs.d
cd ~/.emacs.d
git clone https://github.com/casouri/xeft.git
cd xeft
make
# add activation for xeft to init.el
# launch emacs then xeft with "M-x  xeft [RET]"

Does this solution only suitable for emacs installed from mingw? I use the native emacs binary from GNU Emacs mirror and follow this instruction. However, although the xapian-lite.dll has been properly generated, when I execute M-x xeft, there is the following error:

xeft--require-xapian-lite: Module could not be opened: "c:/Users/xxx/.emacs.d/elpa/xeft-3.2/xapian-lite.dll"

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants