-
Notifications
You must be signed in to change notification settings - Fork 938
/
Copy pathGruntfile.js
188 lines (179 loc) · 5 KB
/
Gruntfile.js
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
// TODO: This could be rewritten as one (or more) pure Node.js script(s)
// without Grunt, and called from package.json.
module.exports = function (grunt) {
const fs = require('fs');
const path = require('path');
const isWin = /^win/.test(process.platform);
const useMinGW = grunt.option('use-MinGW') || false;
const possibleVariants = [
'release',
'dev',
'debug',
'debug-assertions',
'debug-sanitizers',
];
const variant = grunt.option('variant') || (grunt.option('dev') ? 'dev' : 'release');
if (variant && possibleVariants.indexOf(variant) === -1) {
console.error(
`Invalid build variant: ${variant}. Possible values are: ${possibleVariants.join(
', '
)}.`
);
process.exit(1);
}
const buildOutputPath = '../Binaries/embuild/GDevelop.js/';
const buildPath = '../Binaries/embuild';
let cmakeBinary = 'emcmake cmake';
let cmakeGeneratorArgs = [];
let makeBinary = 'emmake make';
let makeArgs = ['-j 8'];
// Use more specific paths on Windows
if (isWin) {
let makeProgram = '';
if (useMinGW) {
// Use make from MinGW
if (!fs.existsSync('C:\\MinGW\\bin\\mingw32-make.exe')) {
console.error(
"🔴 Can't find mingw32-make in C:\\MinGW. Make sure MinGW is installed."
);
return;
}
const mingwBinary = 'C:\\MinGW\\bin\\mingw32-make';
cmakeGeneratorArgs = ['-G "MinGW Makefiles"'];
makeProgram = mingwBinary;
} else {
// Use Ninja (by default)
const ninjaBinary = path.join(__dirname, 'ninja', 'ninja.exe');
cmakeGeneratorArgs = [
'-G "Ninja"',
`-DCMAKE_MAKE_PROGRAM="${ninjaBinary}"`,
];
makeProgram = ninjaBinary;
}
makeBinary = `emmake "${makeProgram}"`;
makeArgs = [];
// Find CMake in usual folders or fallback to PATH.
if (fs.existsSync('C:\\Program Files\\CMake\\bin\\cmake.exe')) {
cmakeBinary = 'emcmake "C:\\Program Files\\CMake\\bin\\cmake"';
} else if (
fs.existsSync('C:\\Program Files (x86)\\CMake\\bin\\cmake.exe')
) {
cmakeBinary = 'emcmake "C:\\Program Files (x86)\\CMake\\bin\\cmake"';
} else {
console.log(
"⚠️ Can't find CMake in its usual Program Files folder. Make sure you have cmake in your PATH instead."
);
}
}
grunt.initConfig({
mkdir: {
embuild: {
options: {
create: [buildPath],
},
},
},
shell: {
// Launch CMake if needed
cmake: {
src: [buildPath + '/CMakeCache.txt', 'CMakeLists.txt'],
command:
cmakeBinary +
' ' +
[
...cmakeGeneratorArgs,
'../..',
// Disable link time optimizations for slightly faster build time.
variant ? '-DGDEVELOPJS_BUILD_VARIANT=' + variant : '',
].join(' '),
options: {
execOptions: {
cwd: buildPath,
env: process.env,
maxBuffer: Infinity,
},
},
},
// Generate glue.cpp and glue.js file using Bindings.idl, and patch them
updateGDBindings: {
src: 'Bindings/Bindings.idl',
command: 'node update-bindings.js',
},
// Compile GDevelop with emscripten
make: {
command: makeBinary + ' ' + makeArgs.join(' '),
options: {
execOptions: {
cwd: buildPath,
env: process.env,
},
},
},
// Copy the library to newIDE
copyToNewIDE: {
command: 'node scripts/copy-to-newIDE.js',
options: {
execOptions: {
cwd: __dirname,
},
},
},
// Generate typings from the Bindings.idl
generateFlowTypes: {
command: 'node scripts/generate-types.js',
options: {
execOptions: {
cwd: __dirname,
},
},
},
generateTSTypes: {
command: 'node scripts/generate-dts.mjs',
options: {
execOptions: {
cwd: __dirname,
},
},
},
syncVersions: {
command: 'node scripts/sync-versions.js',
options: {
execOptions: {
cwd: __dirname,
},
},
},
},
clean: {
options: { force: true },
build: {
src: [
buildPath,
'Bindings/glue.cpp',
'Bindings/glue.js',
buildOutputPath + 'libGD.js',
buildOutputPath + 'libGD.wasm',
],
},
},
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-string-replace');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-newer');
grunt.loadNpmTasks('grunt-mkdir');
grunt.registerTask('build:raw', [
'mkdir:embuild',
'shell:cmake',
'newer:shell:updateGDBindings',
'shell:make',
]);
grunt.registerTask('build', [
'shell:syncVersions',
'build:raw',
'shell:copyToNewIDE',
'shell:generateFlowTypes',
'shell:generateTSTypes',
]);
};