How To Build the Development Version of Emacs on Windows

I think I’ve probably spent… more than an hour? but less than three hours? My entire life? on a Windows machine, so I’m the most qualified person ever to explain how to get started developing Emacs on Windows.

Because people who’ve used Windows before don’t really know what other people don’t know. It’s about the unknown unknowns.

So here’s a guide to get this working anyway, if you’re a Linux-ey person, and for some inexplicable reason you want to build the development version of Emacs on Windows.

1) Install Windows in a VM. Download the ISO from here. Then open virt-manager on your GNU/Linux machine, create a new machine, and point it at the ISO. You’ll be faced with a whole bunch of questions from Windows when installing, but answer “no” to as many as possible. Less surveillance is better.

2) After it’s up and running, search for “powershell” in the search field at the bottom of the screen. Start the “for administrators” version.

3) Type this:

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

Yes, those tildes and the numbers and all. And then:

Start-Service sshd
Set-Service -Name sshd -StartupType Automatic
ssh localhost

The latter should give you a login, so just try that to see whether it works.

4) From your GNU/Linux machine, say

scp ~/.ssh/authorized_keys windblows:.ssh/

This will later enable you to ssh to the machine without passwords, but first we have to do more confing, so we might as well just start installing the Linux-ey prerequisites already, because that makes things easier.

5) Install Cygwin by clicking on the “setup-x64_64.exe” link. It’ll ask you more questions, but just answer yes to everything.

6) Done! You don’t need to do anything more on the console, so get back to the couch and do the rest via ssh from a GNU/Linux machine, like a proper human being.

You can copy and paste the rest of this into your ssh session:

C:\cygwin64\bin\bash -l sed -i -E 's/^Match Group administrators|AuthorizedKeysFile __PROGRAMDATA__/#&/' /cygdrive/c/ProgramData/ssh/sshd_config
powershell -command "restart-service sshd"
curl -O https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg
install apt-cyg /bin
sed -i 's/lynx -source/curl/' /bin/apt-cyg
apt-cyg install wget
apt-cyg install gcc-core git automake autoconf libgnutls30 make gnutls libncurses-devel gnutls-devel libjpeg-devel libpng-devel libharfbuzz-devel libXpm-noX-devel libgif-devel libxml2-devel libjansson-devel libdbus1-devel librsvg2-devel libtiff-devel libXpm-devel
git clone https://git.savannah.gnu.org/git/emacs.git
cd emacs
./autogen.sh
./configure --with-native-image-api --with-w32
make -j8
./src/emacs

Presto! This should now be displaying in the VM, if you run over to it and have a look:

But you’d normally say

./src/emacs -nw

when working remotely from the sofa, of course.

Additional tweaks: Windows only uses one CPU by default (?), and qemu/virt-manager will tell the Windows client that it has many CPUs. To make it say that it has a lot of cores instead, say:

# virsh edit win10

Find the bit that says:

<cpu mode='host-model' check='partial'>

and edit that into:

<cpu mode='host-model' check='partial'>
    <topology sockets='1' dies='1' cores='8' threads='2'/>
</cpu>

Or however many cores/cpus you have. This will make building Emacs a lot quicker.

(Tips for improving the installation recipe are welcome, of course.)

6 thoughts on “How To Build the Development Version of Emacs on Windows”

  1. If you build Emacs inside Cygwin, do you get a real native port, meaning: can you start it outside of an MSYS environment? And does this have native rendering or does it need Xorg?
    I think building a truly native port must be done with MinGW and is actually a bit more involved, see nt/INSTALL.

    1. It has native rendering, but it has to be started from the Cygwin bash, apparently. (Which I didn’t know.) I’ll try to make a pasteable MinGW recipe (but not today).

      1. Thanks! The main issue with MSYS-Emacs is that I don’t think it can properly deal with Windows native paths (try opening C:\Users\etc…) since everything goes through MSYS path conversion. You will always need MSYS tools for building Emacs, but it should not be a runtime dependency. The real work is setting up the build environment; if that is done correctly, simply calling ‘make’ should pretty much work.

        1. Hey David, I used to build my own Emacs on Windows (because, who in their right mind waits for official, stable releases, right?) and you can copy a bunch of libs into the “bin” Emacs directory and then you should be able to runemacs.exe from outside MSYS.
          Alternatively, add MSYS to your PATH.

          There is a comment about this in the official instructions to build in Windows, in the Emacs repo.

          1. I prefer native Emacs binaries because they have better interoperability with the rest of Windows, mainly dealing with proper Windows paths. If I remember correctly, if you have an MSYS binary, everything goes through MSYS path conversion, and this has bitten me time and time again, because it is not easy for MSYS to decide what actually is a path that needs converting and what isn’t.

Leave a Reply to larsmagne23Cancel reply