ReviewOS

also looking at this

craft-native/craft

perf(android): ship libcraft.so without its DWARF, and keep the DWARF for symbols

#217
Merged glennmichael123 wants to merge fix/android-strip-libcraft into main
6 files +235 -14
scripts/mobile-e2e/android.tsmodified+16-2
Changes to scripts/mobile-e2e/android.ts
@@ -1,8 +1,8 @@
11import type { LegOutcome, RunnerOptions } from './types'
2import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
2import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
33import { join } from 'node:path'
44import { init } from '../../packages/android/src/index'
5import { androidDeclines, awaitedNeeds, DISMISS_SHARE_MENU, evaluateRun, hasTerminated, runtimePermissionGranted, shareMenuInFront } from './protocol'
5import { androidDeclines, awaitedNeeds, DISMISS_SHARE_MENU, elfSectionNames, evaluateRun, hasTerminated, runtimePermissionGranted, shareMenuInFront, strippedLibraryProblems } from './protocol'
66import { command, driverPage, waitForFile } from './support'
77
88/**
@@ -321,6 +321,20 @@ export async function runAndroid(options: RunnerOptions): Promise<LegOutcome[]>
321321 )
322322 }
323323
324 // What every generated app will ship, checked before any leg uses it. The
325 // runtime leg asserts the library loads and answers; this asserts it is the
326 // release shape #204 settled on, stripped with its DWARF kept beside it,
327 // because a regression there costs every APK megabytes and fails no case.
328 const symbolsPath = join(runtimeDir, '..', 'android-symbols', 'x86_64', 'libcraft.so.debug')
329 const libraryProblems = strippedLibraryProblems(
330 elfSectionNames(new Uint8Array(readFileSync(abi))),
331 existsSync(symbolsPath) ? elfSectionNames(new Uint8Array(readFileSync(symbolsPath))) : null,
332 )
333 if (libraryProblems.length)
334 throw new Error(`${abi}: ${libraryProblems.join('; ')}`)
335 const megabytes = (path: string) => `${(statSync(path).size / 1024 / 1024).toFixed(2)} MB`
336 console.log(`x86_64/libcraft.so ships at ${megabytes(abi)}; its symbols are ${megabytes(symbolsPath)} beside it`)
337
324338 const outcomes: LegOutcome[] = []
325339 for (const leg of legs(runtimeDir)) {
326340 try {