Skip to content

Commit

Permalink
[Jenkins-Build] Build SWT-natives against specified Java-17 JDKs
Browse files Browse the repository at this point in the history
Use the C header files and shared native libraries from minimal JustJ
JDKs when building the SWT native binaries on specialized build
machines.

Always specify the location of the JDK providing the headers/libs using
the 'SWT_JAVA_HOME' environment variable.
This allows to use another JDK as the one specified in the global
JAVA_HOME variable.

When building the natives for the current platform via Maven set the
value of 'SWT_JAVA_HOME' to the location of the running JDK, if not set
externally.

Fixes eclipse-platform#626
  • Loading branch information
HannesWell committed Apr 28, 2023
1 parent c43aaaa commit af86103
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 81 deletions.
33 changes: 16 additions & 17 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ spec:
}
}

/** Returns the download URL of the JDK against whoose C headers (in the 'include/' folder) and native libaries 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/20230428_1804/org.eclipse.justj.openjdk.hotspot.jre.minimal.stripped-17.0.7-${os}-${arch}.tar.gz"
}

pipeline {
options {
skipDefaultCheckout() // Specialiced checkout is performed below
Expand Down Expand Up @@ -129,29 +134,23 @@ pipeline {
}
steps {
script {
def (ws, os, arch) = env.PLATFORM.split('\\.')
dir("jdk-download-${os}.${arch}") {
// Fetch the JDK, which provides the C header-files and shared native libaries, against which the natives are build.
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

# 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
# AWT_LIB_PATH (only if build jawt shall be build)

include make_common.mak

SWT_PREFIX=swt
Expand All @@ -32,7 +37,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
33 changes: 11 additions & 22 deletions bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh
Original file line number Diff line number Diff line change
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,6 +160,12 @@ 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"
Expand All @@ -185,14 +174,14 @@ else
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
6 changes: 6 additions & 0 deletions bundles/org.eclipse.swt/buildSWT.xml
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,13 @@

<target name="build_local">
<property name="gtk_version" value="3.0" />
<property name="SWT_JAVA_HOME" value="${java.home}"/><!-- Not overwritten if already set-->
<echo>SWT_JAVA_HOME=${SWT_JAVA_HOME}</echo>
<exec dir="${build_dir}" executable="sh" failonerror="true">
<arg line="build.sh"/>
<env key="GTK_VERSION" value="${gtk_version}"/>
<env key="MODEL" value="${swt.arch}"/>
<env key="SWT_JAVA_HOME" value="${SWT_JAVA_HOME}"/>
<env key="OUTPUT_DIR" value="${output_dir}"/>
<arg line="${targets}"/>
<arg line="${clean}"/>
Expand All @@ -824,7 +827,10 @@
<pathconvert property="win_output_dir">
<path location="${output_dir}"></path>
</pathconvert>
<property name="SWT_JAVA_HOME" value="${java.home}"/><!-- Not overwritten if already set-->
<echo>SWT_JAVA_HOME=${SWT_JAVA_HOME}</echo>
<exec dir="${build_dir}" executable="${build_dir}/build.bat" failonerror="true">
<env key="SWT_JAVA_HOME" value="${SWT_JAVA_HOME}"/>
<env key="OUTPUT_DIR" value="${win_output_dir}"/>
<arg line="${targets}"/>
<arg line="${clean}"/>
Expand Down

0 comments on commit af86103

Please sign in to comment.