Skip to content

Commit e6054e0

Browse files
committed
optimize(harmony): enable LTO, strip symbols, and conditionally skip ohpm install on empty packages
1 parent 0ccb4bf commit e6054e0

2 files changed

Lines changed: 50 additions & 10 deletions

File tree

harmony/pushy/src/main/cpp/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,19 @@ if(TARGET rnoh)
6868
target_include_directories(rnoh_pushy PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
6969
target_link_libraries(rnoh_pushy PUBLIC rnoh)
7070
endif()
71+
72+
# Optimize binary size and performance for Release builds
73+
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
74+
# Enable Link Time Optimization (LTO / IPO)
75+
include(CheckIPOSupported)
76+
check_ipo_supported(RESULT ipo_supported OUTPUT error)
77+
if(ipo_supported)
78+
set_property(TARGET rnupdate PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
79+
if(TARGET rnoh_pushy)
80+
set_property(TARGET rnoh_pushy PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
81+
endif()
82+
endif()
83+
84+
# Strip debug symbols and perform garbage collection of unused code sections
85+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -s")
86+
endif()

scripts/build-harmony-har.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,23 +134,30 @@ function buildHar() {
134134
}
135135

136136
if (!skipInstall) {
137-
runCommand(ohpmPath, ['install'], {
138-
cwd: harmonyModuleDir,
139-
env,
140-
label: 'Install Harmony dependencies',
141-
});
137+
if (hasDependencies(harmonyModuleDir)) {
138+
runCommand(ohpmPath, ['install'], {
139+
cwd: harmonyModuleDir,
140+
env,
141+
label: 'Install Harmony dependencies',
142+
});
143+
}
142144

143-
runCommand(ohpmPath, ['install'], {
144-
cwd: wrapperProjectDir,
145-
env,
146-
label: 'Install wrapper project dependencies',
147-
});
145+
if (hasDependencies(wrapperProjectDir)) {
146+
runCommand(ohpmPath, ['install'], {
147+
cwd: wrapperProjectDir,
148+
env,
149+
label: 'Install wrapper project dependencies',
150+
});
151+
}
148152
}
149153

150154
const hvigorArgs = ['assembleHar'];
151155
if (buildMode !== 'debug') {
152156
hvigorArgs.push('-p', `buildMode=${buildMode}`);
153157
}
158+
if (process.env.CI === 'true') {
159+
hvigorArgs.push('--no-daemon');
160+
}
154161

155162
runCommand(hvigorwPath, hvigorArgs, {
156163
cwd: wrapperProjectDir,
@@ -437,3 +444,20 @@ function relativeToProject(filePath) {
437444
function fail(message) {
438445
throw new Error(message);
439446
}
447+
448+
function hasDependencies(dir) {
449+
try {
450+
const pkgPath = path.join(dir, 'oh-package.json5');
451+
if (!fs.existsSync(pkgPath)) {
452+
return false;
453+
}
454+
const pkgContent = fs.readFileSync(pkgPath, 'utf8');
455+
const cleanJson = pkgContent.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '');
456+
const pkg = eval('(' + cleanJson + ')');
457+
const hasDeps = pkg.dependencies && Object.keys(pkg.dependencies).length > 0;
458+
const hasDevDeps = pkg.devDependencies && Object.keys(pkg.devDependencies).length > 0;
459+
return !!(hasDeps || hasDevDeps);
460+
} catch (e) {
461+
return true;
462+
}
463+
}

0 commit comments

Comments
 (0)