Skip to content

Commit

Permalink
[unity] do not lipo node binary because of github's 100MB limit
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieyang committed Sep 7, 2023
1 parent 7f0604f commit c8710c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
24 changes: 5 additions & 19 deletions unity/cli/make.mts
Original file line number Diff line number Diff line change
Expand Up @@ -217,26 +217,12 @@ async function makeOSXUniveralBinary(cwd: string, copyConfig: string[][]): Promi
const OUTPUT_PATH = cwd + '/../Assets/core/upm/Plugins/macOS';
const cmakeAddedLibraryName = readFileSync(`${cwd}/CMakeLists.txt`, 'utf-8').match(/add_library\((\w*)/)[1];

if (copyConfig.length != 2) throw new Error(`makeOSXUniveralBinary can only combine 2 archs(arm64, x64) now, but got ${copyConfig.length}`);

for (let i = 0; i < copyConfig[0].length; i++) {
for (let j = 0; j < copyConfig[1].length; j++) {
if (basename(copyConfig[0][i]) == basename(copyConfig[1][j])) {
assert.equal(0, exec(`lipo -create -output ${join(OUTPUT_PATH, basename(copyConfig[0][i]))} ${copyConfig[0][i]} ${copyConfig[1][j]}`).code)
copyConfig[0].splice(i, 1); i--;
copyConfig[1].splice(j, 1); j--;
break;
}
}
}

if (copyConfig[0].length != 1 && copyConfig[1].length != 1) throw new Error(`makeOSXUniveralBinary error: too many binary still need to lipo: ${copyConfig}`)
assert.equal(0, exec(`lipo -create -output ${join(OUTPUT_PATH, cmakeAddedLibraryName + '.bundle')} ${copyConfig[0][0]} ${copyConfig[1][0]}`).code)
const arm64binary = cwd + '/../Assets/core/upm/Plugins/' + platformCompileConfig.osx.arm64.outputPluginPath + "/libpuerts.dylib";
const x64binary = cwd + '/../Assets/core/upm/Plugins/' + platformCompileConfig.osx.x64.outputPluginPath + "/puerts.bundle";
assert.equal(0, exec(`lipo -create -output ${join(OUTPUT_PATH, cmakeAddedLibraryName + '.bundle')} ${arm64binary} ${x64binary}`).code)

rm('-rf', cwd + '/../Assets/core/upm/Plugins/' + platformCompileConfig.osx.arm64.outputPluginPath + "/*.dylib");
rm('-rf', cwd + '/../Assets/core/upm/Plugins/' + platformCompileConfig.osx.arm64.outputPluginPath + "/*.bundle");
rm('-rf', cwd + '/../Assets/core/upm/Plugins/' + platformCompileConfig.osx.x64.outputPluginPath + "/*.dylib");
rm('-rf', cwd + '/../Assets/core/upm/Plugins/' + platformCompileConfig.osx.x64.outputPluginPath + "/*.bundle");
rm('-rf', arm64binary);
rm('-rf', x64binary);
}

export default runPuertsMake;
Expand Down
7 changes: 5 additions & 2 deletions unity/native_src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,14 @@ if ( APPLE )
set(CMAKE_OSX_ARCHITECTURES arm64)
endif ()

set(CMAKE_SKIP_RPATH FALSE)
add_link_options(-rpath "@loader_path/")
add_library(puerts SHARED
${PUERTS_SRC} ${PUERTS_INC}
)
target_link_options(
puerts
PRIVATE "-Wl,-rpath,@loader_path/${CMAKE_OSX_ARCHITECTURES}/"
PRIVATE "-Wl,-rpath,@loader_path/"
)
endif ()
else ()
add_library(puerts SHARED
Expand Down

0 comments on commit c8710c8

Please sign in to comment.