Skip to content

Commit

Permalink
[unity]添加ns的编译支持
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Sep 24, 2024
1 parent e38fce5 commit e75b2c6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
5 changes: 5 additions & 0 deletions unity/cli/backends.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"x64": [
"/Lib/Linux/libquickjs.a"
]
},
"ns":{
"arm64": [
"/Lib/ns/arm64-v8a/libquickjs.a"
]
}
},
"copy-libraries": {
Expand Down
2 changes: 1 addition & 1 deletion unity/cli/cmd.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ program
.addOption(
new Option("--platform <platform>", "the target platform")
.default("")
.choices(["win", "osx", "linux", "android", "ios", "ohos", "wasm"])
.choices(["win", "osx", "linux", "android", "ios", "ohos", "wasm", "ns"])
)
.addOption(
new Option("--arch <arch>", "the target architecture. 'auto' means build all available archs for the platform and universal binary will be created in osx.")
Expand Down
14 changes: 14 additions & 0 deletions unity/cli/make.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,20 @@ const platformCompileConfig = {
return `${CMAKE_BUILD_PATH}/lib${cmakeAddedLibraryName}.a`;
}
}
},
'ns':{
'arm64': {
outputPluginPath: 'ns/libs/arm64-v8a/',
hook: function (CMAKE_BUILD_PATH, options, cmakeAddedLibraryName, cmakeDArgs) {
const TOOLCHAIN_NAME = 'arm-linux-androideabi-clang';
const NINTENDO_SDK_ROOT_CMAKE=process.env.NINTENDO_SDK_ROOT.replace(/\\/g, '/');

assert.equal(0, exec(`cmake ${cmakeDArgs} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DJS_ENGINE=${options.backend} -DCMAKE_BUILD_TYPE=${options.config} -H. -B${CMAKE_BUILD_PATH} -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Switch -DSWITCH_PLATFORM=1 -DCMAKE_C_COMPILER=${NINTENDO_SDK_ROOT_CMAKE}/Compilers/NX/nx/aarch64/bin/clang.exe -DCMAKE_CXX_COMPILER=${NINTENDO_SDK_ROOT_CMAKE}/Compilers/NX/nx/aarch64/bin/clang++.exe ..`).code)
assert.equal(0, exec(`cmake --build ${CMAKE_BUILD_PATH} --config ${options.config}`).code)

return [`${CMAKE_BUILD_PATH}/lib${cmakeAddedLibraryName}.a`]
}
}
}
}

Expand Down
36 changes: 36 additions & 0 deletions unity/native_src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ if ( APPLE )
PRIVATE "-Wl,-rpath,@loader_path/"
)
endif ()
elseif ( SWITCH_PLATFORM )
add_library(puerts STATIC
${PUERTS_SRC} ${PUERTS_INC}
)
else ()
if (CMAKE_SYSTEM_NAME MATCHES "Emscripten")
add_library(puerts STATIC
Expand Down Expand Up @@ -412,6 +416,38 @@ elseif (UNIX)
endif ()
endif ()

# ref https://github.com/Tencent/puerts/issues/1796 Author:NiceTry12138
if (SWITCH_PLATFORM)
set(NINTENDO_SDK_ROOT $ENV{NINTENDO_SDK_ROOT})
set(NS_INCLUDE "${NINTENDO_SDK_ROOT}/Include")
set(NS_SPECIFIC_INCLUDE "${NINTENDO_SDK_ROOT}/TargetSpecificInclude/NX-Win32-v142")
set(NS_AARCH64 "${NINTENDO_SDK_ROOT}/Compilers/NX/nx/aarch64")

set(NS_INCLUDE_LIST ${NS_INCLUDE}) # 定义搜索路径
list(APPEND NS_INCLUDE_LIST ${NS_SPECIFIC_INCLUDE}) # 添加特殊文件搜索路径
#list(APPEND NS_INCLUDE_LIST "${NS_AARCH64}/include") # 添加 AARCH64 头文件
list(APPEND NS_INCLUDE_LIST "${NINTENDO_SDK_ROOT}/Include/nn/socket") # 网络库相关
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")

#set(NS_LIB_LIST "$${NS_AARCH64}/lib") # 添加 AARCH64 静态库

if(NS_US_ELF)
#list(APPEND NS_INCLUDE_LIST "${NS_AARCH64}/include/aarch64-nintendo-nx-elf")
#list(APPEND NS_LIB_LIST "${NS_AARCH64}/lib/aarch64-nintendo-nx-elf")
else ()
#list(APPEND NS_INCLUDE_LIST "${NS_AARCH64}/include/aarch64-nintendo-nx-nncfi")
#list(APPEND NS_LIB_LIST "${NS_AARCH64}/lib/aarch64-nintendo-nx-nncfi")
endif()

add_compile_options(-fdeclspec)
add_definitions(-DNN_SDK_BUILD_RELEASE)
#add_definitions(-DNN_SDK_BUILD_DEBUG)


include_directories(${NS_INCLUDE_LIST})
link_directories(${NS_LIB_LIST})
endif()

# link
target_link_libraries(puerts
${BACKEND_LIB_NAMES}
Expand Down

0 comments on commit e75b2c6

Please sign in to comment.