Skip to content

Commit

Permalink
Support for Alpine Linux
Browse files Browse the repository at this point in the history
This adds support for building a musl flavored J2V8 version, by providing a Alpine dockerfile to cross-compile J2V8 inside.

Also fixes install.maven.sh in case install.java.sh was not run beforehand (opt folder creation)
  • Loading branch information
kernle32dll committed Jun 21, 2017
1 parent d339049 commit 35703d1
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(J2V8_LIB_PLATFORM_NAME "linux")
set(J2V8_LIB_PREFIX "")
set(J2V8_LIB_ARCH_NAME "x86")

# TODO: This hack could be used to have a different lib filename for alpine, e.g. libj2v8_alpine_x86_64
# However, this would require java code changes to account for the different filename
# Source: https://github.com/dotnet/coreclr/pull/5731/files
#EXEC_PROGRAM(uname ARGS -v OUTPUT_VARIABLE CMAKE_SYSTEM_KERNEL_VERSION)
#string(FIND "${CMAKE_SYSTEM_KERNEL_VERSION}" "Alpine" PAL_SYSTEM_ALPINE)
#if(PAL_SYSTEM_ALPINE EQUAL -1)
# set(J2V8_LIB_PLATFORM_NAME "alpine")
#endif()
#}
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
#{
Expand Down
3 changes: 3 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from build_system.config_android import android_config
from build_system.config_linux import linux_config
from build_system.config_alpine import alpine_config
from build_system.config_macos import macos_config
from build_system.config_win32 import win32_config

Expand All @@ -34,6 +35,7 @@
avail_targets = {
c.target_android: android_config,
c.target_linux: linux_config,
c.target_alpine: alpine_config,
c.target_macos: macos_config,
c.target_win32: win32_config,
}
Expand All @@ -53,6 +55,7 @@
choices=[
c.target_android,
c.target_linux,
c.target_alpine,
c.target_macos,
c.target_win32,
])
Expand Down
25 changes: 25 additions & 0 deletions build_system/config_alpine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import constants as c
from cross_build import BuildStep, PlatformConfig
from docker_build import DockerBuildSystem
import config_linux as lc

alpine_config = PlatformConfig(c.target_alpine, [c.arch_x86, c.arch_x64], DockerBuildSystem)

alpine_config.cross_config(BuildStep(
name="cross-compile-host",
platform=c.target_alpine,
host_cwd="$CWD/docker",
build_cwd="/j2v8",
))

alpine_config.set_file_abis({
c.arch_x64: "x86_64",
c.arch_x86: "x86"
})

# Alpine build steps are the same as for linux - just the build environment is different
alpine_config.build_step(c.build_node_js, lc.build_node_js)
alpine_config.build_step(c.build_j2v8_cmake, lc.build_j2v8_cmake)
alpine_config.build_step(c.build_j2v8_jni, lc.build_j2v8_jni)
alpine_config.build_step(c.build_j2v8_java, lc.build_j2v8_java)
alpine_config.build_step(c.build_j2v8_junit, lc.build_j2v8_junit)
1 change: 1 addition & 0 deletions build_system/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# target platforms
target_android = 'android'
target_linux = 'linux'
target_alpine = 'alpine'
target_macos = 'macos'
target_win32 = 'win32'

Expand Down
23 changes: 23 additions & 0 deletions docker/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM library/openjdk:8u131-alpine

RUN mkdir -p /temp/docker/shared/
WORKDIR /temp/docker/shared/

# NOTE: copy shared scripts and run them separately
# this helps when changing commands only in a single script,
# since it will not requrie rebuilding all docker image layers
# but just the ones that were affected

COPY ./shared/install.alpine.packages.sh /temp/docker/shared
RUN ./install.alpine.packages.sh

COPY ./shared/install.maven.sh /temp/docker/shared
RUN ./install.maven.sh
ENV PATH "$PATH:/opt/apache-maven-3.5.0/bin"

# download the most critical maven dependencies for the build beforehand
COPY ./shared/pom.xml /temp
WORKDIR /temp
RUN export J2V8_PLATFORM_NAME=temp && \
export J2V8_ARCH_NAME=temp && \
mvn verify -DskipTests || true
16 changes: 16 additions & 0 deletions docker/shared/install.alpine.packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

echo "Preparing Alpine packages..."
apk add --update --no-cache \
git \
unzip \
gcc \
g++ \
curl \
file \
python \
make \
cmake \
wget \
supervisor \
bash \
linux-headers
1 change: 1 addition & 0 deletions docker/shared/install.maven.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

echo "Preparing Maven..."
curl http://www-eu.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz -O
mkdir -p /opt
tar xzvf apache-maven-3.5.0-bin.tar.gz -C /opt/
chmod -R 777 /opt/apache-maven-3.5.0

0 comments on commit 35703d1

Please sign in to comment.