peachsim 0.1.2610 → 0.1.2612
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +2 -2
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +5 -5
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +3 -3
- package/dist-lib/bundle-channel.cjs +1213 -684
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +3 -3
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +3 -3
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +2 -2
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +7 -7
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +5 -5
- package/dist-lib/detox/index.cjs +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/esm-chunks/{acorn-L2SFCOHG.mjs → acorn-QO4N4OBM.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-MK4DOEDN.mjs → chunk-252KNQUF.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-ZZB2LFYV.mjs → chunk-3ZTDI2MF.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-WZHEW7Z7.mjs → chunk-4JTACUL3.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-WBQFHIGS.mjs → chunk-6VWQEI2U.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-FP447MCW.mjs → chunk-6ZP7JWNX.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-X74N3K5N.mjs → chunk-7OAXAYW7.mjs} +4 -4
- package/dist-lib/esm-chunks/{chunk-XN74REO2.mjs → chunk-BWWPWGZW.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-W3LNUIUA.mjs → chunk-GRDRKYB5.mjs} +6 -6
- package/dist-lib/esm-chunks/{chunk-VDLPNJ6P.mjs → chunk-HEPU5HEE.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-2LJTZ2KG.mjs → chunk-HHQHP6NX.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-MJP4WOSX.mjs → chunk-HQGPI7FM.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-RN73P2DY.mjs → chunk-LDYLSTVC.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-YLUD2UET.mjs → chunk-O5VA25UA.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-CUBTZPSZ.mjs → chunk-PDKX5WGD.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-KTAGV5U6.mjs → chunk-PPDXMRAA.mjs} +6 -6
- package/dist-lib/esm-chunks/{chunk-EYSNLE5V.mjs → chunk-THHH7IPK.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-N3M5KT33.mjs → chunk-UGPX2JTI.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-73NIGS7D.mjs → chunk-VAIU3RSQ.mjs} +14 -14
- package/dist-lib/esm-chunks/{chunk-N7XU2WWO.mjs → chunk-VM5QGKMB.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-HMTSU22Q.mjs → chunk-WMQA6U5H.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-EU5WMP5O.mjs → chunk-WTTIS3AY.mjs} +2 -2
- package/dist-lib/esm-chunks/{chunk-YVLXYLNV.mjs → chunk-XPVBWRWY.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-42NDD4R7.mjs → chunk-YAK7RNDV.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-YYGSN3BN.mjs → chunk-ZRJG25JE.mjs} +3 -3
- package/dist-lib/esm-chunks/{metro-layout-parser-VDPXJ7LW.mjs → metro-layout-parser-UUA4AJ2Q.mjs} +3 -3
- package/dist-lib/esm-chunks/{swift-package-prebuilt-HRPDLN2P.mjs → swift-package-prebuilt-EVJIROFN.mjs} +12 -12
- package/dist-lib/esm-chunks/{swift-sdk-app-module-5DOGMU3M.mjs → swift-sdk-app-module-M5TKMPU6.mjs} +16 -16
- package/dist-lib/esm-chunks/{swift-sdk-image-W3UU4H4L.mjs → swift-sdk-image-4FST3VAH.mjs} +16 -16
- package/dist-lib/esm-chunks/{swift-sdk-image-producer-OJWD6ZOH.mjs → swift-sdk-image-producer-4DUU7RUD.mjs} +5 -5
- package/dist-lib/expo-swift-bundle.cjs +11 -6
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +7 -7
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +1544 -1015
- package/dist-lib/host/fetch-proxy-handler.cjs +2 -2
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +676 -171
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +3 -3
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +3 -3
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +4 -4
- package/dist-lib/native-app-identity-project.cjs +1 -1
- package/dist-lib/native-app-identity-project.mjs +15 -15
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +6 -6
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +3 -3
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.mjs +2 -2
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +3 -3
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +85 -85
- package/dist-lib/public-origins-lib.json +76 -65
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +2 -2
- package/dist-lib/reap-browser.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +8 -8
- package/dist-lib/skills.cjs +2100 -1632
- package/dist-lib/swift-compile.cjs +1 -1
- package/dist-lib/swift-compile.mjs +12 -12
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +3 -3
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +6 -6
- package/dist-lib/swift-svg-raster.cjs +1 -1
- package/dist-lib/swift-svg-raster.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
- package/dist-lib/vendor/acorn.cjs +1 -1
- package/dist-lib/vendor/magic-string.cjs +1 -1
- package/dist-lib/vendor/stream-json.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
- package/dist-lib/vendor/sucrase.cjs +1 -1
- package/dist-lib/vendor/terser.cjs +1 -1
- package/dist-lib/vendor/valibot.cjs +1 -1
- package/dist-lib/vendor/ws.cjs +1 -1
- package/dist-lib/vendor/zod.cjs +1 -1
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +3 -3
- package/package.json +1 -1
- package/src/android-gradle-sources.ts +97 -2
- package/src/androidGradleContract.ts +11 -0
- package/src/gitignore.ts +9 -4
- package/src/kotlin-app.ts +37 -4
- package/src/kotlin-gradle-library-plan.ts +142 -0
- package/src/kotlin-host.ts +32 -3
- package/src/kotlin-library-sources.ts +320 -0
- package/src/kotlin-maven-sources.ts +0 -7
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { compileKotlinLibrarySources } from './kotlin-library-sources'
|
|
5
|
+
import { readMavenSourcesArchive } from './kotlin-maven-sources'
|
|
6
|
+
import type {
|
|
7
|
+
AndroidGradleDependencySource,
|
|
8
|
+
AndroidGradleModule,
|
|
9
|
+
} from './androidGradleContract'
|
|
10
|
+
import type { KotlinToolchainInstallation } from './kotlinSdkContract'
|
|
11
|
+
|
|
12
|
+
export interface KotlinGradleLibrary {
|
|
13
|
+
coordinate: string
|
|
14
|
+
archive: string
|
|
15
|
+
jars: readonly string[]
|
|
16
|
+
dependencies: readonly string[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface KotlinGradleLibraries {
|
|
20
|
+
libraries: KotlinGradleLibrary[]
|
|
21
|
+
classpath: string[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function kotlinGradleLibraryPlan(input: {
|
|
25
|
+
compile: readonly AndroidGradleModule[]
|
|
26
|
+
runtime: readonly AndroidGradleModule[]
|
|
27
|
+
sourceArchives: readonly AndroidGradleDependencySource[]
|
|
28
|
+
roots: readonly string[]
|
|
29
|
+
supplied: (coordinate: string) => boolean
|
|
30
|
+
}): KotlinGradleLibrary[] {
|
|
31
|
+
const compile = new Map(input.compile.map((module) => [module.coordinate, module]))
|
|
32
|
+
const runtime = new Map(input.runtime.map((module) => [module.coordinate, module]))
|
|
33
|
+
const archives = new Map(
|
|
34
|
+
input.sourceArchives.map((row) => [
|
|
35
|
+
[row.group, row.name, row.version].join(':'),
|
|
36
|
+
row.archive,
|
|
37
|
+
]),
|
|
38
|
+
)
|
|
39
|
+
const active = new Set<string>()
|
|
40
|
+
const visited = new Map<string, readonly string[]>()
|
|
41
|
+
const name = (coordinate: string) => coordinate.slice(0, coordinate.lastIndexOf(':'))
|
|
42
|
+
const runtimeSelection = new Map(
|
|
43
|
+
input.runtime.map(({ coordinate }) => [name(coordinate), coordinate]),
|
|
44
|
+
)
|
|
45
|
+
const result: KotlinGradleLibrary[] = []
|
|
46
|
+
const visit = (requested: string): readonly string[] => {
|
|
47
|
+
const coordinate = runtimeSelection.get(name(requested)) ?? requested
|
|
48
|
+
if (input.supplied(coordinate)) return []
|
|
49
|
+
const previous = visited.get(coordinate)
|
|
50
|
+
if (previous) return previous
|
|
51
|
+
if (active.has(coordinate))
|
|
52
|
+
throw new Error('Android dependencies form a cycle at ' + coordinate)
|
|
53
|
+
active.add(coordinate)
|
|
54
|
+
const compileModule = compile.get(coordinate)
|
|
55
|
+
const runtimeModule = runtime.get(coordinate)
|
|
56
|
+
if (!compileModule && !runtimeModule)
|
|
57
|
+
throw new Error('Gradle did not resolve Android module ' + coordinate)
|
|
58
|
+
const edges = new Set([
|
|
59
|
+
...(compileModule?.dependencies ?? []),
|
|
60
|
+
...(runtimeModule?.dependencies ?? []),
|
|
61
|
+
])
|
|
62
|
+
const dependencies = [...new Set([...edges].flatMap(visit))]
|
|
63
|
+
const jars = compileModule?.jars.length
|
|
64
|
+
? compileModule.jars
|
|
65
|
+
: (runtimeModule?.jars ?? [])
|
|
66
|
+
let closure: readonly string[] = dependencies
|
|
67
|
+
if (jars.length) {
|
|
68
|
+
const archive = archives.get(coordinate)
|
|
69
|
+
if (!archive)
|
|
70
|
+
throw new Error('Gradle did not resolve a source archive for ' + coordinate)
|
|
71
|
+
result.push({ coordinate, archive, jars, dependencies })
|
|
72
|
+
closure = [...dependencies, coordinate]
|
|
73
|
+
}
|
|
74
|
+
active.delete(coordinate)
|
|
75
|
+
visited.set(coordinate, closure)
|
|
76
|
+
return closure
|
|
77
|
+
}
|
|
78
|
+
input.roots.forEach(visit)
|
|
79
|
+
return result
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function compileKotlinGradleLibraries(input: {
|
|
83
|
+
plan: KotlinGradleLibraries
|
|
84
|
+
ready: KotlinToolchainInstallation
|
|
85
|
+
sdkRoot: string
|
|
86
|
+
libraries: readonly string[]
|
|
87
|
+
language: string
|
|
88
|
+
output: string
|
|
89
|
+
}): Promise<string[]> {
|
|
90
|
+
const compiled = new Map<string, { klib: string; jars: readonly string[] }>()
|
|
91
|
+
for (const library of input.plan.libraries) {
|
|
92
|
+
const { java: archiveJava, kotlin } = await readMavenSourcesArchive(library.archive)
|
|
93
|
+
const java = archiveJava.filter((file) => path.basename(file) !== 'module-info.java')
|
|
94
|
+
const dependencies = library.dependencies.map((name) => {
|
|
95
|
+
const dependency = compiled.get(name)
|
|
96
|
+
if (!dependency) throw new Error(`${library.coordinate} depends on missing ${name}`)
|
|
97
|
+
return dependency
|
|
98
|
+
})
|
|
99
|
+
const classpath = [
|
|
100
|
+
...new Set([
|
|
101
|
+
...library.jars,
|
|
102
|
+
...dependencies.flatMap(({ jars }) => jars),
|
|
103
|
+
...input.plan.classpath,
|
|
104
|
+
]),
|
|
105
|
+
]
|
|
106
|
+
const name = library.coordinate.replace(/[^a-zA-Z0-9._-]/g, '-')
|
|
107
|
+
const suffix = createHash('sha256')
|
|
108
|
+
.update(library.coordinate)
|
|
109
|
+
.digest('hex')
|
|
110
|
+
.slice(0, 12)
|
|
111
|
+
const klib = path.join(input.output, `${name}-${suffix}.klib`)
|
|
112
|
+
const kotlinJvmAbi =
|
|
113
|
+
java.length && kotlin.length && library.jars.length === 1
|
|
114
|
+
? library.jars[0]
|
|
115
|
+
: undefined
|
|
116
|
+
const abiPairs = java.length
|
|
117
|
+
? dependencies.flatMap(({ klib, jars }) =>
|
|
118
|
+
jars.length === 1 ? [{ klib, jar: jars[0] }] : [],
|
|
119
|
+
)
|
|
120
|
+
: []
|
|
121
|
+
const dependencyJvmAbi = abiPairs.length ? `${klib}.json` : undefined
|
|
122
|
+
if (dependencyJvmAbi) {
|
|
123
|
+
fs.mkdirSync(input.output, { recursive: true })
|
|
124
|
+
fs.writeFileSync(dependencyJvmAbi, JSON.stringify(abiPairs))
|
|
125
|
+
}
|
|
126
|
+
await compileKotlinLibrarySources({
|
|
127
|
+
ready: input.ready,
|
|
128
|
+
sdkRoot: input.sdkRoot,
|
|
129
|
+
libraries: input.libraries,
|
|
130
|
+
source: { kind: 'files', java, kotlin },
|
|
131
|
+
javaClasspath: classpath,
|
|
132
|
+
release: '17',
|
|
133
|
+
kotlinJvmAbi,
|
|
134
|
+
dependencyJvmAbi,
|
|
135
|
+
kotlinLanguage: input.language,
|
|
136
|
+
dependencies: dependencies.map(({ klib }) => klib),
|
|
137
|
+
output: klib,
|
|
138
|
+
})
|
|
139
|
+
compiled.set(library.coordinate, { klib, jars: library.jars })
|
|
140
|
+
}
|
|
141
|
+
return [...compiled.values()].map(({ klib }) => klib)
|
|
142
|
+
}
|
package/src/kotlin-host.ts
CHANGED
|
@@ -27,6 +27,10 @@ import {
|
|
|
27
27
|
readJavaModuleSpecs,
|
|
28
28
|
} from './java-module-abi'
|
|
29
29
|
import { kotlinCoroutineDispatcher, kotlinNodeDetection } from './kotlin-browser-seams'
|
|
30
|
+
import {
|
|
31
|
+
compileKotlinGradleLibraries,
|
|
32
|
+
type KotlinGradleLibraries,
|
|
33
|
+
} from './kotlin-gradle-library-plan'
|
|
30
34
|
import { kotlinInstanceSource } from './kotlin-instance-source'
|
|
31
35
|
import { installKotlinSdkArchive } from './kotlin-sdk'
|
|
32
36
|
import { kotlinSkikoSource } from './kotlin-skiko-source'
|
|
@@ -924,6 +928,7 @@ export async function kotlinAppArtifact(
|
|
|
924
928
|
kotlinOptIns: app.kotlinOptIns,
|
|
925
929
|
sources: app.sources,
|
|
926
930
|
javaSpecs: app.javaSources,
|
|
931
|
+
gradleLibraries: app.gradleLibraries,
|
|
927
932
|
generated,
|
|
928
933
|
sdkProfile: 'app',
|
|
929
934
|
usesCompose: true,
|
|
@@ -1217,6 +1222,7 @@ async function compileKotlin(
|
|
|
1217
1222
|
kotlinOptIns?: readonly string[]
|
|
1218
1223
|
sources: string[]
|
|
1219
1224
|
javaSpecs?: string[]
|
|
1225
|
+
gradleLibraries?: KotlinGradleLibraries
|
|
1220
1226
|
generated: Record<string, string>
|
|
1221
1227
|
// the app source a generated file rewrites, which its diagnostics name
|
|
1222
1228
|
origins?: Record<string, string>
|
|
@@ -1247,6 +1253,7 @@ async function compileKotlin(
|
|
|
1247
1253
|
usesSerialization = false,
|
|
1248
1254
|
viewModels,
|
|
1249
1255
|
javaSpecs = [],
|
|
1256
|
+
gradleLibraries,
|
|
1250
1257
|
} = input
|
|
1251
1258
|
const sdk = await loadKotlinSdk(moduleRoot, toolchain)
|
|
1252
1259
|
const plugin = path.join(sdk.root, 'plugin.jar')
|
|
@@ -1304,6 +1311,16 @@ async function compileKotlin(
|
|
|
1304
1311
|
)
|
|
1305
1312
|
for (const { file, bytes } of inputs)
|
|
1306
1313
|
digest.update(path.relative(root, file)).update('\0').update(bytes).update('\0')
|
|
1314
|
+
if (gradleLibraries) {
|
|
1315
|
+
digest.update(JSON.stringify(gradleLibraries))
|
|
1316
|
+
const files = new Set([
|
|
1317
|
+
...gradleLibraries.classpath,
|
|
1318
|
+
...gradleLibraries.libraries.flatMap(({ archive, jars }) => [archive, ...jars]),
|
|
1319
|
+
])
|
|
1320
|
+
for (const file of files) {
|
|
1321
|
+
digest.update(createHash('sha256').update(fs.readFileSync(file)).digest())
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1307
1324
|
if (viewModels) digest.update(viewModels.toolClass)
|
|
1308
1325
|
for (const [name, text] of Object.entries(generated))
|
|
1309
1326
|
digest.update(`${name}\0${text}\0`)
|
|
@@ -1337,7 +1354,7 @@ async function compileKotlin(
|
|
|
1337
1354
|
fs.writeFileSync(target, bytes)
|
|
1338
1355
|
return { file, target }
|
|
1339
1356
|
})
|
|
1340
|
-
const common = [
|
|
1357
|
+
const common = () => [
|
|
1341
1358
|
// the full upstream Compose graph exceeds kotlinc's 512 mib default heap.
|
|
1342
1359
|
'-J-Xmx2g',
|
|
1343
1360
|
'-Xallow-kotlin-package',
|
|
@@ -1349,7 +1366,7 @@ async function compileKotlin(
|
|
|
1349
1366
|
run(
|
|
1350
1367
|
kotlinc,
|
|
1351
1368
|
[
|
|
1352
|
-
...common,
|
|
1369
|
+
...common(),
|
|
1353
1370
|
`-Xplugin=${plugin}`,
|
|
1354
1371
|
`-Xfriend-modules=${[sdkLibrary, ...(javaLibrary ? [javaLibrary] : [])].join(path.delimiter)}`,
|
|
1355
1372
|
...(usesCompose
|
|
@@ -1379,6 +1396,18 @@ async function compileKotlin(
|
|
|
1379
1396
|
{ maxBuffer: 16 * 1024 * 1024 },
|
|
1380
1397
|
)
|
|
1381
1398
|
try {
|
|
1399
|
+
if (gradleLibraries) {
|
|
1400
|
+
libraries.push(
|
|
1401
|
+
...(await compileKotlinGradleLibraries({
|
|
1402
|
+
plan: gradleLibraries,
|
|
1403
|
+
ready,
|
|
1404
|
+
sdkRoot: sdk.root,
|
|
1405
|
+
libraries: libraries.filter((library) => library !== javaLibrary),
|
|
1406
|
+
language,
|
|
1407
|
+
output: path.join(work, 'gradle-libraries'),
|
|
1408
|
+
})),
|
|
1409
|
+
)
|
|
1410
|
+
}
|
|
1382
1411
|
if (java)
|
|
1383
1412
|
await compileJavaModuleAbi({
|
|
1384
1413
|
specs: java,
|
|
@@ -1416,7 +1445,7 @@ async function compileKotlin(
|
|
|
1416
1445
|
await run(
|
|
1417
1446
|
kotlinc,
|
|
1418
1447
|
[
|
|
1419
|
-
...common,
|
|
1448
|
+
...common(),
|
|
1420
1449
|
'-nowarn',
|
|
1421
1450
|
'-Xpartial-linkage-loglevel=error',
|
|
1422
1451
|
`-Xinclude=${path.join(work, 'klib')}`,
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { spawn, type StdioOptions } from 'node:child_process'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { isRecord } from './is-record'
|
|
5
|
+
import { kotlinToolCommand, runKotlinTool } from './kotlin-toolchain'
|
|
6
|
+
import type { KotlinToolchainInstallation } from './kotlinSdkContract'
|
|
7
|
+
|
|
8
|
+
function runCompiler(
|
|
9
|
+
file: string,
|
|
10
|
+
args: readonly string[],
|
|
11
|
+
options: { stdio: StdioOptions; env?: NodeJS.ProcessEnv },
|
|
12
|
+
operation: string,
|
|
13
|
+
): Promise<void> {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const child = spawn(file, args, options)
|
|
16
|
+
child.once('error', reject)
|
|
17
|
+
child.once('close', (code, signal) => {
|
|
18
|
+
if (code === 0) resolve()
|
|
19
|
+
else reject(new Error(operation + ' stopped with ' + (code ?? signal)))
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type KotlinLibrarySource =
|
|
25
|
+
| { kind: 'files'; java: readonly string[]; kotlin: readonly string[] }
|
|
26
|
+
| { kind: 'resources'; archive: string }
|
|
27
|
+
|
|
28
|
+
function kotlinFragmentFlags(
|
|
29
|
+
filename: string,
|
|
30
|
+
kotlinSources: readonly string[],
|
|
31
|
+
translatedSources: readonly string[],
|
|
32
|
+
): string[] {
|
|
33
|
+
const input: unknown = JSON.parse(fs.readFileSync(filename, 'utf8'))
|
|
34
|
+
if (!Array.isArray(input) || !input.length)
|
|
35
|
+
throw new Error('Kotlin fragments must be a nonempty array')
|
|
36
|
+
const fragments = input.map(
|
|
37
|
+
(
|
|
38
|
+
fragment: unknown,
|
|
39
|
+
): {
|
|
40
|
+
name: string
|
|
41
|
+
sources: string[]
|
|
42
|
+
refines: string[]
|
|
43
|
+
java: boolean
|
|
44
|
+
} => {
|
|
45
|
+
if (
|
|
46
|
+
!isRecord(fragment) ||
|
|
47
|
+
typeof fragment.name !== 'string' ||
|
|
48
|
+
!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(fragment.name) ||
|
|
49
|
+
!Array.isArray(fragment.sources) ||
|
|
50
|
+
!fragment.sources.every((source: unknown) => typeof source === 'string') ||
|
|
51
|
+
!Array.isArray(fragment.refines) ||
|
|
52
|
+
!fragment.refines.every((parent: unknown) => typeof parent === 'string') ||
|
|
53
|
+
(fragment.java !== undefined && typeof fragment.java !== 'boolean')
|
|
54
|
+
)
|
|
55
|
+
throw new Error(
|
|
56
|
+
'Each Kotlin fragment needs a name, source paths and refined fragments',
|
|
57
|
+
)
|
|
58
|
+
return {
|
|
59
|
+
name: fragment.name,
|
|
60
|
+
sources: fragment.sources.map((source: string) => path.resolve(source)),
|
|
61
|
+
refines: fragment.refines,
|
|
62
|
+
java: fragment.java === true,
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
)
|
|
66
|
+
const names = new Set(fragments.map(({ name }) => name))
|
|
67
|
+
const refined = new Set(fragments.flatMap(({ refines }) => refines))
|
|
68
|
+
const [platform, ...otherPlatforms] = [...names].filter((name) => !refined.has(name))
|
|
69
|
+
const javaFragments = fragments.filter(({ java }) => java)
|
|
70
|
+
if (
|
|
71
|
+
names.size !== fragments.length ||
|
|
72
|
+
[...refined].some((name) => !names.has(name)) ||
|
|
73
|
+
!platform ||
|
|
74
|
+
otherPlatforms.length ||
|
|
75
|
+
javaFragments.length > 1
|
|
76
|
+
)
|
|
77
|
+
throw new Error(
|
|
78
|
+
'Kotlin fragments need unique names, known parents, one platform fragment and at most one Java source fragment',
|
|
79
|
+
)
|
|
80
|
+
const sources = fragments.flatMap(({ sources }) => sources)
|
|
81
|
+
const selected = new Set(kotlinSources)
|
|
82
|
+
if (
|
|
83
|
+
sources.length !== selected.size ||
|
|
84
|
+
new Set(sources).size !== sources.length ||
|
|
85
|
+
sources.some((source) => !selected.has(source)) ||
|
|
86
|
+
[...sources, ...translatedSources].some((source) => source.includes(','))
|
|
87
|
+
)
|
|
88
|
+
throw new Error('Each Kotlin library source must belong to exactly one fragment')
|
|
89
|
+
const mappings = fragments.flatMap(({ name, sources }) =>
|
|
90
|
+
sources.map((source) => `${name}:${source}`),
|
|
91
|
+
)
|
|
92
|
+
const javaFragment = javaFragments[0]?.name ?? platform
|
|
93
|
+
mappings.push(...translatedSources.map((source) => `${javaFragment}:${source}`))
|
|
94
|
+
const edges = fragments.flatMap(({ name, refines }) =>
|
|
95
|
+
refines.map((parent) => `${name}:${parent}`),
|
|
96
|
+
)
|
|
97
|
+
return [
|
|
98
|
+
'-Xmulti-platform',
|
|
99
|
+
`-Xfragments=${[...names].join(',')}`,
|
|
100
|
+
...(edges.length ? [`-Xfragment-refines=${edges.join(',')}`] : []),
|
|
101
|
+
`-Xfragment-sources=${mappings.join(',')}`,
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export async function compileKotlinLibrarySources(input: {
|
|
106
|
+
ready: KotlinToolchainInstallation
|
|
107
|
+
sdkRoot: string
|
|
108
|
+
libraries: readonly string[]
|
|
109
|
+
source: KotlinLibrarySource
|
|
110
|
+
javaClasspath: readonly string[]
|
|
111
|
+
kotlinJvmAbi?: string
|
|
112
|
+
dependencyJvmAbi?: string
|
|
113
|
+
release: string
|
|
114
|
+
processorPath?: string
|
|
115
|
+
kotlinLanguage?: string
|
|
116
|
+
kotlinOptIns?: readonly string[]
|
|
117
|
+
commonSources?: readonly string[]
|
|
118
|
+
kotlinFragments?: string
|
|
119
|
+
dependencies: readonly string[]
|
|
120
|
+
output: string
|
|
121
|
+
}): Promise<void> {
|
|
122
|
+
const output = path.resolve(input.output)
|
|
123
|
+
const name = path.basename(output, '.klib')
|
|
124
|
+
if (
|
|
125
|
+
!name ||
|
|
126
|
+
!output.endsWith('.klib') ||
|
|
127
|
+
(input.source.kind === 'files' &&
|
|
128
|
+
!input.source.java.length &&
|
|
129
|
+
!input.source.kotlin.length)
|
|
130
|
+
)
|
|
131
|
+
throw new Error('Android library compilation requires sources and a KLIB output')
|
|
132
|
+
const { ready, sdkRoot, libraries } = input
|
|
133
|
+
const parent = path.dirname(output)
|
|
134
|
+
fs.mkdirSync(parent, { recursive: true })
|
|
135
|
+
const work = fs.mkdtempSync(path.join(parent, '.android-library-'))
|
|
136
|
+
try {
|
|
137
|
+
const compileLibraries = [...libraries, ...input.dependencies]
|
|
138
|
+
let javaSources: readonly string[]
|
|
139
|
+
if (input.source.kind === 'resources') {
|
|
140
|
+
const generated = path.join(work, 'resources')
|
|
141
|
+
await runKotlinTool(
|
|
142
|
+
ready,
|
|
143
|
+
sdkRoot,
|
|
144
|
+
'dev.peach.tools.platform.AndroidResourceClassesKt',
|
|
145
|
+
[path.resolve(input.source.archive), generated],
|
|
146
|
+
)
|
|
147
|
+
javaSources = fs
|
|
148
|
+
.readdirSync(generated, { recursive: true, encoding: 'utf8' })
|
|
149
|
+
.filter((file) => file.endsWith('.java'))
|
|
150
|
+
.sort()
|
|
151
|
+
.map((file) => path.join(generated, file))
|
|
152
|
+
} else {
|
|
153
|
+
javaSources = input.source.java
|
|
154
|
+
}
|
|
155
|
+
const kotlinSources =
|
|
156
|
+
input.source.kind === 'files'
|
|
157
|
+
? input.source.kotlin.map((file) => path.resolve(file))
|
|
158
|
+
: []
|
|
159
|
+
const commonSources = (input.commonSources ?? []).map((file) => path.resolve(file))
|
|
160
|
+
if (commonSources.length && input.kotlinFragments)
|
|
161
|
+
throw new Error('Choose common sources or a Kotlin fragment graph')
|
|
162
|
+
if (commonSources.some((file) => file.includes(',') || !kotlinSources.includes(file)))
|
|
163
|
+
throw new Error('Common Kotlin sources must be included in the library source list')
|
|
164
|
+
const kotlinJvmAbi = input.kotlinJvmAbi && path.resolve(input.kotlinJvmAbi)
|
|
165
|
+
if (
|
|
166
|
+
kotlinJvmAbi &&
|
|
167
|
+
(!javaSources.length ||
|
|
168
|
+
!kotlinSources.length ||
|
|
169
|
+
!kotlinJvmAbi.endsWith('.jar') ||
|
|
170
|
+
!input.javaClasspath.some((file) => path.resolve(file) === kotlinJvmAbi))
|
|
171
|
+
)
|
|
172
|
+
throw new Error(
|
|
173
|
+
'The Kotlin JVM ABI must be a JAR on the mixed library’s Java classpath',
|
|
174
|
+
)
|
|
175
|
+
const dependencyAbiFlags: string[] = []
|
|
176
|
+
if (input.dependencyJvmAbi) {
|
|
177
|
+
const dependencyPaths = new Set(
|
|
178
|
+
input.dependencies.map((file) => path.resolve(file)),
|
|
179
|
+
)
|
|
180
|
+
const classpathPaths = new Set(
|
|
181
|
+
input.javaClasspath.map((file) => path.resolve(file)),
|
|
182
|
+
)
|
|
183
|
+
const value: unknown = JSON.parse(fs.readFileSync(input.dependencyJvmAbi, 'utf8'))
|
|
184
|
+
if (!Array.isArray(value) || !value.length || !javaSources.length)
|
|
185
|
+
throw new Error(
|
|
186
|
+
'Dependency JVM ABIs require Java sources and a nonempty array of KLIB/JAR pairs',
|
|
187
|
+
)
|
|
188
|
+
for (const pair of value) {
|
|
189
|
+
if (
|
|
190
|
+
!isRecord(pair) ||
|
|
191
|
+
typeof pair.klib !== 'string' ||
|
|
192
|
+
typeof pair.jar !== 'string'
|
|
193
|
+
)
|
|
194
|
+
throw new Error('Each dependency JVM ABI requires a klib and a jar path')
|
|
195
|
+
const klib = path.resolve(pair.klib)
|
|
196
|
+
const jar = path.resolve(pair.jar)
|
|
197
|
+
if (
|
|
198
|
+
!klib.endsWith('.klib') ||
|
|
199
|
+
!dependencyPaths.has(klib) ||
|
|
200
|
+
!jar.endsWith('.jar') ||
|
|
201
|
+
!classpathPaths.has(jar) ||
|
|
202
|
+
jar === kotlinJvmAbi
|
|
203
|
+
)
|
|
204
|
+
throw new Error(
|
|
205
|
+
'Dependency JVM ABI pairs must refer to a dependency KLIB and its Java classpath JAR',
|
|
206
|
+
)
|
|
207
|
+
dependencyAbiFlags.push('--dependency-jvm-abi', klib, jar)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
let translatedSources: string[] = []
|
|
211
|
+
if (javaSources.length) {
|
|
212
|
+
const platform = path.join(work, 'platform.txt')
|
|
213
|
+
const members = kotlinToolCommand(
|
|
214
|
+
ready,
|
|
215
|
+
sdkRoot,
|
|
216
|
+
'dev.peach.tools.platform.KlibClassesKt',
|
|
217
|
+
[
|
|
218
|
+
...compileLibraries.map((file) => path.resolve(file)),
|
|
219
|
+
...(kotlinJvmAbi ? ['--same-library-jvm-abi', kotlinJvmAbi] : []),
|
|
220
|
+
...dependencyAbiFlags,
|
|
221
|
+
],
|
|
222
|
+
)
|
|
223
|
+
const fd = fs.openSync(platform, 'w')
|
|
224
|
+
try {
|
|
225
|
+
await runCompiler(
|
|
226
|
+
members.file,
|
|
227
|
+
members.args,
|
|
228
|
+
{ stdio: ['ignore', fd, 'inherit'] },
|
|
229
|
+
'Android library ' + name + ' metadata read',
|
|
230
|
+
)
|
|
231
|
+
} finally {
|
|
232
|
+
fs.closeSync(fd)
|
|
233
|
+
}
|
|
234
|
+
const sourceList = path.join(work, 'sources.txt')
|
|
235
|
+
fs.writeFileSync(
|
|
236
|
+
sourceList,
|
|
237
|
+
javaSources.map((file) => path.resolve(file)).join('\n'),
|
|
238
|
+
)
|
|
239
|
+
const translated = path.join(work, 'translated')
|
|
240
|
+
const diagnostics = await runKotlinTool(
|
|
241
|
+
ready,
|
|
242
|
+
sdkRoot,
|
|
243
|
+
'dev.peach.tools.java.JavaTranslatorKt',
|
|
244
|
+
[
|
|
245
|
+
'--target',
|
|
246
|
+
'wasm',
|
|
247
|
+
'--release',
|
|
248
|
+
input.release,
|
|
249
|
+
'--classpath',
|
|
250
|
+
input.javaClasspath.map((file) => path.resolve(file)).join(path.delimiter),
|
|
251
|
+
'--platform',
|
|
252
|
+
platform,
|
|
253
|
+
...(input.processorPath ? ['--processorpath', input.processorPath] : []),
|
|
254
|
+
'--out',
|
|
255
|
+
translated,
|
|
256
|
+
`@${sourceList}`,
|
|
257
|
+
],
|
|
258
|
+
)
|
|
259
|
+
if (/^refuses /m.test(diagnostics))
|
|
260
|
+
throw new Error(
|
|
261
|
+
`Android library ${name} requires unsupported platform members:\n${diagnostics.trimEnd()}`,
|
|
262
|
+
)
|
|
263
|
+
translatedSources = input.kotlinFragments
|
|
264
|
+
? fs
|
|
265
|
+
.readdirSync(translated, { recursive: true, encoding: 'utf8' })
|
|
266
|
+
.filter((file) => file.endsWith('.kt'))
|
|
267
|
+
.sort()
|
|
268
|
+
.map((file) => path.join(translated, file))
|
|
269
|
+
: [translated]
|
|
270
|
+
}
|
|
271
|
+
const multiplatform = input.kotlinFragments
|
|
272
|
+
? kotlinFragmentFlags(input.kotlinFragments, kotlinSources, translatedSources)
|
|
273
|
+
: commonSources.length
|
|
274
|
+
? ['-Xmulti-platform', `-Xcommon-sources=${commonSources.join(',')}`]
|
|
275
|
+
: []
|
|
276
|
+
const language = input.kotlinLanguage ?? '2.1'
|
|
277
|
+
const raw = path.join(work, 'raw')
|
|
278
|
+
await runCompiler(
|
|
279
|
+
ready.kotlinc,
|
|
280
|
+
[
|
|
281
|
+
'-J-Xmx4g',
|
|
282
|
+
'-Xwasm-target=js',
|
|
283
|
+
'-nowarn',
|
|
284
|
+
`-Xplugin=${path.join(sdkRoot, 'plugin.jar')}`,
|
|
285
|
+
'-P',
|
|
286
|
+
'plugin:dev.peach.jni:android=true',
|
|
287
|
+
'-language-version',
|
|
288
|
+
language,
|
|
289
|
+
'-api-version',
|
|
290
|
+
language,
|
|
291
|
+
...(input.kotlinOptIns ?? []).map((marker) => `-opt-in=${marker}`),
|
|
292
|
+
...multiplatform,
|
|
293
|
+
'-libraries',
|
|
294
|
+
compileLibraries.join(path.delimiter),
|
|
295
|
+
'-ir-output-dir',
|
|
296
|
+
raw,
|
|
297
|
+
'-ir-output-name',
|
|
298
|
+
name,
|
|
299
|
+
...kotlinSources,
|
|
300
|
+
...translatedSources,
|
|
301
|
+
],
|
|
302
|
+
{ stdio: 'inherit', env: { ...process.env, JAVA_HOME: ready.javaHome } },
|
|
303
|
+
'Android library ' + name + ' compilation',
|
|
304
|
+
)
|
|
305
|
+
const compiled = path.join(raw, `${name}.klib`)
|
|
306
|
+
if (!javaSources.length) {
|
|
307
|
+
fs.renameSync(compiled, output)
|
|
308
|
+
return
|
|
309
|
+
}
|
|
310
|
+
const normalized = path.join(work, 'normalized.klib')
|
|
311
|
+
await runKotlinTool(ready, sdkRoot, 'dev.peach.tools.platform.JavaPlatformTypesKt', [
|
|
312
|
+
compiled,
|
|
313
|
+
normalized,
|
|
314
|
+
'--java-classes',
|
|
315
|
+
])
|
|
316
|
+
fs.renameSync(normalized, output)
|
|
317
|
+
} finally {
|
|
318
|
+
fs.rmSync(work, { recursive: true, force: true })
|
|
319
|
+
}
|
|
320
|
+
}
|
|
@@ -330,13 +330,6 @@ export async function mavenKotlinSources(
|
|
|
330
330
|
return null
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
-
export function readKotlinSourcesArchive(
|
|
334
|
-
archive: string,
|
|
335
|
-
where: string,
|
|
336
|
-
): Promise<string[]> {
|
|
337
|
-
return kotlinSources(readSourcesJar(archive, where), where)
|
|
338
|
-
}
|
|
339
|
-
|
|
340
333
|
export function readMavenSourcesArchive(archive: string): Promise<MavenSources> {
|
|
341
334
|
return extract(readSourcesJar(archive, archive), archive)
|
|
342
335
|
}
|