Skip to content

Commit 52ec31d

Browse files
committed
Take array of triplet + path when creating Android prebuilds
1 parent 034e66b commit 52ec31d

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ export const platform: Platform<Triplet[], AndroidOpts> = {
122122
return typeof ANDROID_HOME === "string" && fs.existsSync(ANDROID_HOME);
123123
},
124124
async postBuild({ outputPath, triplets }, { autoLink, configuration }) {
125-
const prebuilds: Record<string, Partial<Record<Triplet, string>>> = {};
125+
const prebuilds: Record<
126+
string,
127+
{ triplet: Triplet; libraryPath: string }[]
128+
> = {};
126129

127130
for (const { triplet, buildPath } of triplets) {
128131
assert(fs.existsSync(buildPath), `Expected a directory at ${buildPath}`);
@@ -148,25 +151,23 @@ export const platform: Platform<Triplet[], AndroidOpts> = {
148151
const [artifact] = artifacts;
149152
// Add prebuild entry, creating a new entry if needed
150153
if (!(sharedLibrary.name in prebuilds)) {
151-
prebuilds[sharedLibrary.name] = {};
154+
prebuilds[sharedLibrary.name] = [];
152155
}
153-
prebuilds[sharedLibrary.name][triplet] = path.join(
154-
buildPath,
155-
artifact.path,
156-
);
156+
prebuilds[sharedLibrary.name].push({
157+
triplet,
158+
libraryPath: path.join(buildPath, artifact.path),
159+
});
157160
}
158161

159-
for (const [libraryName, libraryPathByTriplet] of Object.entries(
160-
prebuilds,
161-
)) {
162+
for (const [libraryName, libraries] of Object.entries(prebuilds)) {
162163
const prebuildOutputPath = path.resolve(
163164
outputPath,
164165
`${libraryName}.android.node`,
165166
);
166167
await oraPromise(
167168
createAndroidLibsDirectory({
168169
outputPath: prebuildOutputPath,
169-
libraryPathByTriplet,
170+
libraries,
170171
autoLink,
171172
}),
172173
{

packages/ferric/src/build.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,13 @@ export const buildCommand = new Command("build")
204204
);
205205

206206
if (androidLibraries.length > 0) {
207-
const libraryPathByTriplet = Object.fromEntries(
208-
androidLibraries.map(([target, outputPath]) => [
209-
ANDROID_TRIPLET_PER_TARGET[target],
210-
outputPath,
211-
]),
212-
) as Record<AndroidTriplet, string>;
207+
const libraries = androidLibraries.map(([target, outputPath]) => ({
208+
triplet: ANDROID_TRIPLET_PER_TARGET[target],
209+
libraryPath: outputPath,
210+
}));
213211

214212
const androidLibsFilename = determineAndroidLibsFilename(
215-
Object.values(libraryPathByTriplet),
213+
libraries.map(({ libraryPath }) => libraryPath),
216214
);
217215
const androidLibsOutputPath = path.resolve(
218216
outputPath,
@@ -222,7 +220,7 @@ export const buildCommand = new Command("build")
222220
await oraPromise(
223221
createAndroidLibsDirectory({
224222
outputPath: androidLibsOutputPath,
225-
libraryPathByTriplet,
223+
libraries,
226224
autoLink: true,
227225
}),
228226
{

packages/host/src/node/prebuilds/android.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,24 @@ export function determineAndroidLibsFilename(libraryPaths: string[]) {
3232

3333
type AndroidLibsDirectoryOptions = {
3434
outputPath: string;
35-
libraryPathByTriplet: Partial<Record<AndroidTriplet, string>>;
35+
libraries: { triplet: AndroidTriplet; libraryPath: string }[];
3636
autoLink: boolean;
3737
};
3838

3939
export async function createAndroidLibsDirectory({
4040
outputPath,
41-
libraryPathByTriplet,
41+
libraries,
4242
autoLink,
4343
}: AndroidLibsDirectoryOptions) {
4444
// Delete and recreate any existing output directory
4545
await fs.promises.rm(outputPath, { recursive: true, force: true });
4646
await fs.promises.mkdir(outputPath, { recursive: true });
47-
for (const [triplet, libraryPath] of Object.entries(libraryPathByTriplet)) {
47+
for (const { triplet, libraryPath } of libraries) {
4848
assert(
4949
fs.existsSync(libraryPath),
5050
`Library not found: ${libraryPath} for triplet ${triplet}`,
5151
);
52-
const arch = ANDROID_ARCHITECTURES[triplet as AndroidTriplet];
52+
const arch = ANDROID_ARCHITECTURES[triplet];
5353
const archOutputPath = path.join(outputPath, arch);
5454
await fs.promises.mkdir(archOutputPath, { recursive: true });
5555
// Strip the ".node" extension from the library name

0 commit comments

Comments
 (0)