Skip to content

Commit f600866

Browse files
committed
Locate and call NDK strip tool on Android libraries
1 parent 8ec3f41 commit f600866

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

packages/cmake-rn/src/platforms/android.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ function getNdkToolchainPath(ndkPath: string) {
7777
return toolchainPath;
7878
}
7979

80+
function getNdkLlvmBinPath(ndkPath: string) {
81+
const prebuiltPath = path.join(ndkPath, "toolchains/llvm/prebuilt");
82+
const platforms = fs.readdirSync(prebuiltPath);
83+
assert(
84+
platforms.length === 1,
85+
`Expected a single llvm prebuilt toolchain in ${prebuiltPath}`,
86+
);
87+
return path.join(prebuiltPath, platforms[0], "bin");
88+
}
89+
8090
export const platform: Platform<Triplet[], AndroidOpts> = {
8191
id: "android",
8292
name: "Android",
@@ -184,14 +194,14 @@ export const platform: Platform<Triplet[], AndroidOpts> = {
184194
async postBuild(
185195
outputPath,
186196
triplets,
187-
{ autoLink, configuration, target, build },
197+
{ autoLink, configuration, target, build, strip, ndkVersion },
188198
) {
189199
const prebuilds: Record<
190200
string,
191201
{ triplet: Triplet; libraryPath: string }[]
192202
> = {};
193203

194-
for (const { triplet } of triplets) {
204+
for (const { spawn, triplet } of triplets) {
195205
const buildPath = getBuildPath(build, triplet);
196206
assert(fs.existsSync(buildPath), `Expected a directory at ${buildPath}`);
197207
const targets = await cmakeFileApi.readCurrentTargetsDeep(
@@ -220,9 +230,24 @@ export const platform: Platform<Triplet[], AndroidOpts> = {
220230
if (!(sharedLibrary.name in prebuilds)) {
221231
prebuilds[sharedLibrary.name] = [];
222232
}
233+
const libraryPath = path.join(buildPath, artifact.path);
234+
assert(
235+
fs.existsSync(libraryPath),
236+
`Expected built library at ${libraryPath}`,
237+
);
238+
239+
if (strip) {
240+
const llvmBinPath = getNdkLlvmBinPath(getNdkPath(ndkVersion));
241+
const stripToolPath = path.join(llvmBinPath, `llvm-strip`);
242+
assert(
243+
fs.existsSync(stripToolPath),
244+
`Expected llvm-strip to exist at ${stripToolPath}`,
245+
);
246+
await spawn(stripToolPath, [libraryPath]);
247+
}
223248
prebuilds[sharedLibrary.name].push({
224249
triplet,
225-
libraryPath: path.join(buildPath, artifact.path),
250+
libraryPath,
226251
});
227252
}
228253

0 commit comments

Comments
 (0)