diff --git a/.dockerignore b/.dockerignore index 1477462e3..ca8f7ad07 100644 --- a/.dockerignore +++ b/.dockerignore @@ -62,4 +62,4 @@ hs_err_pid* # ------------------------------------------------------------------------------ # Misc -docker/* \ No newline at end of file +**/*.Dockerfile diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml new file mode 100644 index 000000000..b4bec9544 --- /dev/null +++ b/.github/workflows/android_build.yml @@ -0,0 +1,36 @@ +name: Android Build + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths-ignore: + - '**.rst' + - 'docs/**' + push: + paths-ignore: + - '**.rst' + - 'docs/**' + +jobs: + + javet_android: + + name: Javet Android + runs-on: ubuntu-latest + + steps: + + - name: Checkout the code + uses: actions/checkout@v2 + + - name: Build docker image + run: docker build -t javet-android:local -f docker/android/build.Dockerfile . + + - name: Copy the artifact + run: mkdir $PWD/build && docker run --rm -i -v $PWD/build:/output javet-android:local cp -rf /Javet/android/javet-android/build/outputs /output + + - name: Upload the artifact + uses: actions/upload-artifact@v2 + with: + name: javet-android + path: build/outputs/aar/javet*release.aar diff --git a/README.rst b/README.rst index 5658efdc6..ecc3d8d6a 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,9 @@ Javet ===== -|Maven Central| |Discord| |Donate| |Linux Build| +|Maven Central| |Discord| |Donate| + +|Linux Build| |Android Build| .. |Maven Central| image:: https://img.shields.io/maven-central/v/com.caoccao.javet/javet?style=for-the-badge :target: https://search.maven.org/search?q=g:com.caoccao.javet @@ -15,6 +17,9 @@ Javet .. |Linux Build| image:: https://img.shields.io/github/workflow/status/caoccao/Javet/Linux%20Build?label=Linux%20Build&style=for-the-badge :target: https://github.com/caoccao/Javet/actions/workflows/linux_build.yml +.. |Android Build| image:: https://img.shields.io/github/workflow/status/caoccao/Javet/Android%20Build?label=Android%20Build&style=for-the-badge + :target: https://github.com/caoccao/Javet/actions/workflows/android_build.yml + `Javet `_ is Java + V8 (JAVa + V + EighT). It is an awesome way of embedding Node.js and V8 in Java. If you like my work, please **Star** this project. And, you may follow me `@sjtucaocao `_, or visit http://caoccao.blogspot.com/. And the official support channel is at `discord `_. @@ -27,7 +32,8 @@ Major Features ============== * Linux + Mac OS + ️Windows (x86_64) -* Node.js ``v16.11.1`` + V8 ``v9.4.146.19`` +* Android (arm, arm64, x86 and x86_64) +* Node.js ``v16.12.0`` + V8 ``v9.5.172.22`` * Dynamic switch between Node.js and V8 mode (`Which mode do you prefer? `_) * Polyfill V8 mode with `Javenode `_ * V8 API exposure in JVM @@ -52,14 +58,21 @@ Maven com.caoccao.javet javet - 1.0.1 + 1.0.2 com.caoccao.javet javet-macos - 1.0.1 + 1.0.2 + + + + + com.caoccao.javet + javet-android + 1.0.2 Gradle Kotlin DSL @@ -67,16 +80,18 @@ Gradle Kotlin DSL .. code-block:: kotlin - implementation("com.caoccao.javet:javet:1.0.1") // Linux or Windows - implementation("com.caoccao.javet:javet-macos:1.0.1") // Mac OS (x86_64 Only) + implementation("com.caoccao.javet:javet:1.0.2") // Linux or Windows + implementation("com.caoccao.javet:javet-macos:1.0.2") // Mac OS (x86_64 Only) + implementation("com.caoccao.javet:javet-android:1.0.2") // Android (arm, arm64, x86 and x86_64) Gradle Groovy DSL ^^^^^^^^^^^^^^^^^ .. code-block:: groovy - implementation 'com.caoccao.javet:javet:1.0.1' // Linux or Windows - implementation 'com.caoccao.javet:javet-macos:1.0.1' // Mac OS (x86_64 Only) + implementation 'com.caoccao.javet:javet:1.0.2' // Linux or Windows + implementation 'com.caoccao.javet:javet-macos:1.0.2' // Mac OS (x86_64 Only) + implementation 'com.caoccao.javet:javet-android:1.0.2' // Android (arm, arm64, x86 and x86_64) Hello Javet ----------- diff --git a/android/.gitignore b/android/.gitignore new file mode 100644 index 000000000..aa724b770 --- /dev/null +++ b/android/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/android/build.gradle.kts b/android/build.gradle.kts new file mode 100644 index 000000000..a21c18888 --- /dev/null +++ b/android/build.gradle.kts @@ -0,0 +1,30 @@ +/* + * Copyright 2021. caoccao.com Sam Cao + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath("com.android.tools.build:gradle:7.0.3") + } +} + +tasks.register("clean", Delete::class) { + delete(rootProject.buildDir) +} diff --git a/android/gradle.properties b/android/gradle.properties new file mode 100644 index 000000000..52f5917cb --- /dev/null +++ b/android/gradle.properties @@ -0,0 +1,19 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app"s APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true \ No newline at end of file diff --git a/android/gradle/wrapper/gradle-wrapper.jar b/android/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..e708b1c02 Binary files /dev/null and b/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..ae7d2adcd --- /dev/null +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Oct 21 08:49:28 CST 2021 +distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/android/gradlew b/android/gradlew new file mode 100755 index 000000000..4f906e0c8 --- /dev/null +++ b/android/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/android/gradlew.bat b/android/gradlew.bat new file mode 100644 index 000000000..ac1b06f93 --- /dev/null +++ b/android/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/android/javet-android/.gitignore b/android/javet-android/.gitignore new file mode 100644 index 000000000..d717879da --- /dev/null +++ b/android/javet-android/.gitignore @@ -0,0 +1,2 @@ +/build +*.so \ No newline at end of file diff --git a/android/javet-android/build.gradle.kts b/android/javet-android/build.gradle.kts new file mode 100644 index 000000000..6a4970568 --- /dev/null +++ b/android/javet-android/build.gradle.kts @@ -0,0 +1,72 @@ +/* + * Copyright 2021. caoccao.com Sam Cao + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +plugins { + id("com.android.library") +} + +version = "1.0.2" + +android { + compileSdk = 30 + + defaultConfig { + minSdk = 26 + targetSdk = 30 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + getByName("release") { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + setProperty("archivesBaseName", property("archivesBaseName") as String + "-" + version) + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + + sourceSets { + getByName("main") { + java.srcDirs("${projectDir}/../../src/main/java", "src/main/java") + jniLibs.srcDirs("src/main/jniLibs") + } + } +} + +dependencies { + implementation("androidx.appcompat:appcompat:1.3.1") + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.ext:junit:1.1.3") + androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0") +} + +tasks.register(name = "sourceJar") { + from(android.sourceSets["main"].java.srcDirs) + classifier = "sources" +} + +tasks.register(name = "javadocJar") { + from(android.sourceSets["main"].java.srcDirs) + classifier = "javadoc" +} + diff --git a/android/javet-android/consumer-rules.pro b/android/javet-android/consumer-rules.pro new file mode 100644 index 000000000..e69de29bb diff --git a/android/javet-android/proguard-rules.pro b/android/javet-android/proguard-rules.pro new file mode 100644 index 000000000..ff59496d8 --- /dev/null +++ b/android/javet-android/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle.kts. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/android/javet-android/src/androidTest/java/com/caoccao/javet/TestPackage.java b/android/javet-android/src/androidTest/java/com/caoccao/javet/TestPackage.java new file mode 100644 index 000000000..e44fa85ee --- /dev/null +++ b/android/javet-android/src/androidTest/java/com/caoccao/javet/TestPackage.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021. caoccao.com Sam Cao + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.caoccao.javet; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class TestPackage { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.caoccao.javet.test", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/android/javet-android/src/main/AndroidManifest.xml b/android/javet-android/src/main/AndroidManifest.xml new file mode 100644 index 000000000..d6717cb40 --- /dev/null +++ b/android/javet-android/src/main/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/android/javet-android/src/main/java/java/lang/management/ManagementFactory.java b/android/javet-android/src/main/java/java/lang/management/ManagementFactory.java new file mode 100644 index 000000000..afcbff226 --- /dev/null +++ b/android/javet-android/src/main/java/java/lang/management/ManagementFactory.java @@ -0,0 +1,42 @@ +package java.lang.management; + +import com.caoccao.javet.interop.V8Notifier; + +import java.util.ArrayList; +import java.util.List; + +import javax.management.ListenerNotFoundException; +import javax.management.NotificationEmitter; + +public class ManagementFactory { + public static List getMemoryPoolMXBeans() { + return new ArrayList<>(); + } + + public static NotificationEmitter getMemoryMXBean() { + return new NotificationEmitter() { + @Override + public void addNotificationListener(V8Notifier v8Notifier, Object o, Object o1) { + } + + @Override + public void removeNotificationListener(V8Notifier v8Notifier, Object o, Object o1) + throws ListenerNotFoundException { + } + }; + } + + public static RuntimeMXBean getRuntimeMXBean() { + return new RuntimeMXBean() { + @Override + public String getInputArguments() { + return ""; + } + + @Override + public String getName() { + return "1"; + } + }; + } +} diff --git a/android/javet-android/src/main/java/java/lang/management/MemoryNotificationInfo.java b/android/javet-android/src/main/java/java/lang/management/MemoryNotificationInfo.java new file mode 100644 index 000000000..555a59fd6 --- /dev/null +++ b/android/javet-android/src/main/java/java/lang/management/MemoryNotificationInfo.java @@ -0,0 +1,9 @@ +package java.lang.management; + +public class MemoryNotificationInfo { + public static final String MEMORY_THRESHOLD_EXCEEDED = + "java.management.memory.threshold.exceeded"; + + public static final String MEMORY_COLLECTION_THRESHOLD_EXCEEDED = + "java.management.memory.collection.threshold.exceeded"; +} diff --git a/android/javet-android/src/main/java/java/lang/management/MemoryPoolMXBean.java b/android/javet-android/src/main/java/java/lang/management/MemoryPoolMXBean.java new file mode 100644 index 000000000..9a6755b71 --- /dev/null +++ b/android/javet-android/src/main/java/java/lang/management/MemoryPoolMXBean.java @@ -0,0 +1,13 @@ +package java.lang.management; + +public interface MemoryPoolMXBean { + boolean isUsageThresholdSupported(); + + default MemoryType getType() { + return null; + } + + MemoryUsage getUsage(); + + void setUsageThreshold(long memoryUsageThreshold); +} diff --git a/android/javet-android/src/main/java/java/lang/management/MemoryType.java b/android/javet-android/src/main/java/java/lang/management/MemoryType.java new file mode 100644 index 000000000..8a6864b6b --- /dev/null +++ b/android/javet-android/src/main/java/java/lang/management/MemoryType.java @@ -0,0 +1,5 @@ +package java.lang.management; + +public enum MemoryType { + HEAP; +} diff --git a/android/javet-android/src/main/java/java/lang/management/MemoryUsage.java b/android/javet-android/src/main/java/java/lang/management/MemoryUsage.java new file mode 100644 index 000000000..b0e14ab27 --- /dev/null +++ b/android/javet-android/src/main/java/java/lang/management/MemoryUsage.java @@ -0,0 +1,7 @@ +package java.lang.management; + +public class MemoryUsage { + public long getMax() { + return 1; + } +} diff --git a/android/javet-android/src/main/java/java/lang/management/RuntimeMXBean.java b/android/javet-android/src/main/java/java/lang/management/RuntimeMXBean.java new file mode 100644 index 000000000..544fea608 --- /dev/null +++ b/android/javet-android/src/main/java/java/lang/management/RuntimeMXBean.java @@ -0,0 +1,7 @@ +package java.lang.management; + +public interface RuntimeMXBean { + String getInputArguments(); + + String getName(); +} diff --git a/android/javet-android/src/main/java/javax/management/ListenerNotFoundException.java b/android/javet-android/src/main/java/javax/management/ListenerNotFoundException.java new file mode 100644 index 000000000..9ae8fcdf4 --- /dev/null +++ b/android/javet-android/src/main/java/javax/management/ListenerNotFoundException.java @@ -0,0 +1,4 @@ +package javax.management; + +public class ListenerNotFoundException extends Exception { +} diff --git a/android/javet-android/src/main/java/javax/management/Notification.java b/android/javet-android/src/main/java/javax/management/Notification.java new file mode 100644 index 000000000..baea81c91 --- /dev/null +++ b/android/javet-android/src/main/java/javax/management/Notification.java @@ -0,0 +1,7 @@ +package javax.management; + +public class Notification { + public String getType() { + return ""; + } +} diff --git a/android/javet-android/src/main/java/javax/management/NotificationEmitter.java b/android/javet-android/src/main/java/javax/management/NotificationEmitter.java new file mode 100644 index 000000000..948452342 --- /dev/null +++ b/android/javet-android/src/main/java/javax/management/NotificationEmitter.java @@ -0,0 +1,10 @@ +package javax.management; + +import com.caoccao.javet.interop.V8Notifier; + +public interface NotificationEmitter { + void addNotificationListener(V8Notifier v8Notifier, Object o, Object o1); + + void removeNotificationListener(V8Notifier v8Notifier, Object o, Object o1) + throws ListenerNotFoundException; +} diff --git a/android/javet-android/src/main/java/javax/management/NotificationListener.java b/android/javet-android/src/main/java/javax/management/NotificationListener.java new file mode 100644 index 000000000..d0cff4f42 --- /dev/null +++ b/android/javet-android/src/main/java/javax/management/NotificationListener.java @@ -0,0 +1,5 @@ +package javax.management; + +public interface NotificationListener { + void handleNotification(Notification notification, Object handback); +} diff --git a/android/javet-android/src/test/java/com/caoccao/javet/TestDummy.java b/android/javet-android/src/test/java/com/caoccao/javet/TestDummy.java new file mode 100644 index 000000000..3dc3d05f7 --- /dev/null +++ b/android/javet-android/src/test/java/com/caoccao/javet/TestDummy.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021. caoccao.com Sam Cao + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.caoccao.javet; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class TestDummy { + @Test + public void test() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/android/settings.gradle.kts b/android/settings.gradle.kts new file mode 100644 index 000000000..42a247126 --- /dev/null +++ b/android/settings.gradle.kts @@ -0,0 +1,26 @@ +/* + * Copyright 2021. caoccao.com Sam Cao + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} +rootProject.name = "javet" +include(":javet-android") diff --git a/build.gradle.kts b/build.gradle.kts index 36d52e98d..07e9e5bac 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -25,11 +25,7 @@ repositories { } group = "com.caoccao.javet" -version = "1.0.1" - -repositories { - mavenCentral() -} +version = "1.0.2" dependencies { testImplementation("org.eclipse.jetty.websocket:websocket-server:9.4.38.v20210224") diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index ea2ffa0b2..37988dd18 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -34,6 +34,38 @@ if (POLICY CMP0091) cmake_policy(SET CMP0091 NEW) endif() +if(CMAKE_SYSTEM_NAME STREQUAL "Android") + if(NOT DEFINED CMAKE_ANDROID_NDK) + message(FATAL_ERROR "CMAKE_ANDROID_NDK needs to be defined.") + endif() + if(NOT DEFINED CMAKE_ANDROID_ARCH) + message(FATAL_ERROR "CMAKE_ANDROID_ARCH needs to be defined.") + elseif(CMAKE_ANDROID_ARCH STREQUAL "arm64") + set(CMAKE_ANDROID_ARCH_ABI arm64-v8a) + set(JAVET_LIB_ARCH arm64) + elseif(CMAKE_ANDROID_ARCH STREQUAL "arm") + set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a) + set(CMAKE_ANDROID_ARM_NEON 1) + set(JAVET_LIB_ARCH arm) + elseif(CMAKE_ANDROID_ARCH STREQUAL "x86") + set(CMAKE_ANDROID_ARCH_ABI x86) + set(JAVET_LIB_ARCH x86) + elseif(CMAKE_ANDROID_ARCH STREQUAL "x86_64") + set(CMAKE_ANDROID_ARCH_ABI x86_64) + set(JAVET_LIB_ARCH x86_64) + else() + message(FATAL_ERROR "CMAKE_ANDROID_ARCH must be one of arm, arm64, x86, x86_64.") + endif() + # For now, the target ABI version is set to 26 because not all Java code is fully compatible with legacy SDK. + # In the future, more work will be done to lower the target ABI version. + set(CMAKE_SYSTEM_VERSION 26) + set(CMAKE_ANDROID_STL_TYPE c++_static) + set(JAVA_RESOURCES_DIR ${CMAKE_SOURCE_DIR}/../android/javet-android/src/main/jniLibs/${CMAKE_ANDROID_ARCH_ABI}) +else() + set(JAVA_RESOURCES_DIR ${CMAKE_SOURCE_DIR}/../src/main/resources) + set(JAVET_LIB_ARCH x86_64) +endif() + # Initialization project(Javet) aux_source_directory("jni" sourceFiles) @@ -51,10 +83,23 @@ endif() # Preparation if(DEFINED V8_DIR) + if(CMAKE_SYSTEM_NAME STREQUAL "Android") + if(CMAKE_ANDROID_ARCH STREQUAL "arm64") + set(V8_RELEASE_DIR ${V8_DIR}/out.gn/arm64.release) + elseif(CMAKE_ANDROID_ARCH STREQUAL "arm") + set(V8_RELEASE_DIR ${V8_DIR}/out.gn/arm.release) + elseif(CMAKE_ANDROID_ARCH STREQUAL "x86") + set(V8_RELEASE_DIR ${V8_DIR}/out.gn/ia32.release) + elseif(CMAKE_ANDROID_ARCH STREQUAL "x86_64") + set(V8_RELEASE_DIR ${V8_DIR}/out.gn/x64.release) + endif() + else() + set(V8_RELEASE_DIR ${V8_DIR}/out.gn/x64.release) + endif() list(APPEND includeDirs ${V8_DIR} ${V8_DIR}/include - ${V8_DIR}/out.gn/x64.release/gen) + ${V8_RELEASE_DIR}/gen) list(APPEND importLibraries v8_monolith) set(JAVET_LIB_TYPE "v8") endif() @@ -70,7 +115,7 @@ if(DEFINED NODE_DIR) v8_libbase v8_libplatform v8_snapshot v8_zlib zlib) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") list(APPEND importLibraries libnode libuv) - elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") list(APPEND importLibraries node node_text_start uv) elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") list(APPEND importLibraries node uv) @@ -94,7 +139,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") if(DEFINED V8_DIR) foreach(importLibrary ${importLibraries}) - set_target_properties(${importLibrary} PROPERTIES IMPORTED_LOCATION ${V8_DIR}/out.gn/x64.release/obj/${importLibrary}.lib) + set_target_properties(${importLibrary} PROPERTIES IMPORTED_LOCATION ${V8_RELEASE_DIR}/obj/${importLibrary}.lib) endforeach(importLibrary) set_target_properties(v8_monolith PROPERTIES LINK_FLAGS "/WHOLEARCHIVE:v8_monolith.lib") add_library(Javet SHARED ${sourceFiles} "jni/javet_resource_v8.rc") @@ -113,22 +158,22 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") set_property(TARGET Javet APPEND_STRING PROPERTY LINK_FLAGS_RELEASE "") set_property(TARGET Javet PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") target_link_libraries(Javet ${importLibraries}) -elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin") project(JavetStatic) set(JAVET_LIB_PREFIX "javet") - add_definitions(-D__x86_64__) set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_library(Javet SHARED ${sourceFiles}) add_library(JavetStatic STATIC ${sourceFiles}) - if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") set(JAVET_LIB_SYSTEM "linux") + add_definitions(-D__x86_64__) add_definitions(-D__linux__) list(APPEND includeDirs $ENV{JAVA_HOME}/include/linux) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64 ") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 ") if(DEFINED V8_DIR) foreach(importLibrary ${importLibraries}) - set_target_properties(${importLibrary} PROPERTIES IMPORTED_LOCATION ${V8_DIR}/out.gn/x64.release/obj/lib${importLibrary}.a) + set_target_properties(${importLibrary} PROPERTIES IMPORTED_LOCATION ${V8_RELEASE_DIR}/obj/lib${importLibrary}.a) endforeach(importLibrary) target_link_libraries(Javet PUBLIC -Wl,--whole-archive ${importLibraries} -Wl,--no-whole-archive debug "-lrt" optimized "-lrt" "${libgcc}") @@ -152,13 +197,29 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin" # Exported symbol filter is disabled unless production issues call for it. # https://www.gnu.org/software/gnulib/manual/html_node/LD-Version-Scripts.html # target_link_libraries(Javet PUBLIC -Wl,--version-script=${CMAKE_SOURCE_DIR}/jni/version_script.map) - elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + elseif(CMAKE_SYSTEM_NAME STREQUAL "Android" AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + set(JAVET_LIB_SYSTEM "android") + add_definitions(-D__ANDROID__) + list(APPEND includeDirs $ENV{JAVA_HOME}/include/linux) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-unknown-pragmas -Wno-unused-function -Wno-unused-variable -O3 -funroll-loops -ftree-vectorize -ffast-math -fpermissive -fPIC ") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unknown-pragmas -Wno-unused-function -Wno-unused-variable -O3 -funroll-loops -ftree-vectorize -ffast-math -fpermissive -fPIC ") + if(DEFINED V8_DIR) + foreach(importLibrary ${importLibraries}) + set_target_properties(${importLibrary} PROPERTIES IMPORTED_LOCATION ${V8_RELEASE_DIR}/obj/lib${importLibrary}.a) + endforeach(importLibrary) + target_link_libraries(Javet PUBLIC -Wl,--whole-archive ${importLibraries} -Wl,--no-whole-archive + -llog "${libgcc}") + target_link_libraries(JavetStatic PUBLIC -Wl,--whole-archive ${importLibraries} -Wl,--no-whole-archive + -llog "${libgcc}") + endif() + elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") set(JAVET_LIB_SYSTEM "macos") + add_definitions(-D__x86_64__) add_definitions(-D__APPLE__) list(APPEND includeDirs $ENV{JAVA_HOME}/include/darwin) if(DEFINED V8_DIR) foreach(importLibrary ${importLibraries}) - set_target_properties(${importLibrary} PROPERTIES IMPORTED_LOCATION ${V8_DIR}/out.gn/x64.release/obj/lib${importLibrary}.a) + set_target_properties(${importLibrary} PROPERTIES IMPORTED_LOCATION ${V8_RELEASE_DIR}/obj/lib${importLibrary}.a) target_link_libraries(Javet PUBLIC -force_load ${importLibrary}) target_link_libraries(JavetStatic PUBLIC -force_load ${importLibrary}) endforeach(importLibrary) @@ -184,10 +245,11 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin" else() message(FATAL_ERROR "Mac OS arm64 is not supported. Please donate to support the maintainer who will be able to purchase an arm64 device.") endif() - set_target_properties(JavetStatic PROPERTIES OUTPUT_NAME "${JAVET_LIB_PREFIX}-${JAVET_LIB_TYPE}-${JAVET_LIB_SYSTEM}-x86_64.v.${JAVET_VERSION}") + set_target_properties(JavetStatic PROPERTIES OUTPUT_NAME "${JAVET_LIB_PREFIX}-${JAVET_LIB_TYPE}-${JAVET_LIB_SYSTEM}-${JAVET_LIB_ARCH}.v.${JAVET_VERSION}") else() - message(FATAL_ERROR "Linux, Mac OS and Windows x86-64 are the only supported OS.") + message(FATAL_ERROR "Linux (x86-64), Mac OS (x86-64), Windows (x86-64) and Android are the only supported Operating Systems.") endif() -set_target_properties(Javet PROPERTIES OUTPUT_NAME "${JAVET_LIB_PREFIX}-${JAVET_LIB_TYPE}-${JAVET_LIB_SYSTEM}-x86_64.v.${JAVET_VERSION}") +set_target_properties(Javet PROPERTIES OUTPUT_NAME "${JAVET_LIB_PREFIX}-${JAVET_LIB_TYPE}-${JAVET_LIB_SYSTEM}-${JAVET_LIB_ARCH}.v.${JAVET_VERSION}") include_directories(${includeDirs}) +add_custom_command(TARGET Javet POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ "${JAVA_RESOURCES_DIR}/$") diff --git a/cpp/build-android.sh b/cpp/build-android.sh new file mode 100755 index 000000000..7b9a1d78c --- /dev/null +++ b/cpp/build-android.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# Usage for V8: sh build-android.sh -DV8_DIR=${HOME}/v8 -DCMAKE_ANDROID_NDK=${HOME}/android -DCMAKE_ANDROID_ARCH=arm64 +# Usage for Node: sh build-android.sh -DNODE_DIR=${HOME}/node -DCMAKE_ANDROID_NDK=${HOME}/android -DCMAKE_ANDROID_ARCH=arm64 +JAVET_VERSION=1.0.2 +rm -rf build +mkdir build +cd build +mkdir -p ../../build/libs +cmake ../ -DCMAKE_SYSTEM_NAME=Android -DJAVET_VERSION=${JAVET_VERSION} "$@" \ + && make -j4 +if [ $? -eq 0 ]; then + cp -f *.a ../../build/libs + echo Build Completed +else + echo Build Failed +fi +cd ../ + diff --git a/cpp/build-linux.sh b/cpp/build-linux.sh index 61e269c63..b9d1472db 100755 --- a/cpp/build-linux.sh +++ b/cpp/build-linux.sh @@ -2,18 +2,16 @@ # Usage for V8: sh build-linux.sh -DV8_DIR=${HOME}/v8 # Usage for Node: sh build-linux.sh -DNODE_DIR=${HOME}/node -JAVET_VERSION=1.0.1 +JAVET_VERSION=1.0.2 rm -rf build mkdir build cd build -mkdir -p ../../src/main/resources mkdir -p ../../build/libs cmake ../ -DJAVET_VERSION=${JAVET_VERSION} "$@" \ && make -j4 \ - && execstack -c libjavet-*-linux-x86_64.v.${JAVET_VERSION}.so \ - && strip --strip-unneeded -R .note -R .comment libjavet-*-linux-x86_64.v.${JAVET_VERSION}.so + && execstack -c ../../src/main/resources/libjavet-*-linux-x86_64.v.${JAVET_VERSION}.so \ + && strip --strip-unneeded -R .note -R .comment ../../src/main/resources/libjavet-*-linux-x86_64.v.${JAVET_VERSION}.so if [ $? -eq 0 ]; then - cp -f *.so ../../src/main/resources cp -f *.a ../../build/libs echo Build Completed else diff --git a/cpp/build-macos.sh b/cpp/build-macos.sh index 07c81922e..1ad88b524 100755 --- a/cpp/build-macos.sh +++ b/cpp/build-macos.sh @@ -2,16 +2,14 @@ # Usage for V8: sh build-macos.sh -DV8_DIR=${HOME}/v8 # Usage for Node: sh build-macos.sh -DNODE_DIR=${HOME}/node -JAVET_VERSION=1.0.1 +JAVET_VERSION=1.0.2 rm -rf build mkdir build cd build -mkdir -p ../../src/main/resources mkdir -p ../../build/libs cmake ../ -DJAVET_VERSION=${JAVET_VERSION} "$@" \ && make -j4 if [ $? -eq 0 ]; then - cp -f *.dylib ../../src/main/resources cp -f *.a ../../build/libs echo Build Completed else diff --git a/cpp/build-windows.cmd b/cpp/build-windows.cmd index a4c5b802c..ff0406b63 100644 --- a/cpp/build-windows.cmd +++ b/cpp/build-windows.cmd @@ -1,16 +1,14 @@ @echo off REM Usage for V8: build -DV8_DIR=C:\v8 REM Usage for Node: build -DNODE_DIR=C:\node -SET JAVET_VERSION=1.0.1 +SET JAVET_VERSION=1.0.2 rd /s/q build mkdir build cd build -mkdir ..\..\src\main\resources mkdir ..\..\build\libs cmake ..\ -G "Visual Studio 16 2019" -A x64 -DJAVET_VERSION=%JAVET_VERSION% %* ^ && cmake --build . -- /p:CharacterSet=Unicode /p:Configuration=Release /p:Platform=x64 IF %ERRORLEVEL% EQU 0 ( -copy /y Release\*.dll ..\..\src\main\resources copy /y Release\*.lib ..\..\build\libs echo Build Completed ) ELSE ( diff --git a/cpp/jni/com_caoccao_javet_interop_V8Native.cpp b/cpp/jni/com_caoccao_javet_interop_V8Native.cpp index 04807890c..23b682dda 100644 --- a/cpp/jni/com_caoccao_javet_interop_V8Native.cpp +++ b/cpp/jni/com_caoccao_javet_interop_V8Native.cpp @@ -695,19 +695,19 @@ JNIEXPORT jstring JNICALL Java_com_caoccao_javet_interop_V8Native_getSourceCode return nullptr; } -JNIEXPORT jintArray JNICALL Java_com_caoccao_javet_interop_V8Native_getV8HeapSpaceStatistics +JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_getV8HeapSpaceStatistics (JNIEnv* jniEnv, jobject caller, jlong v8RuntimeHandle, jint allocationSpace) { auto v8Runtime = Javet::V8Runtime::FromHandle(v8RuntimeHandle); return Javet::Monitor::GetHeapSpaceStatistics(jniEnv, v8Runtime->v8Isolate, allocationSpace); } -JNIEXPORT jintArray JNICALL Java_com_caoccao_javet_interop_V8Native_getV8HeapStatistics +JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_getV8HeapStatistics (JNIEnv* jniEnv, jobject caller, jlong v8RuntimeHandle) { auto v8Runtime = Javet::V8Runtime::FromHandle(v8RuntimeHandle); return Javet::Monitor::GetHeapStatistics(jniEnv, v8Runtime->v8Isolate); } -JNIEXPORT jintArray JNICALL Java_com_caoccao_javet_interop_V8Native_getV8SharedMemoryStatistics +JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_getV8SharedMemoryStatistics (JNIEnv* jniEnv, jobject caller) { return Javet::Monitor::GetV8SharedMemoryStatistics(jniEnv); } diff --git a/cpp/jni/com_caoccao_javet_interop_V8Native.h b/cpp/jni/com_caoccao_javet_interop_V8Native.h index d24bba3c4..b52fb813f 100644 --- a/cpp/jni/com_caoccao_javet_interop_V8Native.h +++ b/cpp/jni/com_caoccao_javet_interop_V8Native.h @@ -266,25 +266,25 @@ JNIEXPORT jstring JNICALL Java_com_caoccao_javet_interop_V8Native_getSourceCode /* * Class: com_caoccao_javet_interop_V8Native * Method: getV8HeapSpaceStatistics - * Signature: (JI)[I + * Signature: (JI)Ljava/lang/Object; */ -JNIEXPORT jintArray JNICALL Java_com_caoccao_javet_interop_V8Native_getV8HeapSpaceStatistics +JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_getV8HeapSpaceStatistics (JNIEnv *, jobject, jlong, jint); /* * Class: com_caoccao_javet_interop_V8Native * Method: getV8HeapStatistics - * Signature: (J)[I + * Signature: (J)Ljava/lang/Object; */ -JNIEXPORT jintArray JNICALL Java_com_caoccao_javet_interop_V8Native_getV8HeapStatistics +JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_getV8HeapStatistics (JNIEnv *, jobject, jlong); /* * Class: com_caoccao_javet_interop_V8Native * Method: getV8SharedMemoryStatistics - * Signature: ()[I + * Signature: ()Ljava/lang/Object; */ -JNIEXPORT jintArray JNICALL Java_com_caoccao_javet_interop_V8Native_getV8SharedMemoryStatistics +JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_getV8SharedMemoryStatistics (JNIEnv *, jobject); /* diff --git a/cpp/jni/javet_monitor.cpp b/cpp/jni/javet_monitor.cpp index d31f2aa13..bce0b47eb 100644 --- a/cpp/jni/javet_monitor.cpp +++ b/cpp/jni/javet_monitor.cpp @@ -15,60 +15,61 @@ * limitations under the License. */ +#include "javet_converter.h" #include "javet_monitor.h" #include "javet_logging.h" namespace Javet { namespace Monitor { - jintArray GetHeapSpaceStatistics(JNIEnv* jniEnv, v8::Isolate* v8Isolate, jint allocationSpace) { + void Initialize(JNIEnv* jniEnv) { + jclassV8HeapSpaceStatistics = (jclass)jniEnv->NewGlobalRef(jniEnv->FindClass("com/caoccao/javet/interop/monitoring/V8HeapSpaceStatistics")); + jmethodIDV8HeapSpaceStatisticsConstructor = jniEnv->GetMethodID(jclassV8HeapSpaceStatistics, "", "(Ljava/lang/String;IIII)V"); + + jclassV8HeapStatistics = (jclass)jniEnv->NewGlobalRef(jniEnv->FindClass("com/caoccao/javet/interop/monitoring/V8HeapStatistics")); + jmethodIDV8HeapStatisticsConstructor = jniEnv->GetMethodID(jclassV8HeapStatistics, "", "(IIIIIIIIIIIIII)V"); + + jclassV8SharedMemoryStatistics = (jclass)jniEnv->NewGlobalRef(jniEnv->FindClass("com/caoccao/javet/interop/monitoring/V8SharedMemoryStatistics")); + jmethodIDV8SharedMemoryStatisticsConstructor = jniEnv->GetMethodID(jclassV8SharedMemoryStatistics, "", "(III)V"); + } + + jobject GetHeapSpaceStatistics(JNIEnv* jniEnv, v8::Isolate* v8Isolate, jint allocationSpaceIndex) { v8::HeapSpaceStatistics heapSpaceStatistics; - v8Isolate->GetHeapSpaceStatistics(&heapSpaceStatistics, static_cast(allocationSpace)); - jintArray intArray = jniEnv->NewIntArray(4); - jboolean copy = false; - jint* intArrayPointer = jniEnv->GetIntArrayElements(intArray, ©); - intArrayPointer[0] = static_cast(heapSpaceStatistics.physical_space_size()); - intArrayPointer[1] = static_cast(heapSpaceStatistics.space_available_size()); - intArrayPointer[2] = static_cast(heapSpaceStatistics.space_size()); - intArrayPointer[3] = static_cast(heapSpaceStatistics.space_used_size()); - jniEnv->ReleaseIntArrayElements(intArray, intArrayPointer, 0); - return intArray; + v8Isolate->GetHeapSpaceStatistics(&heapSpaceStatistics, static_cast(allocationSpaceIndex)); + return jniEnv->NewObject(jclassV8HeapSpaceStatistics, jmethodIDV8HeapSpaceStatisticsConstructor, + Javet::Converter::ToJavaString(jniEnv, heapSpaceStatistics.space_name()), + static_cast(heapSpaceStatistics.physical_space_size()), + static_cast(heapSpaceStatistics.space_available_size()), + static_cast(heapSpaceStatistics.space_size()), + static_cast(heapSpaceStatistics.space_used_size())); } - jintArray GetHeapStatistics(JNIEnv* jniEnv, v8::Isolate* v8Isolate) { + jobject GetHeapStatistics(JNIEnv* jniEnv, v8::Isolate* v8Isolate) { v8::HeapStatistics heapStatistics; v8Isolate->GetHeapStatistics(&heapStatistics); - jintArray intArray = jniEnv->NewIntArray(14); - jboolean copy = false; - jint* intArrayPointer = jniEnv->GetIntArrayElements(intArray, ©); - intArrayPointer[0] = static_cast(heapStatistics.does_zap_garbage()); - intArrayPointer[1] = static_cast(heapStatistics.external_memory()); - intArrayPointer[2] = static_cast(heapStatistics.heap_size_limit()); - intArrayPointer[3] = static_cast(heapStatistics.malloced_memory()); - intArrayPointer[4] = static_cast(heapStatistics.number_of_detached_contexts()); - intArrayPointer[5] = static_cast(heapStatistics.number_of_native_contexts()); - intArrayPointer[6] = static_cast(heapStatistics.peak_malloced_memory()); - intArrayPointer[7] = static_cast(heapStatistics.total_available_size()); - intArrayPointer[8] = static_cast(heapStatistics.total_global_handles_size()); - intArrayPointer[9] = static_cast(heapStatistics.total_heap_size()); - intArrayPointer[10] = static_cast(heapStatistics.total_heap_size_executable()); - intArrayPointer[11] = static_cast(heapStatistics.total_physical_size()); - intArrayPointer[12] = static_cast(heapStatistics.used_global_handles_size()); - intArrayPointer[13] = static_cast(heapStatistics.used_heap_size()); - jniEnv->ReleaseIntArrayElements(intArray, intArrayPointer, 0); - return intArray; + return jniEnv->NewObject(jclassV8HeapStatistics, jmethodIDV8HeapStatisticsConstructor, + static_cast(heapStatistics.does_zap_garbage()), + static_cast(heapStatistics.external_memory()), + static_cast(heapStatistics.heap_size_limit()), + static_cast(heapStatistics.malloced_memory()), + static_cast(heapStatistics.number_of_detached_contexts()), + static_cast(heapStatistics.number_of_native_contexts()), + static_cast(heapStatistics.peak_malloced_memory()), + static_cast(heapStatistics.total_available_size()), + static_cast(heapStatistics.total_global_handles_size()), + static_cast(heapStatistics.total_heap_size()), + static_cast(heapStatistics.total_heap_size_executable()), + static_cast(heapStatistics.total_physical_size()), + static_cast(heapStatistics.used_global_handles_size()), + static_cast(heapStatistics.used_heap_size())); } - jintArray GetV8SharedMemoryStatistics(JNIEnv* jniEnv) { + jobject GetV8SharedMemoryStatistics(JNIEnv* jniEnv) { v8::SharedMemoryStatistics sharedMemoryStatistics; v8::V8::GetSharedMemoryStatistics(&sharedMemoryStatistics); - jintArray intArray = jniEnv->NewIntArray(3); - jboolean copy = false; - jint* intArrayPointer = jniEnv->GetIntArrayElements(intArray, ©); - intArrayPointer[0] = static_cast(sharedMemoryStatistics.read_only_space_physical_size()); - intArrayPointer[1] = static_cast(sharedMemoryStatistics.read_only_space_size()); - intArrayPointer[2] = static_cast(sharedMemoryStatistics.read_only_space_used_size()); - jniEnv->ReleaseIntArrayElements(intArray, intArrayPointer, 0); - return intArray; + return jniEnv->NewObject(jclassV8SharedMemoryStatistics, jmethodIDV8SharedMemoryStatisticsConstructor, + static_cast(sharedMemoryStatistics.read_only_space_physical_size()), + static_cast(sharedMemoryStatistics.read_only_space_size()), + static_cast(sharedMemoryStatistics.read_only_space_used_size())); } #ifdef ENABLE_MONITOR diff --git a/cpp/jni/javet_monitor.h b/cpp/jni/javet_monitor.h index bf6552d9c..7c1f9b9da 100644 --- a/cpp/jni/javet_monitor.h +++ b/cpp/jni/javet_monitor.h @@ -29,9 +29,20 @@ namespace Javet { namespace Monitor { - jintArray GetHeapSpaceStatistics(JNIEnv* jniEnv, v8::Isolate* v8Isolate, jint allocationSpace); - jintArray GetHeapStatistics(JNIEnv* jniEnv, v8::Isolate* v8Isolate); - jintArray GetV8SharedMemoryStatistics(JNIEnv* jniEnv); + static jclass jclassV8HeapSpaceStatistics; + static jmethodID jmethodIDV8HeapSpaceStatisticsConstructor; + + static jclass jclassV8HeapStatistics; + static jmethodID jmethodIDV8HeapStatisticsConstructor; + + static jclass jclassV8SharedMemoryStatistics; + static jmethodID jmethodIDV8SharedMemoryStatisticsConstructor; + + void Initialize(JNIEnv* jniEnv); + + jobject GetHeapSpaceStatistics(JNIEnv* jniEnv, v8::Isolate* v8Isolate, jint allocationSpaceIndex); + jobject GetHeapStatistics(JNIEnv* jniEnv, v8::Isolate* v8Isolate); + jobject GetV8SharedMemoryStatistics(JNIEnv* jniEnv); #ifdef ENABLE_MONITOR namespace CounterType { diff --git a/cpp/jni/javet_native.cpp b/cpp/jni/javet_native.cpp index 7d75a5454..e068a05f0 100644 --- a/cpp/jni/javet_native.cpp +++ b/cpp/jni/javet_native.cpp @@ -30,7 +30,7 @@ JavaVM* GlobalJavaVM; jint JNI_OnLoad(JavaVM* javaVM, void* reserved) { LOG_INFO("JNI_Onload() begins."); JNIEnv* jniEnv; - if (javaVM->GetEnv((void**)&jniEnv, JNI_VERSION_1_8) != JNI_OK) { + if (javaVM->GetEnv((void**)&jniEnv, SUPPORTED_JNI_VERSION) != JNI_OK) { LOG_ERROR("Failed to call JavaVM.GetEnv()."); return ERROR_JNI_ON_LOAD; } @@ -48,14 +48,15 @@ jint JNI_OnLoad(JavaVM* javaVM, void* reserved) { Javet::Converter::Initialize(jniEnv); Javet::Exceptions::Initialize(jniEnv); Javet::Inspector::Initialize(jniEnv); + Javet::Monitor::Initialize(jniEnv); LOG_INFO("JNI_Onload() ends."); - return JNI_VERSION_1_8; + return SUPPORTED_JNI_VERSION; } void JNI_OnUnload(JavaVM* javaVM, void* reserved) { LOG_INFO("JNI_OnUnload() begins."); JNIEnv* jniEnv; - if (javaVM->GetEnv((void**)&jniEnv, JNI_VERSION_1_8) != JNI_OK) { + if (javaVM->GetEnv((void**)&jniEnv, SUPPORTED_JNI_VERSION) != JNI_OK) { LOG_ERROR("Failed to call JavaVM.GetEnv()."); } if (jniEnv == nullptr) { diff --git a/cpp/jni/javet_native.h b/cpp/jni/javet_native.h index ce5b32f4e..387f87e70 100644 --- a/cpp/jni/javet_native.h +++ b/cpp/jni/javet_native.h @@ -21,9 +21,15 @@ #include "javet_node.h" #include "javet_v8.h" +#ifdef __ANDROID__ +#define SUPPORTED_JNI_VERSION JNI_VERSION_1_6 +#else +#define SUPPORTED_JNI_VERSION JNI_VERSION_1_8 +#endif + #define FETCH_JNI_ENV(javaVMPointer) \ JNIEnv* jniEnv; \ - javaVMPointer->GetEnv((void**)&jniEnv, JNI_VERSION_1_8); \ + javaVMPointer->GetEnv((void**)&jniEnv, SUPPORTED_JNI_VERSION); \ javaVMPointer->AttachCurrentThread((void**)&jniEnv, nullptr); #define RUNTIME_HANDLES_TO_OBJECTS_WITH_SCOPE(v8RuntimeHandle) \ diff --git a/cpp/jni/javet_resource_node.rc b/cpp/jni/javet_resource_node.rc index a871d07bb..66427e1ec 100644 --- a/cpp/jni/javet_resource_node.rc +++ b/cpp/jni/javet_resource_node.rc @@ -61,8 +61,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,1,0 - PRODUCTVERSION 1,0,1,0 + FILEVERSION 1,0,2,0 + PRODUCTVERSION 1,0,2,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -79,12 +79,12 @@ BEGIN BEGIN VALUE "CompanyName", "caoccao.com" VALUE "FileDescription", "caoccao.com" - VALUE "FileVersion", "1.0.1.0" - VALUE "InternalName", "libjavet-node-windows-x86_64.v.1.0.1.dll" + VALUE "FileVersion", "1.0.2.0" + VALUE "InternalName", "libjavet-node-windows-x86_64.v.1.0.2.dll" VALUE "LegalCopyright", "Copyright (C) 2021" - VALUE "OriginalFilename", "libjavet-node-windows-x86_64.v.1.0.1.dll" + VALUE "OriginalFilename", "libjavet-node-windows-x86_64.v.1.0.2.dll" VALUE "ProductName", "Javet Windows" - VALUE "ProductVersion", "1.0.1.0" + VALUE "ProductVersion", "1.0.2.0" END END BLOCK "VarFileInfo" diff --git a/cpp/jni/javet_resource_v8.rc b/cpp/jni/javet_resource_v8.rc index 0cfc9a479..5fa8eb1d0 100644 --- a/cpp/jni/javet_resource_v8.rc +++ b/cpp/jni/javet_resource_v8.rc @@ -61,8 +61,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,1,0 - PRODUCTVERSION 1,0,1,0 + FILEVERSION 1,0,2,0 + PRODUCTVERSION 1,0,2,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -79,12 +79,12 @@ BEGIN BEGIN VALUE "CompanyName", "caoccao.com" VALUE "FileDescription", "caoccao.com" - VALUE "FileVersion", "1.0.1.0" - VALUE "InternalName", "libjavet-v8-windows-x86_64.v.1.0.1.dll" + VALUE "FileVersion", "1.0.2.0" + VALUE "InternalName", "libjavet-v8-windows-x86_64.v.1.0.2.dll" VALUE "LegalCopyright", "Copyright (C) 2021" - VALUE "OriginalFilename", "libjavet-v8-windows-x86_64.v.1.0.1.dll" + VALUE "OriginalFilename", "libjavet-v8-windows-x86_64.v.1.0.2.dll" VALUE "ProductName", "Javet Windows" - VALUE "ProductVersion", "1.0.1.0" + VALUE "ProductVersion", "1.0.2.0" END END BLOCK "VarFileInfo" diff --git a/docker/android/base.Dockerfile b/docker/android/base.Dockerfile new file mode 100644 index 000000000..b50fb362b --- /dev/null +++ b/docker/android/base.Dockerfile @@ -0,0 +1,109 @@ +# Copyright (c) 2021 caoccao.com Sam Cao +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Usage: docker build -t sjtucaocao/javet-android:1.0.2 -f docker/android/base.Dockerfile . + +FROM ubuntu:20.04 +WORKDIR / + +# Update Ubuntu +ENV DEBIAN_FRONTEND=noninteractive +RUN echo Cache V1 +RUN apt-get update +RUN apt-get install --upgrade -qq -y --no-install-recommends git curl wget build-essential software-properties-common patchelf maven sudo zip unzip execstack cmake +RUN apt-get install --upgrade -qq -y --no-install-recommends python3 python python3-pip python3-distutils python3-testresources +RUN apt-get upgrade -y +RUN pip3 install coloredlogs + +# Prepare V8 +RUN mkdir google +WORKDIR /google +RUN git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git +WORKDIR /google/depot_tools +RUN git checkout remotes/origin/main +ENV PATH=/google/depot_tools:$PATH +WORKDIR /google +RUN fetch v8 +WORKDIR /google/v8 +RUN git checkout 9.5.172.22 +RUN sed -i 's/snapcraft/nosnapcraft/g' ./build/install-build-deps.sh +RUN ./build/install-build-deps.sh +RUN sed -i 's/nosnapcraft/snapcraft/g' ./build/install-build-deps.sh +WORKDIR /google +RUN echo 'target_os = ["android"]' >> .gclient +RUN gclient sync +RUN echo V8 preparation is completed. + +# Prepare Android NDK +WORKDIR / +RUN wget https://dl.google.com/android/repository/android-ndk-r21e-linux-x86_64.zip +RUN unzip android-ndk-r21e-linux-x86_64.zip +RUN rm android-ndk-r21e-linux-x86_64.zip + +# Prepare Android SDK +WORKDIR /google/v8/third_party/android_sdk/public/cmdline-tools/latest/bin +RUN yes | ./sdkmanager --licenses +RUN ./sdkmanager "build-tools;30.0.2" "platforms;android-30" +ENV ANDROID_SDK_ROOT=/google/v8/third_party/android_sdk + +# Patch Docker +RUN apt-get install --upgrade -qq -y --no-install-recommends gcc-multilib + +# Build V8 +WORKDIR /google/v8 +COPY ./scripts/python/patch_v8_build.py . +RUN python tools/dev/v8gen.py arm.release -- 'target_os="android"' 'target_cpu="arm"' 'v8_target_cpu="arm"' v8_monolithic=true v8_use_external_startup_data=false is_component_build=false v8_enable_i18n_support=false v8_enable_pointer_compression=false v8_static_library=true symbol_level=0 use_custom_libcxx=false +RUN ninja -C out.gn/arm.release v8_monolith || python3 patch_v8_build.py -p ./ +RUN ninja -C out.gn/arm.release v8_monolith +RUN python tools/dev/v8gen.py arm64.release -- 'target_os="android"' 'target_cpu="arm64"' 'v8_target_cpu="arm64"' v8_monolithic=true v8_use_external_startup_data=false is_component_build=false v8_enable_i18n_support=false v8_enable_pointer_compression=false v8_static_library=true symbol_level=0 use_custom_libcxx=false +RUN ninja -C out.gn/arm64.release v8_monolith || python3 patch_v8_build.py -p ./ +RUN ninja -C out.gn/arm64.release v8_monolith +RUN python tools/dev/v8gen.py ia32.release -- 'target_os="android"' 'target_cpu="x86"' 'v8_target_cpu="x86"' v8_monolithic=true v8_use_external_startup_data=false is_component_build=false v8_enable_i18n_support=false v8_enable_pointer_compression=false v8_static_library=true symbol_level=0 use_custom_libcxx=false +RUN ninja -C out.gn/ia32.release v8_monolith || python3 patch_v8_build.py -p ./ +RUN ninja -C out.gn/ia32.release v8_monolith +RUN python tools/dev/v8gen.py x64.release -- 'target_os="android"' 'target_cpu="x64"' 'v8_target_cpu="x64"' v8_monolithic=true v8_use_external_startup_data=false is_component_build=false v8_enable_i18n_support=false v8_enable_pointer_compression=false v8_static_library=true symbol_level=0 use_custom_libcxx=false +RUN ninja -C out.gn/x64.release v8_monolith || python3 patch_v8_build.py -p ./ +RUN ninja -C out.gn/x64.release v8_monolith +RUN rm patch_v8_build.py +RUN echo V8 build is completed. + +# Prepare Javet Build Environment +RUN apt-get install --upgrade -qq -y --no-install-recommends openjdk-11-jdk +ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 +RUN rm /bin/sh && ln -s /bin/bash /bin/sh +ENV SDKMAN_HOME="/root/.sdkman" +ENV GRADLE_HOME="${SDKMAN_HOME}/candidates/gradle/current" +RUN curl -s https://get.sdkman.io | bash +RUN source ${SDKMAN_HOME}/bin/sdkman-init.sh && sdk install gradle 7.2 +ENV PATH=$GRADLE_HOME/bin:$PATH + +# Shrink +RUN rm -rf ${SDKMAN_HOME}/archives/* +RUN rm -rf ${SDKMAN_HOME}/tmp/* +RUN apt-get clean -y +RUN rm -rf /var/lib/apt/lists/* +WORKDIR / + +# Pre-cache Dependencies +RUN mkdir Javet +WORKDIR /Javet +COPY . . +WORKDIR /Javet/android +RUN gradle dependencies +WORKDIR / +RUN rm -rf /Javet + +# Completed +RUN echo Javet Android build base image is completed. diff --git a/docker/android/build.Dockerfile b/docker/android/build.Dockerfile new file mode 100644 index 000000000..5a4a7cca1 --- /dev/null +++ b/docker/android/build.Dockerfile @@ -0,0 +1,40 @@ +# Copyright (c) 2021 caoccao.com Sam Cao +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Usage: docker build -t javet-android:local -f docker/android/build.Dockerfile . + +FROM sjtucaocao/javet-android:1.0.2 +WORKDIR / + +# Copy Javet +RUN mkdir Javet +WORKDIR /Javet +COPY . . + +# Build JNI +WORKDIR /Javet/cpp +RUN sh ./build-android.sh -DV8_DIR=/google/v8 -DCMAKE_ANDROID_NDK=/android-ndk-r21e -DCMAKE_ANDROID_ARCH=arm +RUN sh ./build-android.sh -DV8_DIR=/google/v8 -DCMAKE_ANDROID_NDK=/android-ndk-r21e -DCMAKE_ANDROID_ARCH=arm64 +RUN sh ./build-android.sh -DV8_DIR=/google/v8 -DCMAKE_ANDROID_NDK=/android-ndk-r21e -DCMAKE_ANDROID_ARCH=x86 +RUN sh ./build-android.sh -DV8_DIR=/google/v8 -DCMAKE_ANDROID_NDK=/android-ndk-r21e -DCMAKE_ANDROID_ARCH=x86_64 + +# Build AAR +WORKDIR /Javet/android +RUN gradle build + +VOLUME /output + +# Completed +RUN echo Javet Android build is completed. diff --git a/docker/linux-x86_64/base.Dockerfile b/docker/linux-x86_64/base.Dockerfile index 22dc0801b..d45b7e643 100644 --- a/docker/linux-x86_64/base.Dockerfile +++ b/docker/linux-x86_64/base.Dockerfile @@ -13,13 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Usage: docker build -t sjtucaocao/javet:1.0.2 -f docker/linux-x86_64/base.Dockerfile . +# Usage: docker build -t sjtucaocao/javet:1.0.2.1 -f docker/linux-x86_64/base.Dockerfile . FROM ubuntu:20.04 WORKDIR / # Update Ubuntu ENV DEBIAN_FRONTEND=noninteractive +RUN echo Cache V1 RUN apt-get update RUN apt-get install --upgrade -qq -y --no-install-recommends git curl wget build-essential software-properties-common patchelf maven sudo zip unzip execstack cmake RUN apt-get install --upgrade -qq -y --no-install-recommends python3 python python3-pip python3-distutils python3-testresources @@ -36,7 +37,7 @@ ENV PATH=/google/depot_tools:$PATH WORKDIR /google RUN fetch v8 WORKDIR /google/v8 -RUN git checkout 9.4.146.19 +RUN git checkout 9.5.172.22 RUN sed -i 's/snapcraft/nosnapcraft/g' ./build/install-build-deps.sh RUN ./build/install-build-deps.sh RUN sed -i 's/nosnapcraft/snapcraft/g' ./build/install-build-deps.sh @@ -47,14 +48,18 @@ RUN echo V8 preparation is completed. # Build V8 WORKDIR /google/v8 RUN python tools/dev/v8gen.py x64.release -- v8_monolithic=true v8_use_external_startup_data=false is_component_build=false v8_enable_i18n_support=false v8_enable_pointer_compression=false v8_static_library=true symbol_level=0 use_custom_libcxx=false +COPY ./scripts/python/patch_v8_build.py . +RUN ninja -C out.gn/x64.release v8_monolith || echo Patch +RUN python3 patch_v8_build.py -p ./ RUN ninja -C out.gn/x64.release v8_monolith +RUN rm patch_v8_build.py RUN echo V8 build is completed. # Prepare Node.js v16 WORKDIR / RUN git clone https://github.com/nodejs/node.git WORKDIR /node -RUN git checkout v16.11.1 +RUN git checkout v16.12.0 RUN echo Node.js preparation is completed. # Build Node.js diff --git a/docker/linux-x86_64/build.Dockerfile b/docker/linux-x86_64/build.Dockerfile index 82df02b6b..6cb93e7fe 100644 --- a/docker/linux-x86_64/build.Dockerfile +++ b/docker/linux-x86_64/build.Dockerfile @@ -15,7 +15,7 @@ # Usage: docker build -t javet:local -f docker/linux-x86_64/build.Dockerfile . -FROM sjtucaocao/javet:1.0.2 +FROM sjtucaocao/javet:1.0.2.1 WORKDIR / # Copy Javet diff --git a/docker/windows-x86_64/base.Dockerfile b/docker/windows-x86_64/base.Dockerfile index 102aa8741..18c9f0c12 100644 --- a/docker/windows-x86_64/base.Dockerfile +++ b/docker/windows-x86_64/base.Dockerfile @@ -60,7 +60,7 @@ ENV DEPOT_TOOLS_WIN_TOOLCHAIN=0 WORKDIR /google RUN fetch v8 WORKDIR /google/v8 -RUN git checkout 9.4.146.19 +RUN git checkout 9.5.172.22 WORKDIR /google RUN gclient sync RUN echo V8 preparation is completed. @@ -103,7 +103,7 @@ RUN powershell -ExecutionPolicy Bypass -c "iex(New-Object Net.WebClient).Downloa RUN choco install -y nasm RUN git clone https://github.com/nodejs/node.git WORKDIR /node -RUN git checkout v16.11.1 +RUN git checkout v16.12.0 RUN echo Node.js preparation is completed. # Build Node.js diff --git a/docs/_static/documentation_options.js b/docs/_static/documentation_options.js index f61f1c025..893e5bf11 100644 --- a/docs/_static/documentation_options.js +++ b/docs/_static/documentation_options.js @@ -1,6 +1,6 @@ var DOCUMENTATION_OPTIONS = { URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), - VERSION: '1.0.1', + VERSION: '1.0.2', LANGUAGE: 'en, zh-CN', COLLAPSE_INDEX: false, BUILDER: 'html', diff --git a/docs/conf.py b/docs/conf.py index b95158657..788ff06c3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,7 @@ author = 'Sam Cao' # The full version, including alpha/beta/rc tags -release = '1.0.1' +release = '1.0.2' # -- General configuration --------------------------------------------------- diff --git a/docs/development/build.html b/docs/development/build.html index 2a97fceda..489323ce1 100644 --- a/docs/development/build.html +++ b/docs/development/build.html @@ -5,7 +5,7 @@ - Build Javet - Javet 1.0.1 documentation + Build Javet - Javet 1.0.2 documentation @@ -124,7 +124,7 @@
@@ -135,7 +135,7 @@
-
- Javet 1.0.1 documentation + Javet 1.0.2 documentation