diff --git a/.github/workflows/natives.yml b/.github/workflows/natives.yml index b575eed8..96f2a44d 100644 --- a/.github/workflows/natives.yml +++ b/.github/workflows/natives.yml @@ -36,6 +36,10 @@ jobs: if: matrix.os == 'ubuntu' run: sudo apt install libxt-dev + - name: install g++-aarch64-linux-gnu + if: matrix.os == 'ubuntu' + run: sudo apt install g++-aarch64-linux-gnu + - name: Setup Java 11 uses: actions/setup-java@v4 with: diff --git a/flatlaf-natives/flatlaf-natives-linux/README.md b/flatlaf-natives/flatlaf-natives-linux/README.md index 3dd00c68..4be74776 100644 --- a/flatlaf-natives/flatlaf-natives-linux/README.md +++ b/flatlaf-natives/flatlaf-natives-linux/README.md @@ -5,12 +5,15 @@ This sub-project contains the source code for the FlatLaf Linux native library. The native library can be built only on Linux and requires a C++ compiler. +The native library is available for following CPU architectures: `x86_64` (or +`amd64`) and `arm64` (or `aarch64`). + To be able to build FlatLaf on any platform, and without C++ compiler, the -pre-built native library is checked into Git at +pre-built native libraries are checked into Git at [flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/](https://github.com/JFormDesigner/FlatLaf/tree/main/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives). -The native library was built on a GitHub server with the help of GitHub Actions. -See: +The native libraries were built on a GitHub server with the help of GitHub +Actions. See: [Native Libraries](https://github.com/JFormDesigner/FlatLaf/actions/workflows/natives.yml) workflow. Then the produced Artifacts ZIP was downloaded and the native library checked into Git. @@ -18,19 +21,27 @@ checked into Git. ## Development -To build the library on Linux, some packages needs to be installed. +To build the library on Linux, some packages needs to be installed: + +- `build-essential` - GCC and development tools +- `libxt-dev` - X11 toolkit development headers +- `g++-aarch64-linux-gnu` - GNU C++ compiler for the arm64 architecture (only on + x86_64 Linux for cross-compiling for arm64 architecture) ### Ubuntu -`build-essential` contains GCC and development tools. `libxt-dev` contains the -X11 toolkit development headers. - ~~~ sudo apt update sudo apt install build-essential libxt-dev ~~~ +Only on x86_64 Linux for cross-compiling for arm64 architecture: + +~~~ +sudo apt install g++-aarch64-linux-gnu +~~~ + ### CentOS diff --git a/flatlaf-natives/flatlaf-natives-linux/build.gradle.kts b/flatlaf-natives/flatlaf-natives-linux/build.gradle.kts index 737385e3..abfad042 100644 --- a/flatlaf-natives/flatlaf-natives-linux/build.gradle.kts +++ b/flatlaf-natives/flatlaf-natives-linux/build.gradle.kts @@ -45,8 +45,11 @@ tasks { if( org.gradle.internal.os.OperatingSystem.current().isLinux ) { val osArch = System.getProperty( "os.arch" ) - if( osArch == "amd64" || osArch == "x86-64" ) + if( osArch == "amd64" ) { dependsOn( "linkReleaseX86-64" ) + if( file( "/usr/bin/aarch64-linux-gnu-gcc" ).exists() ) + dependsOn( "linkCrossAarch64" ) + } if( osArch == "aarch64" ) dependsOn( "linkReleaseAarch64" ) } @@ -97,4 +100,67 @@ tasks { } } } + + if( org.gradle.internal.os.OperatingSystem.current().isLinux && + System.getProperty( "os.arch" ) == "amd64" && + file( "/usr/bin/aarch64-linux-gnu-gcc" ).exists() ) + { + register( "compileCrossAarch64Cpp" ) { + val include = layout.projectDirectory.dir( "src/main/headers" ) + val src = layout.projectDirectory.dir( "src/main/cpp" ) + workingDir = file( layout.buildDirectory.dir( "obj/main/release/aarch64-cross" ) ) + + doFirst { + workingDir.mkdirs() + } + + commandLine = listOf( + "aarch64-linux-gnu-gcc", + "-c", + "-fPIC", + "-fvisibility=hidden", + "-O3", + "-I", "${javaHome}/include", + "-I", "${javaHome}/include/linux", + "-I", "$include", + + "$src/ApiVersion.cpp", + "$src/X11WmUtils.cpp", + ) + } + + register( "linkCrossAarch64" ) { + dependsOn( "compileCrossAarch64Cpp" ) + + val nativesDir = project( ":flatlaf-core" ).projectDir.resolve( "src/main/resources/com/formdev/flatlaf/natives" ) + val libraryName = "libflatlaf-linux-arm64.so" + val outDir = file( layout.buildDirectory.dir( "lib/main/release/aarch64-cross" ) ) + val objDir = file( layout.buildDirectory.dir( "obj/main/release/aarch64-cross" ) ) + + doFirst { + outDir.mkdirs() + } + + commandLine = listOf( + "aarch64-linux-gnu-gcc", + "-shared", + "-Wl,-soname,$libraryName", + "-o", "$outDir/$libraryName", + + "$objDir/ApiVersion.o", + "$objDir/X11WmUtils.o", + + "-L${layout.projectDirectory}/lib/aarch64", + "-ljawt", + ) + + doLast { + // copy shared library to flatlaf-core resources + copy { + from( "$outDir/$libraryName" ) + into( nativesDir ) + } + } + } + } } diff --git a/flatlaf-natives/flatlaf-natives-linux/lib/README.md b/flatlaf-natives/flatlaf-natives-linux/lib/README.md new file mode 100644 index 00000000..f0f72077 --- /dev/null +++ b/flatlaf-natives/flatlaf-natives-linux/lib/README.md @@ -0,0 +1,4 @@ +Contains libraries used to compile FlatLaf native libraries. + +- `aarch64/libjawt.so` is `/lib/libjawt.so` from Eclipse Temurin 11.0.25+9 aarch64, + which is required to cross build aarch64/arm64 .so on x86_64 diff --git a/flatlaf-natives/flatlaf-natives-linux/lib/aarch64/libjawt.so b/flatlaf-natives/flatlaf-natives-linux/lib/aarch64/libjawt.so new file mode 100644 index 00000000..1c03d7df Binary files /dev/null and b/flatlaf-natives/flatlaf-natives-linux/lib/aarch64/libjawt.so differ diff --git a/flatlaf-natives/flatlaf-natives-windows/README.md b/flatlaf-natives/flatlaf-natives-windows/README.md index c164e381..f8504fb8 100644 --- a/flatlaf-natives/flatlaf-natives-windows/README.md +++ b/flatlaf-natives/flatlaf-natives-windows/README.md @@ -8,8 +8,8 @@ The native library can be built only on Windows and requires a C++ compiler. Tested with Microsoft Visual C++ (MSVC) 2019 and 2022 (comes with Visual Studio 2019 and 2022). -The native library is available for folloging CPU architectures: `x86_64` (or -`amd64`), `x86` and `arm64`. +The native library is available for following CPU architectures: `x86_64` (or +`amd64`), `x86` and `arm64` (or `aarch64`). To be able to build FlatLaf on any platform, and without C++ compiler, the pre-built DLLs are checked into Git at