Skip to content

Commit

Permalink
#66 Fix ARM64 error loading hunspell
Browse files Browse the repository at this point in the history
  • Loading branch information
Erikvl87 committed Mar 15, 2023
1 parent b350f6d commit fc12f41
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 114 deletions.
24 changes: 18 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG LANGUAGETOOL_VERSION=6.0

FROM debian:buster as build
FROM debian:bullseye as build

ENV DEBIAN_FRONTEND=noninteractive

Expand All @@ -14,6 +14,14 @@ RUN apt-get update -y \
maven \
unzip \
xmlstarlet \

# packages required for arm64-workaround
build-essential \
cmake \
mercurial \
texlive \
wget \
zip \
&& apt-get clean

RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
Expand All @@ -31,10 +39,14 @@ RUN LANGUAGETOOL_DIST_FOLDER=$(find /dist/ -name 'LanguageTool-*') && mv $LANGUA
# Execute workarounds for ARM64 architectures.
# https://github.com/languagetool-org/languagetool/issues/4543
WORKDIR /
COPY arm64-workaround/. .
RUN chmod +x ./bridj.sh ./hunspell.sh
RUN bash -c "./bridj.sh"
RUN bash -c "./hunspell.sh"
COPY arm64-workaround/bridj.sh arm64-workaround/bridj.sh
RUN chmod +x arm64-workaround/bridj.sh
RUN bash -c "arm64-workaround/bridj.sh"

COPY arm64-workaround/hunspell.sh arm64-workaround/hunspell.sh
RUN chmod +x arm64-workaround/hunspell.sh
RUN bash -c "arm64-workaround/hunspell.sh"

WORKDIR /languagetool

# Note: When changing the base image, verify that the hunspell.sh workaround is
Expand All @@ -46,7 +58,7 @@ RUN apk add --no-cache \
curl \
libc6-compat \
libstdc++ \
openjdk11-jre-headless
openjdk11-jdk

# https://github.com/Erikvl87/docker-languagetool/issues/60
RUN ln -s /lib64/ld-linux-x86-64.so.2 /lib/ld-linux-x86-64.so.2
Expand Down
70 changes: 0 additions & 70 deletions arm64-workaround/bridj.patch

This file was deleted.

47 changes: 15 additions & 32 deletions arm64-workaround/bridj.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,39 @@ if [[ $(dpkg --print-architecture) != "arm64" ]]; then
exit;
fi

echo "Applying arm64 workaround."
echo "Applying arm64 workaround for BridJ."

# Make `wget` more robust by passing retry flags.
alias wget="wget --retry-connrefused --waitretry=30 --read-timeout=30 --timeout=30 --tries=20"
# Set java environment.
export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-arm64"

# Install dependencies.
apt-get install --yes build-essential \
mercurial \
wget \
zip
apt-get clean

####################
## BridJ setup ##
####################
mkdir /BridJ
cd /BridJ
git init
git remote add origin https://github.com/nativelibs4java/BridJ
git fetch --depth 1 origin 373c03447df44b5a5508e94fa897369b41b18f48
git checkout FETCH_HEAD
git apply ../bridj.patch
wget https://dyncall.org/r1.1/dyncall-1.1.tar.gz
tar xf dyncall-1.1.tar.gz
rm dyncall-1.1.tar.gz
mv dyncall-1.1 dyncall
git clone http://github.com/nativelibs4java/BridJ.git
wget https://dyncall.org/r1.4/dyncall-1.4.tar.gz
tar xf dyncall-1.4.tar.gz
rm dyncall-1.4.tar.gz
mv dyncall-1.4 /BridJ/dyncall
cd /BridJ/dyncall
hg init
cd /BridJ

apt-get install -y default-jdk
mvn clean install -DskipTests -Dmaven.javadoc.skip=true -e

####################
## BridJ build ##
####################
cd /BridJ
./BuildNative
mvn clean install -DskipTests -Dmaven.install.skip=true -Dmaven.javadoc.skip=true -e
./BuildNative -DFORCE_JAVA_HOME=/usr/lib/jvm/java-11-openjdk-arm64

####################
## Postprocessing ##
####################
cd /BridJ/target
mv bridj-0.7.1-SNAPSHOT.jar bridj.jar
# Extract desired `libbridj.so`. Will create the directory tree, too.
unzip bridj.jar org/bridj/lib/linux_aarch64/libbridj.so
# We do not need the `linux_aarch64` folder
zip -d bridj.jar org/bridj/lib/linux_aarch64
# Rename the extracted folder to `linux_x64`.
mv org/bridj/lib/linux_aarch64 org/bridj/lib/linux_x64
# Replace the `libbridj.so` inside the jar with the arm64 one.
mv bridj-0.8.0-SNAPSHOT.jar bridj.jar
unzip bridj.jar org/bridj/lib/linux_arm64/libbridj.so
cp -R org/bridj/lib/linux_arm64 org/bridj/lib/linux_x64
zip -d bridj.jar org/bridj/lib/linux_arm64
zip bridj.jar org/bridj/lib/linux_x64/libbridj.so

mv bridj.jar /dist/LanguageTool/libs/bridj.jar
13 changes: 7 additions & 6 deletions arm64-workaround/hunspell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if [[ $(dpkg --print-architecture) != "arm64" ]]; then
exit;
fi

echo "Applying arm64 workaround."
echo "Applying arm64 workaround for Hunspell."

# Make `wget` more robust by passing retry flags.
alias wget="wget --retry-connrefused --waitretry=30 --read-timeout=30 --timeout=30 --tries=20"
Expand All @@ -22,8 +22,9 @@ alias wget="wget --retry-connrefused --waitretry=30 --read-timeout=30 --timeout=
##############################
mkdir /hunspell
cd /hunspell
wget http://dl-cdn.alpinelinux.org/alpine/v3.17/main/aarch64/libhunspell-1.7.1-r0.apk
tar --warning=no-unknown-keyword -xzf libhunspell-1.7.1-r0.apk
mkdir -p /hunspell/org/bridj/lib/linux_x64/
mv /hunspell/usr/lib/libhunspell-1.7.so.0.0.1 /hunspell/org/bridj/lib/linux_x64/libhunspell.so
zip /dist/LanguageTool/libs/hunspell.jar org/bridj/lib/linux_x64/libhunspell.so
wget https://dl-cdn.alpinelinux.org/alpine/v3.16/main/aarch64/libhunspell-1.7.0-r1.apk
tar --warning=no-unknown-keyword -xzf libhunspell-1.7.0-r1.apk
mkdir -p /hunspell/org/bridj/lib/linux-aarch64/
mv /hunspell/usr/lib/libhunspell-1.7.so.0.0.1 /hunspell/org/bridj/lib/linux-aarch64/libhunspell.so
cd /hunspell/org/bridj/lib/
zip /dist/LanguageTool/libs/hunspell.jar linux-aarch64/libhunspell.so

0 comments on commit fc12f41

Please sign in to comment.