-
Notifications
You must be signed in to change notification settings - Fork 23
Incremental steps to support Android XR #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
79e03c1
43d677a
22d1f96
435c798
e1d0f2f
dbef5ba
1159300
39f1536
82b17e8
2dd6185
98c40b5
02a7dc5
99c49b1
a40c852
f98247a
7faff92
b3480ca
118450b
4d9eb96
e5e5648
d205c4a
4633fa3
465685e
fcc3ce1
c1fdff4
a54a121
be1baf6
a6a258d
b9aa23c
27eed75
9a268bb
56be206
f378d3f
ed53fd9
863f962
2e467dd
84005c0
9e3cfc9
98e80ef
499ae36
51f1f45
496c67f
403b452
5253492
ebf6950
cfb1af6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ schedules: | |
|
|
||
| variables: | ||
| - name: ndkVersion | ||
| value: 25.2.9519653 | ||
| value: 28.2.13676358 | ||
|
|
||
| jobs: | ||
| # WIN32 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,8 @@ FetchContent_Declare(arcana.cpp | |
| GIT_REPOSITORY https://github.com/microsoft/arcana.cpp.git | ||
| GIT_TAG 1a8a5d6e95413ed14b38a6ac9419048f9a9c8009) | ||
| FetchContent_Declare(AndroidExtensions | ||
| GIT_REPOSITORY https://github.com/bghgary/AndroidExtensions.git | ||
| GIT_TAG 7d88a601fda9892791e7b4e994e375e049615688) | ||
| GIT_REPOSITORY https://github.com/matthargett/AndroidExtensions.git | ||
| GIT_TAG fix-stale-JNI-ref) | ||
| FetchContent_Declare(asio | ||
| GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git | ||
| GIT_TAG f693a3eb7fe72a5f19b975289afc4f437d373d9c) | ||
|
|
@@ -49,6 +49,19 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) | |
|
|
||
| set(CMAKE_CXX_STANDARD 17) | ||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
| if(APPLE) | ||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc") | ||
| if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
| if(NOT DEFINED JSRUNTIMEHOST_NATIVE_SANITIZERS) | ||
| set(JSRUNTIMEHOST_NATIVE_SANITIZERS "address,undefined") | ||
| endif() | ||
| if(JSRUNTIMEHOST_NATIVE_SANITIZERS) | ||
| message(STATUS "macOS sanitizers enabled: ${JSRUNTIMEHOST_NATIVE_SANITIZERS}") | ||
| add_compile_options("-fsanitize=${JSRUNTIMEHOST_NATIVE_SANITIZERS}" "-fno-omit-frame-pointer") | ||
| add_link_options("-fsanitize=${JSRUNTIMEHOST_NATIVE_SANITIZERS}") | ||
| endif() | ||
| endif() | ||
| endif() | ||
|
Comment on lines
+52
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are sanitizers supposed to be part of this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To some degree, yes, because NDK 28 turns some of them on by default and the crash that occurred is what got me started on that sidequest. We could override the NDK 28 default to turn off default sanitizers, and put the fixes into a separate PR. Up to you :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was curious about what could be found with sanitizers so I opened this PR : BabylonJS/BabylonNative#1559 |
||
|
|
||
| # -------------------------------------------------- | ||
| # Options | ||
|
|
@@ -81,6 +94,21 @@ set_property(TARGET arcana PROPERTY FOLDER Dependencies) | |
| if(JSRUNTIMEHOST_POLYFILL_XMLHTTPREQUEST) | ||
| FetchContent_MakeAvailable_With_Message(UrlLib) | ||
| set_property(TARGET UrlLib PROPERTY FOLDER Dependencies) | ||
| if(APPLE) | ||
| FetchContent_GetProperties(UrlLib) | ||
| if(UrlLib_POPULATED) | ||
| target_compile_options(UrlLib PRIVATE -fobjc-arc) | ||
| set(_urllib_objc_sources | ||
| "${UrlLib_SOURCE_DIR}/Source/UrlRequest_Apple.mm" | ||
| "${UrlLib_SOURCE_DIR}/Source/WebSocket_Apple.mm" | ||
| "${UrlLib_SOURCE_DIR}/Source/WebSocket_Apple_ObjC.m") | ||
| foreach(_file IN LISTS _urllib_objc_sources) | ||
| if(EXISTS "${_file}") | ||
| set_source_files_properties("${_file}" PROPERTIES COMPILE_FLAGS "-fobjc-arc") | ||
| endif() | ||
| endforeach() | ||
| endif() | ||
| endif() | ||
|
Comment on lines
+97
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be in UrlLib itself? |
||
| endif() | ||
|
|
||
| if(BABYLON_DEBUG_TRACE) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,12 @@ | |
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| #if defined(__clang__) || defined(__GNUC__) | ||
| #define NAPI_NO_SANITIZE_VPTR __attribute__((no_sanitize("vptr"))) | ||
| #else | ||
| #define NAPI_NO_SANITIZE_VPTR | ||
| #endif | ||
|
|
||
|
Comment on lines
+22
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did these changes come from? We try to ensure these headers match the original unless it is documented as a change. Search for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the commit message, I noted that this should be upstreamed. When they cast the T down to a void* l, it loses RTTI and that trips a sanitizer. I'll add the local comment and submit a PR upstream as well. |
||
| namespace Napi { | ||
|
|
||
| #ifdef NAPI_CPP_CUSTOM_NAMESPACE | ||
|
|
@@ -4496,7 +4502,7 @@ inline napi_value InstanceWrap<T>::WrappedMethod( | |
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| template <typename T> | ||
| inline ObjectWrap<T>::ObjectWrap(const Napi::CallbackInfo& callbackInfo) { | ||
| inline NAPI_NO_SANITIZE_VPTR ObjectWrap<T>::ObjectWrap(const Napi::CallbackInfo& callbackInfo) { | ||
| napi_env env = callbackInfo.Env(); | ||
| napi_value wrapper = callbackInfo.This(); | ||
| napi_status status; | ||
|
|
@@ -4510,7 +4516,7 @@ inline ObjectWrap<T>::ObjectWrap(const Napi::CallbackInfo& callbackInfo) { | |
| } | ||
|
|
||
| template <typename T> | ||
| inline ObjectWrap<T>::~ObjectWrap() { | ||
| inline NAPI_NO_SANITIZE_VPTR ObjectWrap<T>::~ObjectWrap() { | ||
| // If the JS object still exists at this point, remove the finalizer added | ||
| // through `napi_wrap()`. | ||
| if (!IsEmpty() && !_finalized) { | ||
|
|
@@ -4524,7 +4530,7 @@ inline ObjectWrap<T>::~ObjectWrap() { | |
| } | ||
|
|
||
| template <typename T> | ||
| inline T* ObjectWrap<T>::Unwrap(Object wrapper) { | ||
| inline NAPI_NO_SANITIZE_VPTR T* ObjectWrap<T>::Unwrap(Object wrapper) { | ||
| void* unwrapped; | ||
| napi_status status = napi_unwrap(wrapper.Env(), wrapper, &unwrapped); | ||
| NAPI_THROW_IF_FAILED(wrapper.Env(), status, nullptr); | ||
|
|
@@ -6681,4 +6687,6 @@ bool Env::CleanupHook<Hook, Arg>::IsEmpty() const { | |
|
|
||
| } // namespace Napi | ||
|
|
||
| #undef NAPI_NO_SANITIZE_VPTR | ||
|
|
||
| #endif // SRC_NAPI_INL_H_ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,22 @@ struct napi_callback_info__ { | |
| }; | ||
|
|
||
| namespace { | ||
| // Minimal char_traits-like helper for JSChar (unsigned short) to compute string length at compile time | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should just be a simple function. There is no reason for the struct or template. |
||
| template<typename CharT> | ||
| struct jschar_traits; | ||
|
|
||
| template<> | ||
| struct jschar_traits<JSChar> { | ||
| using char_type = JSChar; | ||
|
|
||
| static constexpr size_t length(const char_type* str) noexcept { | ||
| if (!str) return 0; | ||
| const char_type* s = str; | ||
| while (*s) ++s; | ||
| return s - str; | ||
| } | ||
| }; | ||
|
|
||
| class JSString { | ||
| public: | ||
| JSString(const JSString&) = delete; | ||
|
|
@@ -33,7 +49,7 @@ namespace { | |
| } | ||
|
|
||
| JSString(const JSChar* string, size_t length = NAPI_AUTO_LENGTH) | ||
| : _string{JSStringCreateWithCharacters(string, length == NAPI_AUTO_LENGTH ? std::char_traits<JSChar>::length(string) : length)} { | ||
| : _string{JSStringCreateWithCharacters(string, length == NAPI_AUTO_LENGTH ? jschar_traits<JSChar>::length(string) : length)} { | ||
| } | ||
|
|
||
| ~JSString() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "dependencies": { | ||
| "jsc-android": "250231.0.0" | ||
| "jsc-android": "294992.0.0" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,10 @@ | ||
| add_subdirectory(UnitTests) | ||
| set(JSRUNTIMEHOST_OUTPUT_DIR "${CMAKE_BINARY_DIR}/Tests/UnitTests/dist") | ||
| set(JSRUNTIMEHOST_OUTPUT_DIR "${JSRUNTIMEHOST_OUTPUT_DIR}" CACHE INTERNAL "Output directory for bundled unit test scripts") | ||
|
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to set both the cache and local variable? |
||
| file(MAKE_DIRECTORY "${JSRUNTIMEHOST_OUTPUT_DIR}") | ||
| file(REMOVE_RECURSE "${CMAKE_CURRENT_SOURCE_DIR}/UnitTests/dist") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a good idea? Seems dangerous to remove a folder in the source folder when running CMake. |
||
|
|
||
| set(ENV{JSRUNTIMEHOST_BUNDLE_OUTPUT} "${JSRUNTIMEHOST_OUTPUT_DIR}") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, looking at this more. I didn't realize what was happening here. Looks like |
||
| npm(install --silent) | ||
| unset(ENV{JSRUNTIMEHOST_BUNDLE_OUTPUT}) | ||
|
|
||
| add_subdirectory(UnitTests) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,36 +7,56 @@ if (project.hasProperty("jsEngine")) { | |
| jsEngine = project.property("jsEngine") | ||
| } | ||
|
|
||
| def targetApiLevel = 35 | ||
| def requiredNdkVersion = project.findProperty("ndkVersion") ?: "28.2.13676358" | ||
|
|
||
| android { | ||
| namespace 'com.jsruntimehost.unittests' | ||
| compileSdk 33 | ||
| ndkVersion = "23.1.7779620" | ||
| if (project.hasProperty("ndkVersion")) { | ||
| ndkVersion = project.property("ndkVersion") | ||
| } | ||
| compileSdk targetApiLevel | ||
| ndkVersion = requiredNdkVersion | ||
|
|
||
| defaultConfig { | ||
| applicationId "com.jsruntimehost.unittests" | ||
| minSdk 21 | ||
| targetSdk 33 | ||
| targetSdk targetApiLevel | ||
| versionCode 1 | ||
| versionName "1.0" | ||
|
|
||
| testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
|
|
||
| externalNativeBuild { | ||
| cmake { | ||
| arguments ( | ||
| arguments( | ||
| "-DANDROID_STL=c++_shared", | ||
| "-DNAPI_JAVASCRIPT_ENGINE=${jsEngine}", | ||
| "-DJSRUNTIMEHOST_CORE_APPRUNTIME_V8_INSPECTOR=ON" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| if (project.hasProperty("abiFilters")) { | ||
| ndk { | ||
| abiFilters project.getProperty("abiFilters") | ||
| ndk { | ||
| def abiFiltersProp = project.findProperty("abiFilters")?.toString() | ||
| if (abiFiltersProp) { | ||
| def propFilters = abiFiltersProp.split(',').collect { it.trim() }.findAll { !it.isEmpty() } | ||
| if (!propFilters.isEmpty()) { | ||
| abiFilters(*propFilters) | ||
| } | ||
| } else { | ||
| // Prefer injected ABI hints and fall back to a host-aware default | ||
| def requestedAbi = project.findProperty("android.injected.build.abi") ?: System.getenv("ANDROID_ABI") | ||
| def defaultAbis = [] | ||
| if (requestedAbi) { | ||
| defaultAbis = requestedAbi.split(',').collect { it.trim() }.findAll { !it.isEmpty() } | ||
| } | ||
| if (defaultAbis.isEmpty()) { | ||
| def hostArch = (System.getProperty("os.arch") ?: "").toLowerCase() | ||
| if (hostArch.contains("aarch64") || hostArch.contains("arm64")) { | ||
| defaultAbis = ['arm64-v8a'] | ||
| } else { | ||
| defaultAbis = ['arm64-v8a', 'x86_64'] | ||
| } | ||
| } | ||
| abiFilters(*defaultAbis) | ||
|
Comment on lines
+37
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of this change? |
||
| } | ||
| } | ||
| } | ||
|
|
@@ -101,3 +121,6 @@ tasks.configureEach { task -> | |
| task.dependsOn(copyScripts) | ||
| } | ||
| } | ||
|
|
||
| // Note: The Android Gradle Plugin should handle NDK location automatically | ||
| // If you encounter NDK issues, ensure you have NDK 28.2.13676358 installed via SDK Manager | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that this needs to be updated once AndroidExtensions PR is merged