Skip to content

Commit

Permalink
[Jenkins-Build] Build SWT-natives against Java-17 JDK header files
Browse files Browse the repository at this point in the history
Use headers and libs from minimal JustJ JDK and use SWT_JAVA_HOME
environment variable

Fixes eclipse-platform#626
  • Loading branch information
HannesWell committed Apr 25, 2023
1 parent 772a495 commit e5e038d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 81 deletions.
45 changes: 28 additions & 17 deletions Jenkinsfile
Expand Up @@ -32,6 +32,15 @@ spec:
}
}

/** Returns the download URL of the JDK against whoose headers (in the 'include/' folder) and libs the SWT natives are compiled.*/
def getNativeJdkUrl(String os, String arch){ // To update the used JDK version update the URL template below
return "https://download.eclipse.org/justj/jres/17/downloads/20230423_0633/org.eclipse.justj.openjdk.hotspot.jre.minimal.stripped-17.0.6-${os}-${arch}.tar.gz"
}
def getLinuxPPC64leJdkUrl(){ // To update the used JDK version update the URL template below
// Use type JRE, which has no headers but is much smaller
return '-L https://api.adoptium.net/v3/binary/version/jdk-17.0.6%2B10/linux/ppc64le/jre/hotspot/normal/eclipse?project=jdk'
}

pipeline {
options {
skipDefaultCheckout() // Specialiced checkout is performed below
Expand Down Expand Up @@ -129,29 +138,31 @@ pipeline {
}
steps {
script {
def (ws, os, arch) = env.PLATFORM.split('\\.')
dir("jdk-download-${os}.${arch}") {
if (os =='linux' && arch == 'ppc64le') {
// Get the headers (in the 'include' folder) from JustJ and get the 'lib' folder directly from adoptium using a JRE (which has no headers).
// Downloading both is significantly smaller than just downloading the JDK from adoptium.
sh """
curl ${getNativeJdkUrl(os, 'x86_64')} | tar -xzf - include/
curl ${getLinuxPPC64leJdkUrl()} | tar -xzf - --strip=1 */lib/
"""
} else {
sh "curl ${getNativeJdkUrl(os, arch)} | tar -xzf - include/ lib/"
}
stash name:"jdk.resources.${os}.${arch}", includes: "include/,lib/"
deleteDir()
}
nativeBuildAgent("${PLATFORM}") {
cleanWs() // Workspace is not cleaned up by default, so we do it explicitly
unstash "swt.binaries.sources.${PLATFORM}"

def (ws, os, arch) = env.PLATFORM.split('\\.')
echo "OS: ${os}"
echo "ARCH: ${arch}"
def javaHome = env.JAVA_HOME
// Some of the native-build agents don't have their JAVA_HOME properly set. Actually that should be done in the agents
//TODO: ask the infra-team to fix the setup. This is a infra-setup detail and should not be handled in the pipeline.
if(os =='linux' && arch == 'aarch64'){
def armJDK = '/usr/lib/jvm/java-11-openjdk-arm64'
javaHome = fileExists(armJDK) ? armJDK : '/usr/lib/jvm/java-11-openjdk'
} else if (os =='linux' && arch == 'ppc64le') {
javaHome = '/usr/lib/jvm/java-11-openjdk-11.0.15.0.10-3.el8.ppc64le'
} else if (os =='linux' && arch == 'x86_64') {
javaHome = tool(type:'jdk', name:'temurin-jdk11-latest')
} else if(os == 'macosx') {
javaHome = tool(type:'jdk', name:'temurin-jdk11-latest')
unstash "swt.binaries.sources.${PLATFORM}"
dir('jdk.resources') {
unstash "jdk.resources.${os}.${arch}"
}
echo 'JAVA_HOME: ' + javaHome
// TODO: don't zip the sources and just (un)stash them unzipped! That safes the unzipping and removal of the the zip
withEnv(['MODEL=' + arch, "OUTPUT_DIR=${WORKSPACE}/libs", 'JAVA_HOME=' + javaHome]) {
withEnv(['MODEL=' + arch, "OUTPUT_DIR=${WORKSPACE}/libs", "SWT_JAVA_HOME=${WORKSPACE}/jdk.resources"]) {
if(isUnix()){
sh '''
unzip -aa org.eclipse.swt.${PLATFORM}.master.zip
Expand Down
6 changes: 0 additions & 6 deletions bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/build.sh
Expand Up @@ -15,12 +15,6 @@

cd `dirname $0`

if [ -d /System/Library/Frameworks/JavaVM.framework/Headers ]; then
export CFLAGS_JAVA_VM="-I /System/Library/Frameworks/JavaVM.framework/Headers"
else
export CFLAGS_JAVA_VM="-I $(/usr/libexec/java_home)/include -I $(/usr/libexec/java_home)/include/darwin"
fi

if [ "x${MODEL}" = "xx86_64" ]; then
export ARCHS="-arch x86_64"
if [ "x${OUTPUT_DIR}" = "x" ]; then
Expand Down
Expand Up @@ -14,6 +14,10 @@

# Makefile for SWT libraries on Cocoa/Mac

# assumes these variables are set in the environment from which make is run
# SWT_JAVA_HOME
# OUTPUT_DIR

include make_common.mak

SWT_PREFIX=swt
Expand All @@ -32,7 +36,8 @@ AWT_OBJECTS = swt_awt.o

#SWT_DEBUG = -g
CFLAGS = -c -xobjective-c -Wall $(ARCHS) -DSWT_VERSION=$(SWT_VERSION) $(NATIVE_STATS) $(SWT_DEBUG) -DUSE_ASSEMBLER -DCOCOA -DATOMIC \
$(CFLAGS_JAVA_VM) \
-I $(SWT_JAVA_HOME)/include \
-I $(SWT_JAVA_HOME)/include/darwin \
-I /System/Library/Frameworks/Cocoa.framework/Headers \
-I /System/Library/Frameworks/JavaScriptCore.framework/Headers
LFLAGS = -bundle $(ARCHS) -framework Cocoa -framework WebKit -framework CoreServices -framework JavaScriptCore -framework Security -framework SecurityInterface
Expand Down
35 changes: 13 additions & 22 deletions bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh
Expand Up @@ -114,17 +114,6 @@ case $SWT_OS.$SWT_ARCH in
if [ "${CC}" = "" ]; then
export CC=gcc
fi
if [ "${JAVA_HOME}" = "" ]; then
# Cross-platform method of finding JAVA_HOME.
# Tested on Fedora 24 and Ubuntu 16
DYNAMIC_JAVA_HOME=`readlink -f /usr/bin/java | sed "s:jre/::" | sed "s:bin/java::"`
if [ -e "${DYNAMIC_JAVA_HOME}include/jni.h" ]; then
func_echo_plus "JAVA_HOME not set, but jni.h found, dynamically configured to $DYNAMIC_JAVA_HOME"
export JAVA_HOME="$DYNAMIC_JAVA_HOME"
else
func_echo_error "JAVA_HOME not set and jni.h could not be located. You might get a compile error about include 'jni.h'. You should install 'java-*-openjdk-devel' package or if you have it installed already, find jni.h and set JAVA_HOME manually to base of 'include' folder"
fi
fi
if [ "${PKG_CONFIG_PATH}" = "" ]; then
export PKG_CONFIG_PATH="/usr/lib64/pkgconfig"
fi
Expand All @@ -133,9 +122,6 @@ case $SWT_OS.$SWT_ARCH in
if [ "${CC}" = "" ]; then
export CC=gcc
fi
if [ "${JAVA_HOME}" = "" ]; then
export JAVA_HOME=`readlink -f /usr/bin/java | sed "s:jre/::" | sed "s:bin/java::"`
fi
if [ "${PKG_CONFIG_PATH}" = "" ]; then
export PKG_CONFIG_PATH="/usr/lib64/pkgconfig/"
fi
Expand All @@ -144,9 +130,6 @@ case $SWT_OS.$SWT_ARCH in
if [ "${CC}" = "" ]; then
export CC=gcc
fi
if [ "${JAVA_HOME}" = "" ]; then
export JAVA_HOME=`readlink -f /usr/bin/java | sed "s:jre/bin/java::"`
fi
if [ "${PKG_CONFIG_PATH}" = "" ]; then
export PKG_CONFIG_PATH="/usr/lib64/pkgconfig/"
fi
Expand Down Expand Up @@ -177,22 +160,30 @@ else
func_echo_error "Cairo not found: Advanced graphics support using cairo will not be compiled."
fi


if [ -z ${SWT_JAVA_HOME} ] || [ ! -f "${SWT_JAVA_HOME}/include/jni.h" ]; then
func_echo_error "SWT_JAVA_HOME not set and jni.h could not be located. You might get a compile error about include 'jni.h'. You should install 'java-*-openjdk-devel' package or if you have it installed already, find jni.h and set SWT_JAVA_HOME manually to base of 'include' folder"
else
func_echo_plus "jni.h found"
fi

# Find AWT if available
if [ ${SWT_OS} = 'win32' ]; then
AWT_LIB_EXPR="jawt.dll"
else
AWT_LIB_EXPR="libjawt.so"
fi


if [ -z "${AWT_LIB_PATH}" ]; then
if [ -f ${JAVA_HOME}/jre/lib/${AWT_ARCH}/${AWT_LIB_EXPR} ]; then
AWT_LIB_PATH=${JAVA_HOME}/jre/lib/${AWT_ARCH}
if [ -f ${SWT_JAVA_HOME}/jre/lib/${AWT_ARCH}/${AWT_LIB_EXPR} ]; then
AWT_LIB_PATH=${SWT_JAVA_HOME}/jre/lib/${AWT_ARCH}
export AWT_LIB_PATH
elif [ -f ${JAVA_HOME}/lib/${AWT_LIB_EXPR} ]; then
AWT_LIB_PATH=${JAVA_HOME}/lib
elif [ -f ${SWT_JAVA_HOME}/lib/${AWT_LIB_EXPR} ]; then
AWT_LIB_PATH=${SWT_JAVA_HOME}/lib
export AWT_LIB_PATH
else
AWT_LIB_PATH=${JAVA_HOME}/jre/bin
AWT_LIB_PATH=${SWT_JAVA_HOME}/jre/bin
export AWT_LIB_PATH
fi
fi
Expand Down
Expand Up @@ -14,6 +14,10 @@

# Makefile for creating SWT libraries for Linux GTK

# assumes these variables are set in the environment from which make is run
# SWT_JAVA_HOME
# OUTPUT_DIR

# SWT debug flags for various SWT components.
#SWT_WEBKIT_DEBUG = -DWEBKIT_DEBUG

Expand Down Expand Up @@ -104,8 +108,8 @@ CFLAGS := $(CFLAGS) \
$(SWT_DEBUG) \
$(SWT_WEBKIT_DEBUG) \
-DLINUX -DGTK \
-I$(JAVA_HOME)/include \
-I$(JAVA_HOME)/include/linux \
-I$(SWT_JAVA_HOME)/include \
-I$(SWT_JAVA_HOME)/include/linux \
${SWT_PTR_CFLAGS}
LFLAGS = -shared -fPIC ${SWT_LFLAGS}

Expand Down
36 changes: 3 additions & 33 deletions bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/build.bat
Expand Up @@ -48,21 +48,10 @@ IF NOT EXIST "%MSVC_HOME%" (
CALL :ECHO "MSVC_HOME: %MSVC_HOME%"
)

@rem Search for a usable JDK
@rem -----------------------
IF "%SWT_JAVA_HOME%"=="" CALL :ECHO "'SWT_JAVA_HOME' was not provided, auto-searching for JDK..."
@rem Search for generic JDKs so that user can build with little configuration
@rem Note that first found JDK wins, so sort them by order of preference.
IF "%SWT_JAVA_HOME%"=="" CALL :TryToUseJdk "%ProgramFiles%\Java\jdk-11*"
IF "%SWT_JAVA_HOME%"=="" CALL :TryToUseJdk "%ProgramFiles%\AdoptOpenJDK\jdk-11*"
IF "%SWT_JAVA_HOME%"=="" CALL :TryToUseJdk "%ProgramFiles%\Java\jdk-17*"
IF "%SWT_JAVA_HOME%"=="" CALL :TryToUseJdk "%ProgramFiles%\AdoptOpenJDK\jdk-17*"
@rem Report
@rem Check for a usable JDK
IF "%SWT_JAVA_HOME%"=="" CALL :ECHO "'SWT_JAVA_HOME' was not provided"
IF NOT EXIST "%SWT_JAVA_HOME%" (
CALL :ECHO "WARNING: x64 Java JDK not found. Please set SWT_JAVA_HOME to your JDK directory."
CALL :ECHO " Refer steps for SWT Windows native setup: https://www.eclipse.org/swt/swt_win_native.php"
) ELSE (
CALL :ECHO "SWT_JAVA_HOME x64: %SWT_JAVA_HOME%"
CALL :ECHO "WARNING: x64 Java JDK not found. Please set SWT_JAVA_HOME to the JDK directory containing the intended JDK native headers."
)

@rem -----------------------
Expand Down Expand Up @@ -152,25 +141,6 @@ GOTO :EOF
SET "MSVC_HOME=%TESTED_VS_PATH%"
GOTO :EOF

:TryToUseJdk
SET "TESTED_JDK_PATH_MASK=%~1"
@rem Loop over all directories matching mask.
@rem Note that directories are iterated in alphabetical order and *last* hit will
@rem be selected in hopes to select the highest available JDK version.
FOR /D %%I IN ("%TESTED_JDK_PATH_MASK%") DO (
IF NOT EXIST "%%~I" (
CALL :ECHO "-- JDK '%%~I' doesn't exist on disk"
GOTO :EOF
)
IF NOT EXIST "%%~I\include\jni.h" (
CALL :ECHO "-- JDK '%%~I' is bad: no jni.h"
GOTO :EOF
)
CALL :ECHO "-- JDK '%%~I' looks good, selecting it"
SET "SWT_JAVA_HOME=%%~I"
)
GOTO :EOF

@rem Regular ECHO has trouble with special characters such as ().
@rem At the same time, if its argument is quoted, the quotes are printed literally.
@rem The workaround is to escape all special characters with ^
Expand Down
2 changes: 2 additions & 0 deletions bundles/org.eclipse.swt/buildSWT.xml
Expand Up @@ -814,6 +814,7 @@
<arg line="build.sh"/>
<env key="GTK_VERSION" value="${gtk_version}"/>
<env key="MODEL" value="${swt.arch}"/>
<env key="SWT_JAVA_HOME" value="${java.version}"/>
<env key="OUTPUT_DIR" value="${output_dir}"/>
<arg line="${targets}"/>
<arg line="${clean}"/>
Expand All @@ -825,6 +826,7 @@
<path location="${output_dir}"></path>
</pathconvert>
<exec dir="${build_dir}" executable="${build_dir}/build.bat" failonerror="true">
<env key="SWT_JAVA_HOME" value="${java.version}"/>
<env key="OUTPUT_DIR" value="${win_output_dir}"/>
<arg line="${targets}"/>
<arg line="${clean}"/>
Expand Down

0 comments on commit e5e038d

Please sign in to comment.