-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathandroid.ts
More file actions
58 lines (52 loc) · 1.64 KB
/
android.ts
File metadata and controls
58 lines (52 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { getLibraryName, MAGIC_FILENAME } from "../path-utils";
import {
getLinkedModuleOutputPath,
LinkModuleResult,
type LinkModuleOptions,
} from "./link-modules";
const ANDROID_ARCHITECTURES = [
"arm64-v8a",
"armeabi-v7a",
"x86_64",
"x86",
] as const;
export async function linkAndroidDir({
modulePath,
naming,
}: LinkModuleOptions): Promise<LinkModuleResult> {
const libraryName = getLibraryName(modulePath, naming);
const outputPath = getLinkedModuleOutputPath("android", modulePath, naming);
await fs.promises.rm(outputPath, { recursive: true, force: true });
await fs.promises.cp(modulePath, outputPath, { recursive: true });
for (const arch of ANDROID_ARCHITECTURES) {
const archPath = path.join(outputPath, arch);
if (!fs.existsSync(archPath)) {
// Skip missing architectures
continue;
}
const libraryDirents = await fs.promises.readdir(archPath, {
withFileTypes: true,
});
assert(libraryDirents.length === 1, "Expected exactly one library file");
const [libraryDirent] = libraryDirents;
assert(libraryDirent.isFile(), "Expected a library file");
const libraryPath = path.join(libraryDirent.parentPath, libraryDirent.name);
await fs.promises.rename(
libraryPath,
path.join(archPath, `lib${libraryName}.so`),
);
}
await fs.promises.rm(path.join(outputPath, MAGIC_FILENAME), {
recursive: true,
});
// TODO: Update the DT_NEEDED entry in the .so files
return {
originalPath: modulePath,
outputPath,
libraryName,
skipped: false,
};
}