Skip to content

Commit

Permalink
up ndk and JSRuntimeHost (#1353)
Browse files Browse the repository at this point in the history
  • Loading branch information
CedricGuillemet authored Feb 22, 2024
1 parent 56c3e3d commit 212dea6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 67 deletions.
53 changes: 3 additions & 50 deletions Apps/UnitTests/Android/app/src/main/cpp/JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,10 @@
#include <Android/log.h>
#include <AndroidExtensions/Globals.h>
#include <AndroidExtensions/JavaWrappers.h>
#include <AndroidExtensions/StdoutLogger.h>
#include <atomic>
#include <Shared/Tests.h>

namespace
{
int pfd[2];
int fd_saved[2];
}
void* thread_func(void*)
{
ssize_t rdsz;
char buf[128];
while ((rdsz = read(pfd[0], buf, sizeof buf - 1)) > 0)
{
if (buf[rdsz - 1] == '\n') --rdsz;
buf[rdsz] = 0;
__android_log_write(ANDROID_LOG_DEBUG, "UnitTests", buf);
}
__android_log_write(ANDROID_LOG_DEBUG, "UnitTests", "Logger shutdown");
return 0;
}

void start_logger()
{
pthread_t thr;

// make stdout line-buffered and stderr unbuffered
fd_saved[0] = setvbuf(stdout, 0, _IOLBF, 0);
fd_saved[1] = setvbuf(stderr, 0, _IONBF, 0);

// create the pipe and redirect stdout and stderr
pipe(pfd);
dup2(pfd[1], 1);
dup2(pfd[1], 2);

// spawn the logging thread
if (pthread_create(&thr, 0, thread_func, 0) == -1)
{
return;
}
pthread_detach(thr);
}

void stop_logger()
{
close(pfd[1]);
close(pfd[0]);
setvbuf(stdout, NULL, fd_saved[0], 0);
setvbuf(stderr, NULL, fd_saved[1], 0);
}

extern "C" JNIEXPORT jint JNICALL
Java_com_babylonnative_unittests_Native_javaScriptTests(JNIEnv* env, jclass clazz, jobject context) {
JavaVM* javaVM{};
Expand All @@ -62,11 +15,11 @@ Java_com_babylonnative_unittests_Native_javaScriptTests(JNIEnv* env, jclass claz
throw std::runtime_error{"Failed to get Java VM"};
}

start_logger();
android::StdoutLogger::Start();

android::global::Initialize(javaVM, context);
auto testResult = Run();

stop_logger();
android::StdoutLogger::Stop();
return testResult;
}
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include(FetchContent)
# --------------------------------------------------
FetchContent_Declare(AndroidExtensions
GIT_REPOSITORY /~https://github.com/BabylonJS/AndroidExtensions.git
GIT_TAG 7fd1d3dadacc3f7d85b24bd6783f492cb5fb09b9)
GIT_TAG c84cb305205338b6fd6ff121a0349a810967bbc8)
FetchContent_Declare(arcana.cpp
GIT_REPOSITORY /~https://github.com/microsoft/arcana.cpp.git
GIT_TAG f2757396e80bc4169f2ddb938ce25367a98ffdd0)
Expand All @@ -37,7 +37,7 @@ FetchContent_Declare(ios-cmake
GIT_TAG 4.4.1)
FetchContent_Declare(JsRuntimeHost
GIT_REPOSITORY /~https://github.com/BabylonJS/JsRuntimeHost.git
GIT_TAG 6191427ee29c525f4b81d00b8875cdd1d5e9bf15)
GIT_TAG 02055e8ead071ba04a4cd52d34e7f6a2e86527de)
FetchContent_Declare(OpenXR-MixedReality
GIT_REPOSITORY /~https://github.com/microsoft/OpenXR-MixedReality.git
GIT_TAG 67424511525b96a36847f2a96d689d99e5879503)
Expand Down
18 changes: 10 additions & 8 deletions Install/Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ if(NAPI_JAVASCRIPT_ENGINE STREQUAL "JSI")
set(ADDITIONAL_LIBRARIES "v8jsi.dll.lib")
elseif(NAPI_JAVASCRIPT_ENGINE STREQUAL "V8")
set_cpu_platform_arch()
set(V8_VERSION "8.4.371.15")
set(V8_VERSION "11.9.169.4")
download_nuget()
set(V8_PACKAGE_PATH "${NUGET_PATH}/packages/v8-v142-${CPU_ARCH}.${V8_VERSION}")
set(V8_PACKAGE_PATH "${NUGET_PATH}/packages/v8-v142-${CPU_ARCH}.${V8_VERSION}")
set(V8_REDIST_PACKAGE_PATH "${NUGET_PATH}/packages/v8.redist-v142-${CPU_ARCH}.${V8_VERSION}")
set(V8_PACKAGE_PATH "${NUGET_PATH}/packages/v8-v143-${CPU_ARCH}.${V8_VERSION}")
set(V8_PACKAGE_PATH "${NUGET_PATH}/packages/v8-v143-${CPU_ARCH}.${V8_VERSION}")
set(V8_REDIST_PACKAGE_PATH "${NUGET_PATH}/packages/v8.redist-v143-${CPU_ARCH}.${V8_VERSION}")

add_library(v8_libbase SHARED IMPORTED)
set_target_properties(v8_libbase PROPERTIES IMPORTED_IMPLIB "${V8_PACKAGE_PATH}/lib/Release/v8_libbase.dll.lib")
Expand All @@ -88,12 +88,13 @@ elseif(NAPI_JAVASCRIPT_ENGINE STREQUAL "V8")

set(V8_DIST
"${V8_REDIST_PACKAGE_PATH}/lib/Release/icudtl.dat"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/icui18n.dll"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/third_party_icu_icui18n.dll"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/third_party_abseil-cpp_absl.dll"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/icuuc.dll"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/v8.dll"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/v8_libbase.dll"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/v8_libplatform.dll"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/zlib.dll")
"${V8_REDIST_PACKAGE_PATH}/lib/Release/third_party_zlib.dll")

# only 1 imported location per library -> Adding 1 library per file
foreach(V8FILE ${V8_DIST})
Expand All @@ -108,12 +109,12 @@ elseif(NAPI_JAVASCRIPT_ENGINE STREQUAL "V8")
v8inspector
llhttp
v8::icudtl
v8::icui18n
v8::third_party_icu_icui18n
v8::icuuc
v8::v8
v8::v8_libbase
v8::v8_libplatform
v8::zlib)
v8::third_party_zlib)

if(CPU_ARCH STREQUAL "x64")
# Enable V8 Pointer Compression
Expand All @@ -128,6 +129,7 @@ add_executable(TestInstall ${LOCAL_SCRIPTS} ${NPM_SCRIPTS} ${TEST_INSTALL_APP} $
# for napi
target_compile_definitions(TestInstall PUBLIC NODE_ADDON_API_DISABLE_DEPRECATED)
target_compile_definitions(TestInstall PUBLIC NODE_ADDON_API_DISABLE_NODE_SPECIFIC)
target_compile_definitions(TestInstall PUBLIC NAPI_VERSION=3)

set(INSTALL_LIBS_DIR "${BINARY_DIR}/install/lib")
target_include_directories(TestInstall PRIVATE "${BINARY_DIR}/install/include")
Expand Down
12 changes: 6 additions & 6 deletions Install/Test/packages.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="v8.redist-v142-x64" version="8.4.371.15" targetFramework="native" />
<package id="v8.redist-v142-x86" version="8.4.371.15" targetFramework="native" />
<package id="v8.symbols-v142-x64" version="8.4.371.15" targetFramework="native" />
<package id="v8.symbols-v142-x86" version="8.4.371.15" targetFramework="native" />
<package id="v8-v142-x64" version="8.4.371.15" targetFramework="native" />
<package id="v8-v142-x86" version="8.4.371.15" targetFramework="native" />
<package id="v8.redist-v143-x64" version="11.9.169.4" targetFramework="native" />
<package id="v8.redist-v143-x86" version="11.9.169.4" targetFramework="native" />
<package id="v8.symbols-v143-x64" version="11.9.169.4" targetFramework="native" />
<package id="v8.symbols-v143-x86" version="11.9.169.4" targetFramework="native" />
<package id="v8-v143-x64" version="11.9.169.4" targetFramework="native" />
<package id="v8-v143-x86" version="11.9.169.4" targetFramework="native" />
</packages>
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ variables:
- name: CMAKE_VERSION
value: 3.26.3
- name: NDK_VERSION
value: 21.4.7075529
value: 25.2.9519653
- name: UNITY_BUILD
value: true

Expand Down

0 comments on commit 212dea6

Please sign in to comment.