Tuesday 14 August 2018

Building OpenJDK and OpenJFX on Windows (Mid August 2018)

A lot has changed in the last year when it comes to building OpenJDK and OpenJFX on Windows (10 64bits) (single repository, integrated Freetype, VS2017)... and some more changes are expected with project Skara.
In the mean time here are some updated steps:

Update: 2018-08-18: VS2017 15.8 broke the OpenJFX build, updated the steps with an additional one to work around this issue.
  1. Create a C:\dev\ directory 
  2. Download and install 7-zip (if needed, to open .tar.gz and  .xz files)
  3. Download and install Mercurial
  4. Download OpenJDK 10 and extract it to C:\dev\jdk-10.0.2
  5. Dowload Apache Ant (1.10.5) and extract it to C:\dev\apache-ant-1.10.5 (for OpenJFX)
  6. Download and install Cygwin
    select the following packages
    • autoconf
    • make
    • zip
    • unzip
  7. Download and install Visual Studio 2017 Build Tools (when installing select the Visual C++ Build Tools, and ensure the language module is English (only))
  8. (To fix the OpenJFX build with VS2017 15.8) Open  C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.15.26726\include\xhash in a notepad then locate
    // FUNCTION TEMPLATE hash_value
    and add the following line below it:
    #define _HASH_SEED    (size_t)0xdeadbeef
  9. Get OpenJDK's source:
    in a (cmd) console:
    cd C:\dev
    hg clone http://hg.openjdk.java.net/jdk/jdk/
    alternatively instead of attempting to clone from hg.openjdk.java.net (especially from Europe), download and extract Alexsey Shipilev's https://builds.shipilev.net/workspaces/jdk-jdk.tar.xz then extract in C:\dev\jdk then
    cd C:\dev
    hg pull
    hg update
  10. Get OpenJFX's source:
    in a (cmd) console:
    cd C:\dev
    hg clone http://hg.openjdk.java.net/openjfx/jfx/rt/ jfx
    alternatively instead of attempting to clone from hg.openjdk.java.net (especially from Europe), there is a git mirror of the http://hg.openjdk.java.net/openjfx/jfx-dev/rt/ at https://github.com/javafxports/openjdk-jfx (install Git for Windows then)
    cd C:\dev
    git clone https://github.com/javafxports/openjdk-jfx jfx
  11. Build OpenJDK
    in a Cygwin console:
    cd /cygdrive/c/dev/jdk
    bash configure --with-boot-jdk=/cygdrive/c/dev/jdk-10.0.2/ --disable-warnings-as-errors
    make images
    (--disable-warnings-as-errors so that VS2017 warnings are not stopping the build)
  12. Build OpenJFX
    in a (cmd) console:
    cd C:\dev\jfx
    set _JAVA_OPTIONS=-Dorg.gradle.daemon=false -Dsun.reflect.debugModuleAccessChecks=true
    set ANT_HOME=C:\dev\apache-ant-1.10.5
    set JAVA_HOME=C:\dev\jdk-10.0.2
    set VS150COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build
    set MSVC_VER=14.14.26428
    set PATH=%PATH%;%JAVA_HOME%\bin;%GRADLE_HOME%\bin;%ANT_HOME%\bin
    gradlew jmods
    (where 14.14.26428 is the name of the directory C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428)
  13. Create a combined image
    in a (cmd) console:
    cd C:\dev
    C:\dev\jdk\build\windows-x86_64-normal-server-release\images\jdk\bin\jlink --output openjdk-openjfx-image --module-path C:\dev\jdk\build\windows-x86_64-normal-server-release\images\jdk\jmods;C:\dev\jfx\build\jmods --add-modules java.base,java.compiler,java.datatransfer,java.desktop,java.instrument,java.logging,java.management,java.management.rmi,java.naming,java.net.http,java.prefs,java.rmi,java.scripting,java.se,java.security.jgss,java.security.sasl,java.smartcardio,java.sql,java.sql.rowset,java.transaction.xa,java.xml,java.xml.crypto,jdk.accessibility,jdk.aot,jdk.attach,jdk.charsets,jdk.compiler,jdk.crypto.cryptoki,jdk.crypto.ec,jdk.crypto.mscapi,jdk.dynalink,jdk.editpad,jdk.hotspot.agent,jdk.httpserver,jdk.internal.ed,jdk.internal.jvmstat,jdk.internal.le,jdk.internal.opt,jdk.internal.vm.ci,jdk.internal.vm.compiler,jdk.internal.vm.compiler.management,jdk.jartool,jdk.javadoc,jdk.jcmd,jdk.jconsole,jdk.jdeps,jdk.jdi,jdk.jdwp.agent,jdk.jfr,jdk.jlink,jdk.jshell,jdk.jsobject,jdk.jstatd,jdk.localedata,jdk.management,jdk.management.agent,jdk.management.jfr,jdk.naming.dns,jdk.naming.rmi,jdk.net,jdk.pack,jdk.rmic,jdk.scripting.nashorn,jdk.scripting.nashorn.shell,jdk.sctp,jdk.security.auth,jdk.security.jgss,jdk.unsupported,jdk.xml.dom,jdk.zipfs,javafx.graphics,javafx.swing,javafx.web,javafx.media,javafx.fxml
  14. Test it
    in a (cmd) console:
    cd C:\dev
    openjdk-openjfx-image\bin\java --version
    then in the same console:
    set _JAVA_OPTIONS=-Dorg.gradle.daemon=false -Dsun.reflect.debugModuleAccessChecks=true
    set ANT_HOME=C:\dev\apache-ant-1.10.5
    set JAVA_HOME=C:\dev\jdk-10.0.2
    set VS150COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build
    set MSVC_VER=14.14.26428
    set PATH=%PATH%;%JAVA_HOME%\bin;%GRADLE_HOME%\bin;%ANT_HOME%\bin
    gradlew apps
    openjdk-openjfx-image\bin\java -jar jfx\apps\samples\Ensemble8\dist\Ensemble8.jar
  15. hack!
Caveat: these steps don't build optionals nor do they run the tests. For further information check the JDK build doc and the JFX build doc.