-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.js
More file actions
151 lines (120 loc) · 4.24 KB
/
build.js
File metadata and controls
151 lines (120 loc) · 4.24 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
var fs = require('fs-extra')
var rimraf = require('rimraf')
var BuildSystem = require('cmake-js').BuildSystem
var spawn = require('child_process').spawn
var minimist = require('minimist')
// Use a custom build folder for cmake-js to avoid conflict with node-gyp
var CMAKEJS_BUILD_DIR = 'build-cmakejs'
if(process.platform === 'win32') {
process.chdir('../');
}
function clean () {
function remove (path) {
if (!fs.existsSync(path)) return
try {
fs.unlinkSync(path)
} catch (e) {}
}
remove('./conaninfo.txt')
remove('./conanbuildinfo.cmake')
remove('./conanbuildinfo.txt')
try {
rimraf.sync(CMAKEJS_BUILD_DIR)
} catch (e) {}
}
function getRuntimeAndVersion() {
return new Promise(function(resolve, reject){
var options = minimist(process.argv.slice(2),{boolean:true});
if(!options.nodedir) {
return reject(new Error('use node-gyp to build'))
}
// building for node runtime unless iojs appears in the nodedir path
// which indicates using dev headers for electron
options.runtime = options.nodedir.indexOf('iojs') === -1 ? 'node' : 'electron'
if(!options.target) {
if(options.runtime !== 'node') {
// if buliding for electron target (runtime version must be provided)
return reject(new Error('target not specified'))
}
options.runtime_version = process.versions.node
} else {
options.runtime_version = options.target
}
if(!options.arch) {
if(options.runtime !== 'node') {
// if building for electron architecture must be specified
return reject(new Error('arch not specified'))
}
options.arch = process.arch
}
options.debug = process.env.BUILDTYPE === 'Debug'
resolve(options)
})
}
function conanInstall(options) {
console.log('conan install with options:', options)
// node-gyp sets MAKEFLAGS env var that looks like: "r -- BUILDTYPE=Release"
// -r make flags is causing build issue for openssl and zlib on OSX
// BUILDTYPE=Debug/Release is redundant (it is set in BUILDTYPE env var)
// so just clearing the flag here
process.env.MAKEFLAGS=''
var args = ['install', '.', '--build=missing']
args.push("-oruntime=" + options.runtime)
args.push("-oruntime_version=" + options.runtime_version)
if (process.platform === 'win32') {
args.push("-scompiler=Visual Studio")
args.push("-scompiler.runtime=MT")
}
var mapping = {
'x64' : 'x86_64',
'ia32' : 'x86'
}
//conan architecture setting
if(options.arch) {
args.push("-sarch=" + (mapping[options.arch] || options.arch))
}
if(options.debug) {
args.push("-sbuild_type=Debug")
}
return new Promise(function(resolve, reject){
var child = spawn('conan', args, {stdio: 'inherit', detached:false})
child.on('close', function(exit_code){
if(exit_code === 0) return resolve(options)
reject()
})
})
}
function rebuild(opts){
var mapping = {
'x86_64' : 'x64',
'x86' : 'ia32'
}
var options = {
runtime: opts.runtime,
runtimeVersion: opts.runtime_version,
arch: mapping[opts.arch] || opts.arch,
debug: opts.debug,
out: CMAKEJS_BUILD_DIR
}
console.log('cmake-js rebuild with options:', options)
// configure build system
var bs = new BuildSystem(options)
// rebuild() the addon instead of just compile(), to avoid issues when switching runtimes
return bs.rebuild().then(function(){
// copy module from custom build location to build/ folder
if(process.platform == 'win32') {
// on windows with visual studio, .node files is produced in different locaiton
fs.copySync('build-cmakejs/bin/JoyStreamAddon.node', 'build/JoyStreamAddon.node')
} else {
fs.copySync('build-cmakejs/build-cmakejs/' + process.env.BUILDTYPE + '/JoyStreamAddon.node', 'build/JoyStreamAddon.node')
}
})
}
clean()
getRuntimeAndVersion()
.then(conanInstall)
.then(rebuild)
.catch(function(err){
console.error('JoyStreamAddon build failed:', err)
process.exit(-1)
})