Skip to content

michelou/graalvm-examples

Repository files navigation

Playing with GraalVM on Windows

GraalVM project This repository gathers GraalVM examples coming from various websites and books.
It also includes several build scripts (batch files) for experimenting with GraalVM on a Windows machine.

Ada, Akka, C++, COBOL, Dart, Deno, Docker, Erlang, Flix, Golang, Haskell, Kafka, Kotlin, LLVM, Modula-2, Node.js, Rust, Scala 3, Spark, Spring, TruffleSqueak, WiX Toolset and Zig are other topics we are continuously monitoring.

Read the document "Why GraalVM?" from the GraalVM documentation to know more about the GraalVM benefits.

Project dependencies

This project relies on the following external software for the Microsoft Windows platform:

Optionally one may also install the following software:

Installation policy
When possible we install software from a Zip archive rather than via a Windows installer. In our case we defined C:\opt\ as the installation directory for optional software tools (in reference to the /opt/ directory on Unix).

For instance our development environment looks as follows (August 2024) 3:

C:\opt\ConEmu\                                        ( 26 MB)
C:\opt\Git\                                           (388 MB)
C:\opt\jdk-graalvm-ce-17.0.9_9.1\                     (592 MB)
C:\opt\jdk-graalvm-ce-21.0.1_12.1\                    (585 MB)
C:\opt\Python-3.11.1\                                 ( 82 MB)
C:\opt\upx\                                           ( <1 MB)
C:\opt\VSCode\                                        (370 MB)
C:\Program Files\Microsoft SDKs\Windows\v7.1\         (333 MB)
C:\Program Files (x86)\Microsoft Visual Studio 10.0\  (555 MB)
%USERPROFILE%\.checkstyle\                            ( 16 MB)

🔎 Git for Windows provides a BASH emulation used to run git.exe from the command line (as well as over 250 Unix commands like awk, diff, file, grep, more, mv, rmdir, sed and wc).

Directory structure

This repository is organized as follows:

bin\graal\build.bat
docs\
examples\{README.md, ClassInitialization, ..}
graal\  (Git submodule)
labsjdk-ce-17.0.9-jvmci-23.0-b22\   (385 MB)
labsjdk-ce-21.0.1-jvmci-23.1-b22\   (420 MB)
mx\  (Git submodule)
README.md
RESOURCES.md
setenv.bat

where

We also define a virtual drive – e.g. drive G: – in our working environment in order to reduce/hide the real path of our project directory (see article "Windows command prompt limitation" from Microsoft Support).

🔎 We use the Windows external command subst to create virtual drives; for instance:

> subst G: %USERPROFILE%\workspace\graalvm-examples

In the next section we give a brief description of the batch files present in this project.

Batch commands

We distinguish different sets of batch commands:

  1. setenv.bat – This batch command makes external tools such as clang.exe dor git.exe directly available from the command prompt (see section Project dependencies).

    > setenv help
    Usage: setenv { <option> | <subcommand> }
     
      Options:
        -debug      print commands executed by this script
        -verbose    print progress messages
     
      Subcommands:
        help        print this help message
  2. bin\graal\build.bat – This batch command generates the GraalVM software distribution.

    > build help
    Usage: build { <option> | <subcommand> }
     
      Options:
        -debug       print commands executed by this script
        -timer       print total execution time
        -verbose     print progress messages
     
      Subcommands:
        clean        delete generated files
        dist[:<n>]   generate distribution with environment n=1-9 (default=2)
                     (see environment definitions in file build.ini)
        help         print this help message
        update       fetch/merge local directories graal/mx

    🔎 Parameter n in subcommand dist[:<n>] refers to environment env<n> defined in configuration file build.ini.

Usage examples

setenv.bat

We execute command setenv.bat once to setup our development environment; it makes external tools such as javac.exe, cl.exe and git.exe directly available from the command prompt:

> setenv
Tool versions:
   javac 11.0.19, python 3.11.1, pylint 2.15.8, mx 6.14.12
   cl 19.29.30137, msbuild 16.11.2.50704, link 14.29.30137.0,
   nmake 14.29.30137.0, git 2.46.0, diff 3.10, bash 5.2.26(1)

> where cl java link
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\cl.exe
C:\opt\graalvm-ce-java11-22.3.2\bin\java.exe
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\link.exe

Command setenv.bat -verbose also displays the tool paths:

> setenv -verbose
Tool versions:
   javac 11.0.22, python 3.11.1, pylint 2.15.8, mx 6.14.12
   cl 19.29.30137, msbuild 16.11.2.50704, link 14.29.30137.0,
   nmake 14.29.30137.0, git 2.46.0, diff 3.10, bash 5.2.26(1)
Tool paths:
   C:\opt\graalvm-ce-java11-22.3.2\bin\javac.exe
   C:\opt\Python-3.11.1\python.exe
   C:\opt\Python-3.11.1\Scripts\pylint.exe
   G:\graalvm\mx\mx.cmd
   C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\cl.exe
   C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
   C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\link.exe
   C:\opt\Git\usr\bin\link.exe
   C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\nmake.exe
   C:\opt\Git\bin\git.exe
Environment variables:
   "GIT_HOME=C:\opt\Git"
   "GRAALVM_HOME=C:\opt\graalvm-ce-java11-22.3.2
   "GRAALVM11_HOME=C:\opt\graalvm-ce-java11-22.3.2"
   "GRAALVM17_HOME=C:\opt\graalvm-ce-java17-22.3.2"
   "JAVA_HOME=C:\opt\graalvm-ce-java11-22.3.2"
   "LLVM_HOME=C:\opt\LLVM-15.0.6"
   "MAKE_HOME=C:\opt\make-3.81"
   "MAVEN_HOME=C:\opt\apache-maven"
   "MSVC_BIN_DIR=X:\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64"
   "MSVC_HOME=X:\VC\Tools\MSVC\14.29.30133"
   "MSVS_HOME=X:"
   "PYTHON_HOME=C:\opt\Python-3.11.1"
   "WABT_HOME=C:\opt\wabt-1.0.23"
Path associations:
   G:\: => %USERPROFILE%\workspace-perso\graalvm-examples

graal\build.bat

Directory graal\ is a Github submodule with a copy of the oracle/graal repository; it is setup as follows:

> cp bin\graal\build.* graal
> cd graal

Usage examples of command build.bat are presented in document BUILD.md.

examples\**\build.bat

See document examples\README.md.

Resources

See document RESOURCES.md for GraalVM related resources.

Footnotes

[1] Two GraalVM editions

GraalVM is available as Community Edition (CE) and Enterprise Edition (EE): GraalVM CE is based on the OpenJDK 8 and GraalVM EE is developed on top of the Java SE 1.8.0_302.

[2] UPX

UPX (Ultimate Packer for eXecutables) is a free, portable, extendable, high-performance executable packer for several executable formats. It is particularly useful to reduce the size of executables produced by native-image.

[3] Downloads

In our case we downloaded the following installation files (see section 1):
ConEmuPack.230724.7z                                          (  5 MB)
graalvm-community-java21-windows-amd64-dev.zip (*)             (298 MB)
graalvm-community-jdk-17.0.8_windows-x64_bin.zip (*)           (297 MB)
GRMSDKX_EN_DVD.iso                                            (570 MB)
labsjdk-ce-17.0.9+9-jvmci-23.0-b22-windows-amd64.tar.gz       (190 MB)
labsjdk-ce-21.0.1+12-jvmci-23.1-b22-windows-amd64.tar.gz      (181 MB)
PortableGit-2.46.0-64-bit.7z.exe                              ( 41 MB)
python-3.11.1.amd64.msi                                       ( 19 MB)
upx-4.2.2-win64.zip                                           ( <1 MB)
VC-Compiler-KB2519277.exe                                     (121 MB)
VSCode-win32-x64-1.92.1.zip                                   (131 MB)
(*) The tool native-image was initially installed separately with GraalVM distributions and is now included in GraalVM for JDK distributions (see article "New GraalVM Release and new Free Licence!").

[4] Improvements in GraalVM 20

Versions 20.x of GraalVM bring major improvements to Windows users:
  • Command gu.cmd is finally part of the Windows distribution !
    > where /r c:\opt\jdk-graalvm-ce-17.0.9_9.1 gu.*
    c:\opt\jdk-graalvm-ce-17.0.9_9.1\bin\gu.cmd
    c:\opt\jdk-graalvm-ce-17.0.9_9.1\lib\installer\bin\gu.cmd
    
  • native-image and rebuild-images are now available as an installable component.
    > echo %JAVA_HOME%
    C:\opt\graalvm-ce-java11-22.3.2
     
    > %JAVA_HOME%\bin\gu.cmd install --file native-image-installable-svm-java11-windows-amd64-22.3.2.jar --verbose
    Processing Component archive: native-image-installable-svm-java11-windows-amd64-22.3.2.jar
    Preparing to install native-image-installable-svm-java11-windows-amd64-22.3.2.jar, contains org.graalvm.native-image, version 22.3.2 (org.graalvm.native-image)
    Checking requirements of component Native Image (native-image), version 22.3.2
            Requires Graal Version = 22.3.2, GraalVM provides: 22.3.2
            Requires Java Version = 11, GraalVM provides: 11
            Requires Architecture = amd64, GraalVM provides: amd64
            Requires Operating System = windows, GraalVM provides: windows
    Installing new component: Native Image (org.graalvm.native-image, version 22.3.2)
    Extracting: LICENSE_NATIVEIMAGE.txt
    Extracting: bin/native-image.cmd
    Extracting: bin/rebuild-images.cmd
    [..]
    > %JAVA_HOME%\bin\gu.cmd list
    ComponentId    Version   Component name      Stability           Origin
    ---------------------------------------------------------------------------
    graalvm        22.3.2    GraalVM Core        Supported
    espresso       22.3.2    Java on Truffle     Experimental
    native-image   22.3.2    Native Image        Early adopter
     
    > c:\opt\graalvm-ce-java11-22.3.2\bin\native-image.cmd --version
    GraalVM 22.3.2 Java 11 CE (Java Version 11.0.19+10-jvmci-22.3-b08)
    
  • Command polyglot.cmd is finally part of the Windows distribution (and is native).
    > where /r c:\opt\graalvm-ce-java11-22.3.2\ polyglot.cmd
    c:\opt\graalvm-ce-java11-22.3.2\bin\polyglot.cmd
    c:\opt\graalvm-ce-java11-22.3.2\lib\polyglot\bin\polyglot.cmd
     
    > c:\opt\graalvm-ce-java11-22.3.2\bin\polyglot.cmd --version
    GraalVM CE polyglot launcher 22.3.2
    

[5] JDK 11 Support

Oracle has retired JDK 11 support starting with GraalVM 23.0 (to be released in June 2023).

mics/August 2024  

About

Running and building GraalVM on Windows

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published