napi-rs/generate-triple-list.ts

49 lines
1.1 KiB
TypeScript
Raw Normal View History

import { readFileSync, writeFileSync } from 'fs'
import { join } from 'path'
import * as esbuild from 'esbuild'
import { groupBy, mapValues } from 'lodash'
import { parseTriple } from './cli/src/parse-triple'
2021-07-22 14:35:01 +09:00
const RAW_LIST = readFileSync(join(__dirname, 'triples', 'target-list'), 'utf8')
2021-07-22 14:35:01 +09:00
const SUPPORTED_PLATFORM = new Set([
'darwin',
'ios',
'android',
'win32',
'linux',
'freebsd',
])
2021-11-19 15:58:21 +09:00
const tripleLists: { [key: string]: { platform?: string } } = RAW_LIST.trim()
.split('\n')
.filter((line) => !line.startsWith('wasm') && line.trim().length)
.map(parseTriple)
.reduce((acc, cur) => {
acc[cur.raw] = cur
return acc
}, {})
const platformArchTriples = mapValues(
2021-07-22 14:35:01 +09:00
groupBy(
2021-11-19 15:58:21 +09:00
Object.values(tripleLists).filter((k) =>
SUPPORTED_PLATFORM.has(k.platform!),
2021-07-22 14:35:01 +09:00
),
'platform',
),
(v) => groupBy(v, 'arch'),
)
const fileContent = `
module.exports.platformArchTriples = ${JSON.stringify(platformArchTriples)}
`
writeFileSync(
join(__dirname, 'triples', 'index.js'),
2021-07-22 14:35:01 +09:00
esbuild.transformSync(fileContent, {
minify: true,
}).code,
)