-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdate-toolchain.mjs
More file actions
127 lines (116 loc) · 3.16 KB
/
Copy pathupdate-toolchain.mjs
File metadata and controls
127 lines (116 loc) · 3.16 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { execSync } from 'node:child_process'
import { rmSync, renameSync, writeFileSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { omit } from 'lodash-es'
import rootPkgJson from './package.json' with { type: 'json' }
const __dirname = join(fileURLToPath(import.meta.url), '..')
const LICENSE = readFileSync(join(__dirname, 'LICENSE'), 'utf8')
const hosts = [
{
name: 'amd64',
nameInNode: 'x64',
},
{
name: 'arm64',
nameInNode: 'arm64',
},
]
const targets = [
{
name: 'x86_64-unknown-linux-gnu',
tag: 'x86_64',
},
{
name: 'aarch64-unknown-linux-gnu',
tag: 'aarch64',
},
{
name: 'armv7-unknown-linux-gnueabihf',
tag: 'armv7',
},
{
name: 's390x-ibm-linux-gnu',
tag: 's390x',
},
{
name: 'powerpc64le-unknown-linux-gnu',
tag: 'ppc64le',
},
]
for (const host of hosts) {
for (const target of targets) {
execSync(
`docker run --rm --platform=linux/${host.name} -v "$(pwd)/${host.nameInNode}":/${host.nameInNode} messense/manylinux2014-cross:${target.tag} bash -c "tar -cvf /${host.nameInNode}/${target.name}.tar /usr/${target.name}"`,
{
encoding: 'utf8',
stdio: 'inherit',
}
)
rmSync(join(__dirname, host.nameInNode, target.name), {
recursive: true,
force: true,
})
execSync(
`tar -xvf ${join(
__dirname,
host.nameInNode,
`${target.name}.tar`
)} -C ${join(__dirname, host.nameInNode)}`
)
renameSync(
join(__dirname, host.nameInNode, `usr/${target.name}`),
join(__dirname, host.nameInNode, target.name)
)
rmSync(join(__dirname, host.nameInNode, target.name, 'build.log.bz2'), {
force: true,
})
const gzFile = `${target.name}.tar.xz`
const pkgJson = {
name: `@napi-rs/cross-toolchain-${host.nameInNode}-target-${target.tag}`,
cpu: [host.nameInNode],
scripts: {
prepublishOnly: `tar -cvf ${target.name}.tar . && xz -z -e --threads=4 ${target.name}.tar`,
},
main: 'index.js',
types: 'index.d.ts',
files: ['index.js', 'index.d.ts', gzFile],
...omit(
rootPkgJson,
'name',
'cpu',
'dependencies',
'devDependencies',
'files',
'main',
'types',
'workspaces',
'packageManager',
'peerDependencies',
'scripts',
'peerDependenciesMeta'
),
}
writeFileSync(
join(__dirname, host.nameInNode, target.name, 'package.json'),
JSON.stringify(pkgJson, null, 2) + '\n'
)
writeFileSync(
join(__dirname, host.nameInNode, target.name, 'LICENSE'),
LICENSE
)
writeFileSync(
join(__dirname, host.nameInNode, target.name, 'index.js'),
`module.exports.toolchainPath = require('node:path').join(__dirname, '${gzFile}')\n`
)
writeFileSync(
join(__dirname, host.nameInNode, target.name, 'index.d.ts'),
`export const toolchainPath: string\n`
)
rmSync(join(__dirname, host.nameInNode, `${target.name}.tar`))
}
rmSync(join(__dirname, host.nameInNode, 'usr'), {
recursive: true,
force: true,
})
}