-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add soemJavaNativeLibrary and support cross compilation for aarch64 #18
Changes from 4 commits
09c7709
ad2a54d
e4f03c5
2ce4bef
b1749d0
db43415
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) | ||
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) | ||
set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu) | ||
set(CMAKE_PROGRAM_PATH /usr/aarch64-linux-gnu/bin) | ||
|
||
set(ENV{AARCH64_CROSS} "1") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,14 +131,17 @@ The gradle build files for the SOEM wrapper and native libraries are created by | |
|
||
To build and publish run the following commands. Note that the gradle commands are ran from within the build directory. | ||
|
||
|
||
- cd ihmc-ethercat-master | ||
- mkdir build | ||
- cd build | ||
- cmake -DCMAKE_BUILD_TYPE=Release .. | ||
- make | ||
- ../gradlew publishToMavenLocal -Ptarget=JAVA | ||
- ../gradlew publishToMavenLocal -Ptarget=PLATFORM | ||
``` | ||
cd ihmc-ethercat-master | ||
mkdir build | ||
cd build | ||
cmake -DCMAKE_BUILD_TYPE=Release .. | ||
# Cross compile for arm64 using the toolchain | ||
# cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../linux-aarch64-toolchain.cmake .. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this means we need to run this on any arm64 machine? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When running on a native arm platform you don't need to use the cross compilation toolchain |
||
make | ||
../gradlew publishToMavenLocal -Ptarget=JAVA | ||
../gradlew publishToMavenLocal -Ptarget=PLATFORM | ||
``` | ||
|
||
Note that if you want to publish multiple platform libraries you only have to run target=JAVA on a single platform | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package us.ihmc.etherCAT; | ||
|
||
import us.ihmc.tools.nativelibraries.NativeLibraryDescription; | ||
import us.ihmc.tools.nativelibraries.NativeLibraryLoader; | ||
import us.ihmc.tools.nativelibraries.NativeLibraryWithDependencies; | ||
|
||
public class soemJavaNativeLibrary implements NativeLibraryDescription | ||
{ | ||
@Override | ||
public String getPackage(OperatingSystem os, Architecture arch) | ||
{ | ||
return "us.ihmc.soem.generated"; | ||
} | ||
|
||
@Override | ||
public NativeLibraryWithDependencies getLibraryWithDependencies(OperatingSystem os, Architecture arch) | ||
{ | ||
if (os == OperatingSystem.LINUX64 && arch == Architecture.x64) | ||
{ | ||
return NativeLibraryWithDependencies.fromFilename("libsoemJava-x86_64.so"); | ||
} | ||
else if (os == OperatingSystem.LINUX64 && arch == Architecture.arm64) | ||
{ | ||
return NativeLibraryWithDependencies.fromFilename("libsoemJava-arm64.so"); | ||
} | ||
throw new RuntimeException("Unsupported platform: " + os.name() + "-" + arch.name()); | ||
} | ||
|
||
private static boolean loaded = false; | ||
|
||
public static boolean load() | ||
{ | ||
if (!loaded) | ||
{ | ||
soemJavaNativeLibrary lib = new soemJavaNativeLibrary(); | ||
loaded = NativeLibraryLoader.loadLibrary(lib); | ||
} | ||
return loaded; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,29 @@ | ||
cmake_minimum_required(VERSION 2.8) | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
find_package(JNI REQUIRED) | ||
include_directories(${JNI_INCLUDE_DIRS}) | ||
FIND_PACKAGE(SWIG REQUIRED) | ||
INCLUDE(${SWIG_USE_FILE}) | ||
find_package(SWIG REQUIRED) | ||
include(${SWIG_USE_FILE}) | ||
|
||
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/swig/") | ||
INCLUDE_DIRECTORIES("/usr/include/soem") | ||
include_directories("${PROJECT_SOURCE_DIR}/swig/") | ||
include_directories("/usr/include/soem") | ||
|
||
SET_PROPERTY(SOURCE soem.i PROPERTY SWIG_FLAGS "-package" "us.ihmc.soem.generated") | ||
set_property(SOURCE soem.i PROPERTY SWIG_FLAGS "-package" "us.ihmc.soem.generated") | ||
|
||
SWIG_ADD_MODULE(soemJava java soem.i) | ||
swig_link_libraries(soemJava ihmcsoemwrapper) | ||
if(UNIX AND NOT APPLE) | ||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" AND NOT DEFINED ENV{AARCH64_CROSS}) | ||
message(STATUS "Using target platform x86_64") | ||
set(LIBRARY_NAME "soemJava-x86_64") | ||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR DEFINED ENV{AARCH64_CROSS}) | ||
message(STATUS "Using target platform arm64") | ||
set(LIBRARY_NAME "soemJava-arm64") | ||
else() | ||
message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}") | ||
endif() | ||
else() | ||
message(FATAL_ERROR "This CMake configuration is only for Linux.") | ||
endif() | ||
|
||
# Add SWIG module with the architecture-specific library name | ||
swig_add_module(${LIBRARY_NAME} java soem.i) | ||
swig_link_libraries(${LIBRARY_NAME} ihmcsoemwrapper) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will have to publish these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Looks like that's why the checks are failing. Maybe you should go ahead and publish so the tests in the PR pass?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, note that there is 1 failing test on develop already