diff --git a/CMakeLists.txt b/CMakeLists.txt index ffe9c6074..ef16692a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") #{ diff --git a/build.py b/build.py index 5e8c24baf..d33c06210 100644 --- a/build.py +++ b/build.py @@ -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 @@ -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, } @@ -53,6 +55,7 @@ choices=[ c.target_android, c.target_linux, + c.target_alpine, c.target_macos, c.target_win32, ]) diff --git a/build_system/config_alpine.py b/build_system/config_alpine.py new file mode 100644 index 000000000..712408968 --- /dev/null +++ b/build_system/config_alpine.py @@ -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) \ No newline at end of file diff --git a/build_system/constants.py b/build_system/constants.py index 66e949c82..68481d7b6 100644 --- a/build_system/constants.py +++ b/build_system/constants.py @@ -1,6 +1,7 @@ # target platforms target_android = 'android' target_linux = 'linux' +target_alpine = 'alpine' target_macos = 'macos' target_win32 = 'win32' diff --git a/docker/alpine/Dockerfile b/docker/alpine/Dockerfile new file mode 100644 index 000000000..104b075ab --- /dev/null +++ b/docker/alpine/Dockerfile @@ -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 diff --git a/docker/shared/install.alpine.packages.sh b/docker/shared/install.alpine.packages.sh new file mode 100755 index 000000000..bae3cd2c8 --- /dev/null +++ b/docker/shared/install.alpine.packages.sh @@ -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 diff --git a/docker/shared/install.maven.sh b/docker/shared/install.maven.sh index 27dc8eff3..d3758da2d 100755 --- a/docker/shared/install.maven.sh +++ b/docker/shared/install.maven.sh @@ -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