Skip to content

Commit

Permalink
Merge pull request #1483 from mingxxming/customb
Browse files Browse the repository at this point in the history
暴露isolate给第三方插件做绑定、 android il2cpp 合并v8、传递自定义代码进puerts编译
  • Loading branch information
zombieyang authored Aug 25, 2023
2 parents 8e3e6af + 5253674 commit 2353987
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 12 deletions.
6 changes: 6 additions & 0 deletions unity/Assets/core/upm/Runtime/Src/Default/JsEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ internal TypeManager TypeRegister

internal IntPtr isolate;

public IntPtr Isolate {
get {
return isolate;
}
}

internal ObjectPool objectPool;

private readonly ILoader loader;
Expand Down
6 changes: 6 additions & 0 deletions unity/Assets/core/upm/Runtime/Src/IL2Cpp/JsEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public ILoader GetLoader()
return loader;
}

public IntPtr Isolate {
get {
return PuertsIl2cpp.NativeAPI.GetIsolate(nativeJsEnv);
}
}

public JsEnv(): this(new DefaultLoader(), -1) {}

public JsEnv(ILoader loader, int debugPort = -1)
Expand Down
3 changes: 3 additions & 0 deletions unity/Assets/core/upm/Runtime/Src/IL2Cpp/Native/NativeAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class NativeAPI
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr GetPesapiEnvHolder(IntPtr jsEnv);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr GetIsolate(IntPtr jsEnv);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr CreateCSharpTypeInfo(string name, IntPtr type_id, IntPtr super_type_id, IntPtr klass, bool isValueType, bool isDelegate, string delegateSignature);

Expand Down
8 changes: 8 additions & 0 deletions unity/native_src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ set ( PUERTS_SRC
${PROJECT_SOURCE_DIR}/../../unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.cpp
)

if(DEFINED PUERTS_EXTRA_SRC)
list(APPEND PUERTS_SRC ${PUERTS_EXTRA_SRC})
endif()

if(DEFINED PUERTS_EXTRA_INC)
include_directories(${PUERTS_EXTRA_INC})
endif()

macro(source_group_by_dir proj_dir source_files)
if(MSVC OR APPLE)
get_filename_component(sgbd_cur_dir ${proj_dir} ABSOLUTE)
Expand Down
20 changes: 19 additions & 1 deletion unity/native_src_il2cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ set ( PUERTS_SRC
${PROJECT_SOURCE_DIR}/../../unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.cpp
)

if(DEFINED PUERTS_EXTRA_SRC)
list(APPEND PUERTS_SRC ${PUERTS_EXTRA_SRC})
endif()

if(DEFINED PUERTS_EXTRA_INC)
include_directories(${PUERTS_EXTRA_INC})
endif()

macro(source_group_by_dir proj_dir source_files)
if(MSVC OR APPLE)
Expand Down Expand Up @@ -172,7 +179,18 @@ elseif ( ANDROID )
# "${CMAKE_BINARY_DIR}/libpuerts_il2cpp.so" -o
# "${CMAKE_BINARY_DIR}/libpuerts_il2cpp.stripped.so~"
# COMMENT "Strip debug symbols done on final binary.")

if (JS_ENGINE EQUAL "v8_9.4")
add_custom_command(TARGET puerts_il2cpp POST_BUILD
COMMAND cp ARGS ${BACKEND_LIB_NAMES} ./
COMMAND cp ARGS ${CMAKE_BINARY_DIR}/libpuerts_il2cpp.a ./libpuerts_il2cpp_tmp.a
COMMAND ${ANDROID_TOOLCHAIN_PREFIX}ar ARGS -x libpuerts_il2cpp_tmp.a
COMMAND ${ANDROID_TOOLCHAIN_PREFIX}ar ARGS -rs libwee8.a *.o
COMMAND mv ARGS libwee8.a ${CMAKE_BINARY_DIR}/libpuerts_il2cpp.a
COMMAND rm ARGS libpuerts_il2cpp_tmp.a
COMMAND rm ARGS -f *.o
COMMENT "combine wee8."
)
endif()
elseif ( APPLE )

if ( IOS )
Expand Down
5 changes: 5 additions & 0 deletions unity/native_src_il2cpp/Src/Puerts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,11 @@ V8_EXPORT void SetLogCallback(puerts::LogCallback Log)
puerts::GLogCallback = Log;
}

V8_EXPORT v8::Isolate* GetIsolate(puerts::JSEnv* jsEnv)
{
return jsEnv->MainIsolate;
}

V8_EXPORT pesapi_env_holder GetPesapiEnvHolder(puerts::JSEnv* jsEnv)
{
v8::Isolate* Isolate = jsEnv->MainIsolate;
Expand Down
22 changes: 11 additions & 11 deletions unity/native_src_il2cpp/cmake/backends.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@
"/Inc"
],
"link-libraries": {
"android": {
"armv7": [
"/Lib/Android/armeabi-v7a/libwee8.a"
],
"arm64": [
"/Lib/Android/arm64-v8a/libwee8.a"
],
"x64": [
"/Lib/Android/x64/libwee8.a"
]
},
"win": {
"ia32": [
"/Lib/Win32/wee8.lib"
Expand All @@ -223,17 +234,6 @@
}
},
"copy-libraries": {
"android": {
"armv7": [
"/Lib/Android/armeabi-v7a/libwee8.a"
],
"arm64": [
"/Lib/Android/arm64-v8a/libwee8.a"
],
"x64": [
"/Lib/Android/x64/libwee8.a"
]
},
"ios": {
"arm64": [
"/Lib/iOS/arm64/libwee8.a"
Expand Down

0 comments on commit 2353987

Please sign in to comment.