Development/BuildingOnWSLWindows

    From The Document Foundation Wiki

    Introduction

    Windows Subsystem for Linux (WSL) is a mechanism to run Linux applications unchanged in Windows. You can use WSL to build LibreOffice for Linux and run it on Windows, or you may use WSL as a helper to configure LibreOffice build, and then use GNU make to build it for Windows using Visual Studio. Here we discuss building for Windows. To build for Linux, please refer to Development/BuildingOnWSL.

    The first step to build LibreOffice using WSL is to install WSL itself. You can follow instructions on Microsoft Website to install WSL, preferably WSL 2.

    Windows Subsystem for Linux Documentation

    There are multiple Linux distributions available in Microsoft store, and you can choose your desired distribution. The following instructions use Ubuntu, but the build is very similar across different distributions.

    Build dependencies

    Ubuntu dependencies

    You need a few packages from WSL for the configuration. On Ubuntu, you can invoke:

    Commands to install dependencies (run inside WSL shell)  

    sudo apt-get update
    sudo apt-get install libfont-ttf-perl patch pkg-config automake make zip gperf bison nasm flex

    Windows build dependencies

    You have to install the dependencies for Windows build, and specifically Visual Studio compiler. For more information, please refer to the Windows build instructions. Additionally, select "Git for Windows" from the components.

    Other dependencies like Cygwin are not needed, as WSL provides an alternative to them.

    Notes about Git

    The build instructions should be invoked from the git bash shell.

    You have to make sure that line endings are set correctly, otherwise you may get various errors. You can use this command to set them correctly.

    Configure git (run inside git bash)  

    git config --global core.autocrlf false

    Setting this option is also possible during the installation of git for Windows.

    Also, make sure that you don't have the wslsys program in your path.

    GNU Make for Windows

    You have to download GNU Make for Windows, and copy it to somewhere in the path.

    Commands to install make (run inside git bash)  

    mkdir -p ~/bin
    curl -o ~/bin/make.exe https://dev-www.libreoffice.org/bin/cygwin/make-4.2.1-msvc.exe

    You should be able to see the version of the GNU Make with make --version.

    Be careful to use this Windows Make - the build will fail, if you use Make from Linux!

    Ant and JUnit

    You can extract them anywhere, they don't have to be installed. If you don't want to use Junit, it can be disabled with --without-junit in the autogen.sh command later.

    Commands to install ant and junit (run inside git bash)  

    mkdir -p c:/sources
    cd c:/sources
    curl -O https://archive.apache.org/dist/ant/binaries/apache-ant-1.9.5-bin.tar.bz2
    tar -xjvf apache-ant-1.9.5-bin.tar.bz2
    curl -O http://downloads.sourceforge.net/project/junit/junit/4.10/junit-4.10.jar

    Also works with the combination of junit 4.13, hamcrest 2.2 and Apache Ant 1.10.12

    Strawberry Perl

    You can download and install Strawberry Perl from strawberryperl website.

    Cloning and building

    Start git bash, and try the next steps inside it. You can clone the LibreOffice core repository with:

    Clone LibreOffice code (run inside git bash)  

    $ git clone https://gerrit.libreoffice.org/core libreoffice
    $ cd libreoffice

    You need a suitable configuration for the build that you can put inside autogen.input file. This is a suggested configuration, which assumes JDK is in c:/jdk, Strawberry Perl is in c:/strawberry and JUnit and ant are in c:/sources.

    sample autogen.input  

    --enable-dbgutil
    --with-visual-studio=2022
    --without-lxml
    --disable-ccache
    --with-jdk-home=C:/jdk
    --without-doxygen
    --enable-python=fully-internal
    --with-junit=c:/sources/junit-4.10.jar
    --with-ant-home=c:/sources/apache-ant-1.9.5
    --with-strawberry-perl-portable=c:/strawberry
    --host=x86_64-pc-cygwin

    It is recommended to add the source and build folder to the antivirus exclusions folders to speed up the build, and make sure your anti-virus software will not cause any problems.

    After that, you should configure the build with:

    Command to configure build (run inside git bash)  

    $ wsl ./autogen.sh

    You may see a warning like this, even after a successful configuration:

    * WARNING : To speed up builds and avoid failures in unit tests, it is highly recommended that you exclude the build and source directories associated with LibreOffice in the following Antivirus software:
            *Windows Defender
    

    The next step is to invoke the make command. You can simply invoke:

    Command to start the build (run inside git bash)  

    $ make

    And to also run the tests:

    Command to start the build and tests (run inside git bash)  

    $ make check

    Running your build

    When build is finished, you can start LibreOffice with:

    $ instdir/program/soffice

    If you want to run specific application like Writer or Calc, you can invoke:

    $ instdir/program/soffice --writer
    $ instdir/program/soffice --calc

    Tips

    Error During the Build

    First, you have to make sure that the configuration phase completes correctly. Sometimes when some libraries or other requirements are missing, this phase does not complete correctly. Then, you have to fix the issue, and try again with ./autogen.sh. After the configuration phase completes correctly, you can run make and if everything is set correctly, you should see it finishing without error.

    If you face errors like this:

    src\lxml\etree.c(105): fatal error C1083: Cannot open include file: 'Python.h': No such file or directory
    C:\Users\user\LIBREO~2\tmp\xmlXPathInit09l2r90w.c(1): fatal error C1083: Cannot open include file: 'libxml/xpath.h': No such file or directory
    

    then, please add --without-lxml to autogen.input, as it does not work at the moment, due to incompatibility.