-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathbuild_lib.ts
More file actions
206 lines (189 loc) · 5.06 KB
/
Copy pathbuild_lib.ts
File metadata and controls
206 lines (189 loc) · 5.06 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import {
rmSync,
existsSync,
symlinkSync,
mkdirSync
} from 'fs'
import { platform } from 'os'
import { cwd, chdir } from 'process'
import { spawnSync, SpawnSyncOptionsWithBufferEncoding } from 'child_process'
import {
rf,
ensure,
patch
} from './util.js'
const root = cwd()
const PLATFORM = platform()
const emcmake = PLATFORM === 'win32' ? 'emcmake.bat' : 'emcmake'
const ENABLE_LOGGING = process.env.ENABLE_LOGGING || 'ON'
const BUILD_TYPE = process.env.BUILD_TYPE || 'Release'
const CXXFLAGS = '-fexceptions'
const DESTDIR = `${root}/build/sysroot`
const CMAKE_FIND_ROOT_PATH = `${DESTDIR}/usr`
const CMAKE_DEF = [
'-G', 'Ninja',
'-DCMAKE_INSTALL_PREFIX:PATH=/usr',
`-DCMAKE_BUILD_TYPE:STRING=${BUILD_TYPE}`,
'-DBUILD_SHARED_LIBS:BOOL=OFF'
]
const spawnArg: SpawnSyncOptionsWithBufferEncoding = {
stdio: 'inherit',
env: {
CXXFLAGS,
...process.env
}
}
const installArg: SpawnSyncOptionsWithBufferEncoding = {
stdio: 'inherit',
env: {
DESTDIR,
...process.env
}
}
function buildYamlCpp () {
console.log('Building yaml-cpp')
const src = 'librime/deps/yaml-cpp'
const dir = 'build/yaml-cpp'
rmSync(dir, rf)
ensure(spawnSync(emcmake, [
'cmake', src,
'-B', dir,
...CMAKE_DEF,
'-DYAML_CPP_BUILD_CONTRIB:BOOL=OFF',
'-DYAML_CPP_BUILD_TESTS:BOOL=OFF',
'-DYAML_CPP_BUILD_TOOLS:BOOL=OFF'
], spawnArg))
ensure(spawnSync('cmake', ['--build', dir], spawnArg))
ensure(spawnSync('cmake', ['--install', dir], installArg))
}
function buildLevelDB () {
console.log('Building leveldb')
const src = 'librime/deps/leveldb'
const dst = 'build/leveldb'
patch(src, 'leveldb_patch')
rmSync(dst, rf)
ensure(spawnSync(emcmake, [
'cmake', src,
'-B', dst,
...CMAKE_DEF,
'-DLEVELDB_BUILD_BENCHMARKS:BOOL=OFF',
'-DLEVELDB_BUILD_TESTS:BOOL=OFF'
], spawnArg))
ensure(spawnSync('cmake', ['--build', dst], spawnArg))
ensure(spawnSync('cmake', ['--install', dst], installArg))
}
function buildMarisaTrie () {
console.log('Building marisa-trie')
const src = 'librime/deps/marisa-trie'
const dst = 'build/marisa-trie'
patch(src, 'marisa_patch')
rmSync(dst, rf)
ensure(spawnSync(emcmake, [
'cmake', src,
'-B', dst,
...CMAKE_DEF
], spawnArg))
ensure(spawnSync('cmake', ['--build', dst], spawnArg))
ensure(spawnSync('cmake', ['--install', dst], installArg))
}
function buildOpenCC () {
console.log('Building opencc')
const src = 'librime/deps/opencc'
const dst = 'build/opencc'
patch(src, 'opencc_patch')
rmSync(dst, rf)
ensure(spawnSync(emcmake, [
'cmake', src,
'-B', dst,
...CMAKE_DEF,
`-DCMAKE_FIND_ROOT_PATH:PATH=${CMAKE_FIND_ROOT_PATH}`,
'-DENABLE_DARTS:BOOL=OFF',
'-DUSE_SYSTEM_MARISA:BOOL=ON'
], spawnArg))
ensure(spawnSync('cmake', ['--build', dst], spawnArg))
ensure(spawnSync('cmake', ['--install', dst], installArg))
}
function buildGlog () {
if (ENABLE_LOGGING !== 'ON') {
console.log('Skip glog')
return
}
console.log('Building glog')
const src = 'librime/deps/glog'
const dst = 'build/glog'
chdir(src)
ensure(spawnSync('git', ['reset', '--hard']))
ensure(spawnSync('git', [
'pull',
'https://github.com/google/glog',
'master'
])) // TODO: wait for a new release
ensure(spawnSync('git', [
'checkout',
'36ccb159f442a389ab2b48650d8034aa2a301b79'
]))
chdir(root)
patch(src, 'glog_patch')
rmSync(dst, rf)
ensure(spawnSync(emcmake, [
'cmake', src,
'-B', dst,
...CMAKE_DEF,
'-DWITH_GFLAGS:BOOL=OFF',
'-DBUILD_TESTING:BOOL=OFF',
'-DWITH_UNWIND:BOOL=OFF'
], spawnArg))
ensure(spawnSync('cmake', ['--build', dst], spawnArg))
ensure(spawnSync('cmake', ['--install', dst], installArg))
}
function buildLibrime () {
console.log('Building librime')
const luaPluginLink = 'librime/plugins/lua'
if (!existsSync(luaPluginLink)) {
symlinkSync('../../librime-lua', luaPluginLink, 'dir')
}
const luaParent = 'librime-lua/thirdparty'
const luaLink = `${luaParent}/lua5.4`
mkdirSync(luaParent, { recursive: true })
if (!existsSync(luaLink)) {
symlinkSync('../../lua', luaLink, 'dir')
}
rmSync('lua/onelua.c', rf)
const src = 'librime'
const dst = 'build/librime_wasm'
patch(src, 'librime_patch')
rmSync(dst, rf)
ensure(spawnSync(emcmake, [
'cmake', src,
'-B', dst,
...CMAKE_DEF,
`-DCMAKE_FIND_ROOT_PATH:PATH=${CMAKE_FIND_ROOT_PATH}`,
'-DBUILD_TEST:BOOL=OFF',
'-DBUILD_STATIC:BOOL=ON',
'-DENABLE_THREADING:BOOL=OFF',
'-DENABLE_TIMESTAMP:BOOL=OFF',
`-DENABLE_LOGGING:BOOL=${ENABLE_LOGGING}`
], spawnArg))
ensure(spawnSync('cmake', ['--build', dst], spawnArg))
ensure(spawnSync('cmake', ['--install', dst], installArg))
}
const targetHandler = {
'yaml-cpp': buildYamlCpp,
leveldb: buildLevelDB,
marisa: buildMarisaTrie,
opencc: buildOpenCC,
glog: buildGlog,
rime: buildLibrime
}
let hasTarget = false
for (const [target, handler] of Object.entries(targetHandler)) {
if (process.argv.includes(target)) {
hasTarget = true
handler()
}
}
if (!hasTarget) {
for (const handler of Object.values(targetHandler)) {
handler()
}
}