Skip to content

Commit

Permalink
Compile SWT natives for Windows on Arm64 (WoA).
Browse files Browse the repository at this point in the history
This commit mainly contains changes to the build.bat file,
to support compiling the SWT natives for the WoA platform.

On a WoA box, run the following commands to produce the
SWT natives (swt*.dll) for WoA:

  cd binaries\org.eclipse.swt.win32.win32.aarch64
  mvn clean process-resources -Dnative=win32.win32.aarch64

and the swt*.dll files for WoA will be created in the current directory.

(Similarly, to recompile the existing SWT x64 natives, run the following
commands on an x64 box:
  cd binaries\org.eclipse.swt.win32.win32.x86_64
  mvn clean process-resources -Dnative=win32.win32.x86_64
)

Cross-compiling between the x64 and Arm64 platforms, where either of
them can be host or target, is also possible, after setting up the
TARGET_ARCH environment variable with correct target architecture value,
and with the SWT_JAVA_HOME property pointing to an available JDK of
the target architecture.

For example, to cross-compile on an x64 host and produce SWT natives for
Arm64 target, run the following commands:

  set TARGET_ARCH=arm64
  cd binaries\org.eclipse.swt.win32.win32.aarch64
  mvn clean process-resources -Dnative=win32.win32.aarch64 -DSWT_JAVA_HOME=\path\to\arm64_jdk

and the swt*.dll files for WoA will be created in the current directory.
Note the above SWT_JAVA_HOME property in the command line which points
to an available Arm64 JDK of the target architecture.

Similarly, to cross-compile on an Arm64 host and produce SWT natives for
x64 target, run the following commands:

  set TARGET_ARCH=x64
  cd binaries\org.eclipse.swt.win32.win32.x86_64
  mvn clean process-resources -Dnative=win32.win32.x86_64 -DSWT_JAVA_HOME=\path\to\x64_jdk

and the swt*.dll files for x64 will be created in the current directory.

For cross-compiling between x64 and Arm64 to work, install the MSVC
compiler version 2022, with mandatory build tools for both platforms.
  • Loading branch information
chirontt committed Mar 5, 2024
1 parent 50d7ef7 commit be6bd28
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 6 deletions.
34 changes: 34 additions & 0 deletions binaries/org.eclipse.swt.win32.win32.aarch64/META-INF/MANIFEST.MF
@@ -0,0 +1,34 @@
Manifest-Version: 1.0
Fragment-Host: org.eclipse.swt;bundle-version="[3.125.0,4.0.0)"
Bundle-Name: %fragmentName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.swt.win32.win32.aarch64; singleton:=true
Bundle-Version: 3.125.0.qualifier
Bundle-ManifestVersion: 2
Bundle-Localization: fragment
Export-Package:
org.eclipse.swt,
org.eclipse.swt.accessibility,
org.eclipse.swt.awt,
org.eclipse.swt.browser,
org.eclipse.swt.custom,
org.eclipse.swt.dnd,
org.eclipse.swt.events,
org.eclipse.swt.graphics,
org.eclipse.swt.layout,
org.eclipse.swt.opengl,
org.eclipse.swt.printing,
org.eclipse.swt.program,
org.eclipse.swt.widgets,
org.eclipse.swt.internal; x-friends:="org.eclipse.ui",
org.eclipse.swt.internal.image; x-internal:=true,
org.eclipse.swt.ole.win32,
org.eclipse.swt.internal.gdip; x-internal:=true,
org.eclipse.swt.internal.ole.win32; x-internal:=true,
org.eclipse.swt.internal.win32; x-internal:=true,
org.eclipse.swt.internal.opengl.win32; x-internal:=true
Eclipse-PlatformFilter: (& (osgi.ws=win32) (osgi.os=win32) (osgi.arch=aarch64))
SWT-WS: win32
SWT-OS: win32
SWT-Arch: aarch64
Automatic-Module-Name: org.eclipse.swt.win32.win32.aarch64
40 changes: 40 additions & 0 deletions binaries/org.eclipse.swt.win32.win32.aarch64/build.properties
@@ -0,0 +1,40 @@
###############################################################################
# Copyright (c) 2023, 2024 Tue Ton and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Tue Ton - initial API and implementation
# Hannes Wellmann - Leverage Tycho pomless
###############################################################################
custom = true
bin.includes = .,*.dll,about_files/,about.html,fragment.properties
bin.excludes = library/
source.. = \
../../bundles/org.eclipse.swt/Eclipse SWT/win32,\
../../bundles/org.eclipse.swt/Eclipse SWT/common,\
../../bundles/org.eclipse.swt/Eclipse SWT PI/common,\
../../bundles/org.eclipse.swt/Eclipse SWT PI/win32,\
../../bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32,\
../../bundles/org.eclipse.swt/Eclipse SWT Accessibility/win32,\
../../bundles/org.eclipse.swt/Eclipse SWT Accessibility/common,\
../../bundles/org.eclipse.swt/Eclipse SWT AWT/win32,\
../../bundles/org.eclipse.swt/Eclipse SWT AWT/common,\
../../bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32,\
../../bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/common,\
../../bundles/org.eclipse.swt/Eclipse SWT Printing/win32,\
../../bundles/org.eclipse.swt/Eclipse SWT Printing/common,\
../../bundles/org.eclipse.swt/Eclipse SWT Program/win32,\
../../bundles/org.eclipse.swt/Eclipse SWT Program/common,\
../../bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common,\
../../bundles/org.eclipse.swt/Eclipse SWT Browser/common,\
../../bundles/org.eclipse.swt/Eclipse SWT Browser/win32,\
../../bundles/org.eclipse.swt/Eclipse SWT OpenGL/win32,\
../../bundles/org.eclipse.swt/Eclipse SWT OpenGL/common
src.includes = about.html,about_files/

pom.model.property.os=win32
pom.model.property.ws=win32
pom.model.property.arch=aarch64
40 changes: 34 additions & 6 deletions bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/build.bat
Expand Up @@ -13,7 +13,6 @@
@rem ***************************************************************************

@rem The original build.bat source is located in /org.eclipse.swt/Eclipse SWT PI/win32/library/build.bat. It is copied during various build(s).
@rem Typically it's not ran directly, instead it is reached by build.xml's build_libraries target found in eclipse.platform.swt\bundles\org.eclipse.swt.win32.win32.x86*

@echo off
echo
Expand Down Expand Up @@ -51,15 +50,44 @@ IF NOT EXIST "%MSVC_HOME%" (
@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 the JDK directory containing the intended JDK native headers."
CALL :ECHO "WARNING: 64-bit Java JDK not found. Please set SWT_JAVA_HOME to the JDK directory containing the intended JDK native headers."
)

@rem -----------------------
set PROCESSOR_ARCHITECTURE=AMD64
IF "x.%OUTPUT_DIR%"=="x." set OUTPUT_DIR=..\..\..\org.eclipse.swt.win32.win32.x86_64
@REM Compose host architecture string for MSVC
IF "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
SET HOST_ARCH=x64
) ELSE IF "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
SET HOST_ARCH=arm64
) ELSE (
CALL :ECHO "ERROR: Unknown host architecture: %PROCESSOR_ARCHITECTURE%."
EXIT /B 1
)

@REM %TARGET_ARCH% may be specified by the caller for cross-compiling.
@REM If not, build for builder machine's architecture
IF "%TARGET_ARCH%"=="" (
SET TARGET_ARCH=%HOST_ARCH%
)

@REM Compose build argument for MSVC
IF "%TARGET_ARCH%"=="%HOST_ARCH%" (
SET BUILD_ARCH=%TARGET_ARCH%
) ELSE (
SET BUILD_ARCH=%HOST_ARCH%_%TARGET_ARCH%
)

@REM Select build's output directory (if not specified) based on target arch
IF "%TARGET_ARCH%"=="x64" (
IF "x.%OUTPUT_DIR%"=="x." SET OUTPUT_DIR=..\..\..\org.eclipse.swt.win32.win32.x86_64
) ELSE IF "%TARGET_ARCH%"=="arm64" (
IF "x.%OUTPUT_DIR%"=="x." SET OUTPUT_DIR=..\..\..\org.eclipse.swt.win32.win32.aarch64
) ELSE (
CALL :ECHO "ERROR: Unknown target architecture: %TARGET_ARCH%."
EXIT /B 1
)

set CFLAGS=-DJNI64
call "%MSVC_HOME%\VC\Auxiliary\Build\vcvarsall.bat" x64
call "%MSVC_HOME%\VC\Auxiliary\Build\vcvarsall.bat" %BUILD_ARCH%

@rem if call to vcvarsall.bat (which sets up environment) silently fails, then provide advice to user.
WHERE cl
Expand Down

0 comments on commit be6bd28

Please sign in to comment.