Skip to content

Commit bcfea97

Browse files
committed
Support building multiple addons
1 parent b6a5766 commit bcfea97

File tree

4 files changed

+195
-199
lines changed

4 files changed

+195
-199
lines changed

.changeset/chilly-trains-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cmake-rn": minor
3+
---
4+
5+
Add support for building projects declaring multiple shared object libraries into Node-API addons

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

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ export const platform: Platform<Triplet[], AndroidOpts> = {
164164
await Promise.all(
165165
triplets.map(async ({ triplet, spawn }) => {
166166
const buildPath = getBuildPath(build, triplet, configuration);
167-
const outputPath = path.join(buildPath, "out");
168167
// We want to use the CMake File API to query information later
169168
await cmakeFileApi.createSharedStatelessQuery(
170169
buildPath,
@@ -189,7 +188,6 @@ export const platform: Platform<Triplet[], AndroidOpts> = {
189188
...commonDefinitions,
190189
{
191190
// "CPACK_SYSTEM_NAME": `Android-${architecture}`,
192-
CMAKE_LIBRARY_OUTPUT_DIRECTORY: outputPath,
193191
ANDROID_ABI: ANDROID_ARCHITECTURES[triplet],
194192
},
195193
]),
@@ -232,41 +230,39 @@ export const platform: Platform<Triplet[], AndroidOpts> = {
232230
type === "SHARED_LIBRARY" &&
233231
(target.length === 0 || target.includes(name)),
234232
);
235-
assert.equal(
236-
sharedLibraries.length,
237-
1,
238-
"Expected exactly one shared library",
239-
);
240-
const [sharedLibrary] = sharedLibraries;
241-
const { artifacts } = sharedLibrary;
242-
assert(
243-
artifacts && artifacts.length === 1,
244-
"Expected exactly one artifact",
245-
);
246-
const [artifact] = artifacts;
247-
// Add prebuild entry, creating a new entry if needed
248-
if (!(sharedLibrary.name in prebuilds)) {
249-
prebuilds[sharedLibrary.name] = [];
250-
}
251-
const libraryPath = path.join(buildPath, artifact.path);
252-
assert(
253-
fs.existsSync(libraryPath),
254-
`Expected built library at ${libraryPath}`,
255-
);
233+
await Promise.all(
234+
sharedLibraries.map(async (sharedLibrary) => {
235+
const { artifacts } = sharedLibrary;
236+
assert(
237+
artifacts && artifacts.length === 1,
238+
"Expected exactly one artifact",
239+
);
240+
const [artifact] = artifacts;
241+
// Add prebuild entry, creating a new entry if needed
242+
if (!(sharedLibrary.name in prebuilds)) {
243+
prebuilds[sharedLibrary.name] = [];
244+
}
245+
const libraryPath = path.join(buildPath, artifact.path);
246+
assert(
247+
fs.existsSync(libraryPath),
248+
`Expected built library at ${libraryPath}`,
249+
);
256250

257-
if (strip) {
258-
const llvmBinPath = getNdkLlvmBinPath(getNdkPath(ndkVersion));
259-
const stripToolPath = path.join(llvmBinPath, `llvm-strip`);
260-
assert(
261-
fs.existsSync(stripToolPath),
262-
`Expected llvm-strip to exist at ${stripToolPath}`,
263-
);
264-
await spawn(stripToolPath, [libraryPath]);
265-
}
266-
prebuilds[sharedLibrary.name].push({
267-
triplet,
268-
libraryPath,
269-
});
251+
if (strip) {
252+
const llvmBinPath = getNdkLlvmBinPath(getNdkPath(ndkVersion));
253+
const stripToolPath = path.join(llvmBinPath, `llvm-strip`);
254+
assert(
255+
fs.existsSync(stripToolPath),
256+
`Expected llvm-strip to exist at ${stripToolPath}`,
257+
);
258+
await spawn(stripToolPath, [libraryPath]);
259+
}
260+
prebuilds[sharedLibrary.name].push({
261+
triplet,
262+
libraryPath,
263+
});
264+
}),
265+
);
270266
}
271267

272268
for (const [libraryName, libraries] of Object.entries(prebuilds)) {

0 commit comments

Comments
 (0)