Skip to content
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

Merged
merged 6 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.5.1)
project(ihmcsoemwrapper)

add_subdirectory(swig)
70 changes: 0 additions & 70 deletions Dockerfile

This file was deleted.

72 changes: 72 additions & 0 deletions Dockerfile-arm64_cross
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Do not publish to dockerhub
FROM ubuntu:20.04

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get --yes update \
&& apt-get --yes install \
nano \
git \
wget \
curl \
unzip \
locales \
apt-transport-https \
ca-certificates \
curl \
software-properties-common \
sudo \
build-essential \
swig \
cmake \
openjdk-17-jdk \
gcc-aarch64-linux-gnu \
binutils-aarch64-linux-gnu \
g++-aarch64-linux-gnu \
&& rm -rf /var/lib/apt/lists/*

RUN locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8

ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
ENV PATH=$PATH:$JAVA_HOME/bin

# Installing SOEM
WORKDIR /opt
RUN git clone https://github.com/OpenEtherCATsociety/SOEM.git
WORKDIR /opt/SOEM
RUN mkdir build && cd build
WORKDIR /opt/SOEM/build
RUN cmake -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \
-DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \
-DCMAKE_FIND_ROOT_PATH=/usr/aarch64-linux-gnu \
-DCMAKE_PROGRAM_PATH=/usr/aarch64-linux-gnu/bin \
-DHOST_INSTALL="" -DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_POSITION_INDEPENDENT_CODE=true \
-DCMAKE_BUILD_TYPE=Release \
..
RUN make
RUN make install

# Setup a robotlab user as the development user, to avoid using root.
# Allows using sudo with robotlab user without a password.
RUN addgroup robotlab \
&& adduser --uid 1000 --gid 1000 --home /home/robotlab --disabled-password robotlab \
&& chown -R robotlab /home/robotlab \
&& adduser robotlab sudo \
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER robotlab
WORKDIR /home/robotlab

RUN mkdir -p /home/robotlab/dev/ihmc-ethercat-master/build
RUN mkdir -p /home/robotlab/dev/ihmc-ethercat-master/src
RUN mkdir -p /home/robotlab/dev/ihmc-ethercat-master/swig
VOLUME /home/robotlab/dev/ihmc-ethercat-master/build
VOLUME /home/robotlab/dev/ihmc-ethercat-master/src
VOLUME /home/robotlab/dev/ihmc-ethercat-master/swig
WORKDIR /home/robotlab/dev/ihmc-ethercat-master

ENTRYPOINT ["/bin/bash"]
CMD ["build-arm64_cross.sh"]
62 changes: 62 additions & 0 deletions Dockerfile-x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Do not publish to dockerhub
FROM ubuntu:20.04

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get --yes update \
&& apt-get --yes install \
nano \
git \
wget \
curl \
unzip \
locales \
apt-transport-https \
ca-certificates \
curl \
software-properties-common \
sudo \
build-essential \
swig \
cmake \
openjdk-17-jdk \
&& rm -rf /var/lib/apt/lists/*

RUN locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8

ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
ENV PATH=$PATH:$JAVA_HOME/bin

# Installing SOEM
WORKDIR /opt
RUN git clone https://github.com/OpenEtherCATsociety/SOEM.git
WORKDIR /opt/SOEM
RUN mkdir build && cd build
WORKDIR /opt/SOEM/build
RUN cmake -DHOST_INSTALL="" -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_POSITION_INDEPENDENT_CODE=true -DCMAKE_BUILD_TYPE=Release ..
RUN make
RUN make install

# Setup a robotlab user as the development user, to avoid using root.
# Allows using sudo with robotlab user without a password.
RUN addgroup robotlab \
&& adduser --uid 1000 --gid 1000 --home /home/robotlab --disabled-password robotlab \
&& chown -R robotlab /home/robotlab \
&& adduser robotlab sudo \
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER robotlab
WORKDIR /home/robotlab

RUN mkdir -p /home/robotlab/dev/ihmc-ethercat-master/build
RUN mkdir -p /home/robotlab/dev/ihmc-ethercat-master/src
RUN mkdir -p /home/robotlab/dev/ihmc-ethercat-master/swig
VOLUME /home/robotlab/dev/ihmc-ethercat-master/build
VOLUME /home/robotlab/dev/ihmc-ethercat-master/src
VOLUME /home/robotlab/dev/ihmc-ethercat-master/swig
WORKDIR /home/robotlab/dev/ihmc-ethercat-master

ENTRYPOINT ["/bin/bash"]
CMD ["build-x86_64.sh"]
11 changes: 11 additions & 0 deletions build-arm64_cross.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
export AARCH64_CROSS=1

# Build for arm64
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../linux-aarch64-toolchain.cmake ..
make
../gradlew publishToMavenLocal -Ptarget=JAVA
../gradlew publishToMavenLocal -Ptarget=PLATFORM
cd ..
12 changes: 4 additions & 8 deletions build.sh → build-x86_64.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#!/bin/bash
# Uncomment for debugging this script
set -o xtrace

#!/bin/sh
# Build for native platform (probably x86_64)
mkdir -p build
cd build

cmake -DCMAKE_BUILD_TYPE=Release ..
make

pwd
ls ..
../gradlew publishToMavenLocal -Ptarget=JAVA
../gradlew publishToMavenLocal -Ptarget=PLATFORM
cd ..
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ ihmc {
app.entrypoint("SlaveInfo", "us.ihmc.etherCAT.master.SlaveInfo")

mainDependencies {
api("us.ihmc:soem:1.4.0-ihmc1")
api("us.ihmc:soem-platform-linux:1.4.0-ihmc1")
api("us.ihmc:soem:1.5.0")
api("us.ihmc:soem-platform-linux-x86_64:1.5.0")
api("us.ihmc:soem-platform-linux-arm64:1.5.0")
Comment on lines +20 to +22
Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Contributor Author

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

api("us.ihmc:ihmc-native-library-loader:2.0.3")
api("us.ihmc:ihmc-realtime:1.6.0")
}
Expand Down
3 changes: 3 additions & 0 deletions buildDockerImages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
docker build -f Dockerfile-x86_64 -t ihmcrobotics/soem-compile-x86_64:0.1 .
docker build -f Dockerfile-arm64_cross -t ihmcrobotics/soem-compile-arm64_cross:0.1 .
75 changes: 45 additions & 30 deletions buildWithDocker.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
#!/bin/bash
# Uncomment for debugging this script
set -o xtrace
#!/bin/sh
rm -rf buildDocker
mkdir -p buildDocker

# Make sure it works one way or the other to reduce possible errors
if (( EUID == 0 )); then
echo "Run without sudo." 1>&2
exit 1
fi
echo "Building soemJava x86_64"
sudo docker run \
--rm \
--tty \
--interactive \
--network host \
--dns=1.1.1.1 \
--volume "$(pwd)/buildDocker":/home/robotlab/dev/ihmc-ethercat-master/build \
--volume "$(pwd)/src":/home/robotlab/dev/ihmc-ethercat-master/src \
--volume "$(pwd)/swig":/home/robotlab/dev/ihmc-ethercat-master/swig \
--volume "$(pwd)/build.gradle.kts":/home/robotlab/dev/ihmc-ethercat-master/build.gradle.kts \
--volume "$(pwd)/gradle.properties":/home/robotlab/dev/ihmc-ethercat-master/gradle.properties \
--volume "$(pwd)/settings.gradle.kts":/home/robotlab/dev/ihmc-ethercat-master/settings.gradle.kts \
--volume "$(pwd)/CMakeLists.txt":/home/robotlab/dev/ihmc-ethercat-master/CMakeLists.txt \
--volume "$(pwd)/build-x86_64.sh":/home/robotlab/dev/ihmc-ethercat-master/build-x86_64.sh \
--volume "$(pwd)/gradlew":/home/robotlab/dev/ihmc-ethercat-master/gradlew \
--volume "$(pwd)/gradle/wrapper":/home/robotlab/dev/ihmc-ethercat-master/gradle/wrapper \
--volume "$HOME/.m2":/home/robotlab/.m2 \
ihmcrobotics/soem-compile-x86_64:0.1

sleep 1
rm -rf buildDocker
mkdir -p buildDocker
sleep 1

if [ ! "$(sudo -u root docker ps -a | grep ethercat-master)" ]; then
echo "ethercat-master not found. Running new container."
sudo -u root docker run \
--tty \
--interactive \
--name ethercat-master \
--network host \
--dns=1.1.1.1 \
--volume "$(pwd)/buildDocker":/home/robotlab/dev/ihmc-ethercat-master/build \
--volume "$(pwd)/src":/home/robotlab/dev/ihmc-ethercat-master/src \
--volume "$(pwd)/swig":/home/robotlab/dev/ihmc-ethercat-master/swig \
--volume "$(pwd)/build.gradle.kts":/home/robotlab/dev/ihmc-ethercat-master/build.gradle.kts \
--volume "$(pwd)/gradle.properties":/home/robotlab/dev/ihmc-ethercat-master/gradle.properties \
--volume "$(pwd)/settings.gradle.kts":/home/robotlab/dev/ihmc-ethercat-master/settings.gradle.kts \
--volume "$(pwd)/CMakeLists.txt":/home/robotlab/dev/ihmc-ethercat-master/CMakeLists.txt \
--volume "$(pwd)/build.sh":/home/robotlab/dev/ihmc-ethercat-master/build.sh \
--volume "$(pwd)/gradlew":/home/robotlab/dev/ihmc-ethercat-master/gradlew \
--volume "$(pwd)/gradle/wrapper":/home/robotlab/dev/ihmc-ethercat-master/gradle/wrapper \
ihmcrobotics/ethercat-master:0.2
else
sudo -u root docker start --attach ethercat-master
fi
echo "Building soemJava arm64 (cross compiling)"
sudo docker run \
--rm \
--tty \
--interactive \
--network host \
--dns=1.1.1.1 \
--volume "$(pwd)/buildDocker":/home/robotlab/dev/ihmc-ethercat-master/build \
--volume "$(pwd)/src":/home/robotlab/dev/ihmc-ethercat-master/src \
--volume "$(pwd)/swig":/home/robotlab/dev/ihmc-ethercat-master/swig \
--volume "$(pwd)/build.gradle.kts":/home/robotlab/dev/ihmc-ethercat-master/build.gradle.kts \
--volume "$(pwd)/gradle.properties":/home/robotlab/dev/ihmc-ethercat-master/gradle.properties \
--volume "$(pwd)/settings.gradle.kts":/home/robotlab/dev/ihmc-ethercat-master/settings.gradle.kts \
--volume "$(pwd)/CMakeLists.txt":/home/robotlab/dev/ihmc-ethercat-master/CMakeLists.txt \
--volume "$(pwd)/linux-aarch64-toolchain.cmake":/home/robotlab/dev/ihmc-ethercat-master/linux-aarch64-toolchain.cmake \
--volume "$(pwd)/build-arm64_cross.sh":/home/robotlab/dev/ihmc-ethercat-master/build-arm64_cross.sh \
--volume "$(pwd)/gradlew":/home/robotlab/dev/ihmc-ethercat-master/gradlew \
--volume "$(pwd)/gradle/wrapper":/home/robotlab/dev/ihmc-ethercat-master/gradle/wrapper \
--volume "$HOME/.m2":/home/robotlab/.m2 \
ihmcrobotics/soem-compile-arm64_cross:0.1
8 changes: 8 additions & 0 deletions linux-aarch64-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.5.1)

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")
33 changes: 13 additions & 20 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..
Copy link

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Expand All @@ -149,16 +152,6 @@ Note that if you want to publish multiple platform libraries you only have to ru

### Compiling with Docker

Run `./buildWithDocker.sh`

The Docker image is hosted at [https://hub.docker.com/r/ihmcrobotics/ethercat-master]().

If changes to the Dockerfile are needed, build it with the following command, incrementing the version.
Then, increment the version in the buildWithDocker.sh file before running.

```
# docker build --tag ihmcrobotics/ethercat-master:0.X .
# docker rm ethercat-master
```
Build the docker images first with: `./buildDockerImages.sh`

For more about IHMC Robotics's usage of Docker, see [https://github.com/ihmcrobotics/ihmc-open-robotics-software/tree/develop/docker]().
Then run: `./buildWithDocker.sh` to build the artifacts, they will be copied to the host's local maven repository.
Loading
Loading