Skip to content

Commit d0d88da

Browse files
committed
Add prebuilt.ext.ninja and copy.prebuilt.ninja build.ninja
1. prebuilt.ext.ninja is for prebuilt 2. copy.prebuilt.ninja is for copy when installation 3. build.ninja is for built from source (not supported under windows)
1 parent 50d0366 commit d0d88da

11 files changed

+113
-88
lines changed

jscomp/runtime/release.ninja

+25-25
Large diffs are not rendered by default.

lib/body.ninja

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
flags = -g -w -a ../jscomp/stubs/ext_basic_hash_stubs.c
3+
rule cc
4+
command = $ocamlopt $flags -o $out $in
5+
# -inline 1000 makes size too large
6+
# TODO: make sure it can be bootstrapped, at least is a very good
7+
# test case of our optimizations
8+
9+
# build bsdep.exe: cc bsdep.mli bsdep.ml
10+
build bsppx.$ext: cc bsppx.mli bsppx.ml
11+
# build bspp.exe: cc bspp.mli bspp.ml
12+
build bsb.$ext: cc bsb.mli bsb.ml
13+
flags = $flags unix.cmxa str.cmxa
14+
build bsb_helper.$ext: cc bsb_helper.mli bsb_helper.ml
15+
flags = $flags unix.cmxa -w -a
16+
build refmt.$ext: cc refmt_main3.mli refmt_main3.ml
17+
flags = $flags -w -40-30 -no-alias-deps -I +compiler-libs ocamlcommon.cmxa
18+
build reactjs_jsx_ppx_2.$ext: cc reactjs_jsx_ppx_v2.mli reactjs_jsx_ppx_v2.ml
19+
flags = $flags -w -40-30 -no-alias-deps -I +compiler-libs ocamlcommon.cmxa
20+
build bsc.$ext: cc whole_compiler.mli whole_compiler.ml
21+

lib/build.ninja

+5-27
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
11

2-
flags = -g -w -a ../jscomp/stubs/ext_basic_hash_stubs.c
3-
4-
# ocamlopt = ../vendor/ocaml/bin/ocamlopt.opt
5-
ocamlopt = ocamlopt.opt
6-
# we relies on its dynamic behavior for finding a proper ocamlopt
7-
rule cc
8-
command = $ocamlopt $flags -o $out $in
9-
10-
# -inline 1000 makes size too large
11-
# TODO: make sure it can be bootstrapped, at least is a very good
12-
# test case of our optimizations
13-
14-
15-
16-
17-
# build bsdep.exe: cc bsdep.mli bsdep.ml
18-
build bsppx.exe: cc bsppx.mli bsppx.ml
19-
# build bspp.exe: cc bspp.mli bspp.ml
20-
build bsb.exe: cc bsb.mli bsb.ml
21-
flags = $flags unix.cmxa str.cmxa
22-
build bsb_helper.exe: cc bsb_helper.mli bsb_helper.ml
23-
flags = $flags unix.cmxa -w -a
24-
build refmt.exe: cc refmt_main3.mli refmt_main3.ml
25-
flags = $flags -w -40-30 -no-alias-deps -I +compiler-libs ocamlcommon.cmxa
26-
build reactjs_jsx_ppx_2.exe: cc reactjs_jsx_ppx_v2.mli reactjs_jsx_ppx_v2.ml
27-
flags = $flags -w -40-30 -no-alias-deps -I +compiler-libs ocamlcommon.cmxa
28-
build bsc.exe: cc whole_compiler.mli whole_compiler.ml
292

3+
# used mostly by platforms which does not provide
4+
# prebuilt binaries, so we output .exe directly
5+
ocamlopt = ocamlopt.opt
6+
ext = exe
7+
include body.ninja

lib/copy.darwin.ninja

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
rule cp
4+
command = cp $in $out
5+
6+
ext = darwin
7+
include copy.ninja

lib/copy.ninja

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
3+
4+
build bsc.exe: cp bsc.$ext
5+
build bsb.exe: cp bsb.$ext
6+
build bsb_helper.exe: cp bsb_helper.$ext
7+
build bsppx.exe: cp bsppx.$ext
8+
build refmt.exe: cp refmt.$ext
9+
build reactjs_jsx_ppx_2.exe: cp reactjs_jsx_ppx_2.$ext
10+
11+

lib/copy.win32.ninja

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rule cp
2+
command = cmd /q /c copy $in $out 1>nul

lib/prebuilt.darwin.ninja

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
3+
4+
# ocamlopt = ../vendor/ocaml/bin/ocamlopt.opt
5+
ocamlopt = ocamlopt.opt
6+
# we relies on its dynamic behavior for finding a proper ocamlopt
7+
8+
ext = darwin
9+
include body.ninja
10+
11+

lib/prebuilt.win32.ninja

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
ocamlopt = ocamlopt.opt.exe
4+
5+
ext = win32
6+
7+
include body.ninja

scripts/config.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var os = require('os')
33
var os_type = os.type()
44

55
var is_windows = !(os_type.indexOf('Windows') < 0)
6-
var is_bsd = !(os_type.indexOf('BSD') < 0)
6+
// var is_bsd = !(os_type.indexOf('BSD') < 0)
77

88
exports.is_windows = is_windows
99
var sys_extension;
@@ -17,5 +17,7 @@ switch (os.type()) {
1717
}
1818

1919
exports.sys_extension = sys_extension
20-
var make = is_bsd ? 'gmake' : 'make'
21-
exports.make = make
20+
// var make = is_bsd ? 'gmake' : 'make'
21+
// exports.make = make
22+
23+

scripts/install.js

+18-23
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,13 @@
1414
var cp = require('child_process')
1515
var fs = require('fs')
1616
var path = require('path')
17-
// var os = require('os')
18-
19-
// var os_type = os.type()
2017
var root_dir = path.join(__dirname, '..')
2118
var lib_dir = path.join(root_dir, 'lib')
2219
var jscomp_dir = path.join(root_dir, 'jscomp')
2320
var runtime_dir = path.join(jscomp_dir,'runtime')
2421
var others_dir = path.join(jscomp_dir,'others')
2522
var stdlib_dir = path.join(jscomp_dir, 'stdlib-402')
26-
var root_dir_config = { cwd: root_dir, stdio: [0, 1, 2] }
2723

28-
// var dest_bin = path.join(root_dir, 'lib')
29-
// var dest_lib = path.join(root_dir, 'lib', 'ocaml')
3024

3125
var ocaml_dir = path.join(lib_dir,'ocaml')
3226
var config = require('./config.js')
@@ -43,7 +37,13 @@ process.env.PATH =
4337
process.env.PATH
4438

4539
var ninja_bin_output = path.join(root_dir, 'lib', 'ninja.exe')
46-
// Make sure `ninja_bin_output` exists
40+
41+
42+
/**
43+
* Make sure `ninja_bin_output` exists
44+
* The installation of `ninja.exe` is re-entrant, since we always pre-check if it is already installed
45+
* This is less problematic since `ninja.exe` is very stable
46+
*/
4747
function provideNinja() {
4848
var vendor_ninja_version = '1.8.2'
4949
var ninja_source_dir = path.join(root_dir, 'vendor', 'ninja')
@@ -77,7 +77,7 @@ function provideNinja() {
7777

7878
var ninja_os_path = path.join(ninja_source_dir,'snapshot', 'ninja' + sys_extension)
7979
if (fs.existsSync(ninja_bin_output) && test_ninja_compatible(ninja_bin_output)) {
80-
console.log("ninja binary is already cached: ", ninja_bin_output)
80+
console.log("ninja binary is already cached and installed: ", ninja_bin_output)
8181
}
8282
else if (fs.existsSync(ninja_os_path)) {
8383
if(fs.copyFileSync){
@@ -213,18 +213,10 @@ function tryToProvideOCamlCompiler() {
213213
}
214214
}
215215

216-
function renamePrebuiltCompilers() {
217-
fs.readdirSync(lib_dir).forEach(function (f) {
218-
var last_index = f.lastIndexOf(sys_extension)
219-
if (last_index !== -1) {
220-
var new_file = f.slice(0, - sys_extension.length) + ".exe"
221-
var x = path.join(lib_dir, f)
222-
var y = path.join(lib_dir,new_file)
223-
console.log(x,'-->',y)
224-
fs.renameSync(x, y);
225-
// we do have .win file which means windows npm release
226-
}
227-
})
216+
function copyPrebuiltCompilers() {
217+
cp.execFileSync(ninja_bin_output,
218+
["-f", "copy" + sys_extension + ".ninja"],
219+
{ cwd: lib_dir, stdio: [0, 1, 2] })
228220
}
229221

230222
/**
@@ -235,7 +227,7 @@ function checkPrebuilt() {
235227
var version = cp.execFileSync(path.join(lib_dir, 'bsc' + sys_extension), ['-v'])
236228
console.log("checkoutput:", String(version))
237229
console.log("Prebuilt compiler works good")
238-
renamePrebuiltCompilers()
230+
239231
return true
240232
} catch (e) {
241233
console.log("No working prebuilt buckleScript compiler")
@@ -255,7 +247,10 @@ function provideCompiler() {
255247
console.log('Found pervasives.cmi, assume it was already built')
256248
return true // already built before
257249
}
258-
if (!checkPrebuilt()) {
250+
if (checkPrebuilt()) {
251+
copyPrebuiltCompilers()
252+
}
253+
else {
259254
// when not having bsc.exe
260255
tryToProvideOCamlCompiler()
261256
// Note this ninja file only works under *nix due to the suffix
@@ -268,7 +263,7 @@ function provideCompiler() {
268263
provideNinja()
269264

270265
if(is_windows){
271-
renamePrebuiltCompilers()
266+
copyPrebuiltCompilers()
272267
} else{
273268
provideCompiler()
274269
}

scripts/prebuilt.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//@ts-check
22
var child_process = require('child_process')
3-
var fs = require('fs')
43
var path = require('path')
54
var {sys_extension, is_windows} = require('./config.js')
65

@@ -11,15 +10,7 @@ process.env.BS_RELEASE_BUILD = 'true'
1110

1211

1312
function buildCompiler() {
14-
child_process.execSync('make -j1 -B -C lib all', root_config)
15-
fs.readdirSync(path.join(root, 'lib')).forEach(function (f) {
16-
var last_index = f.lastIndexOf('.exe')
17-
if (last_index !== -1) {
18-
var new_file = f.slice(0, -4) + sys_extension
19-
console.log(f + " --> " + new_file)
20-
fs.renameSync(path.join(root, 'lib', f), path.join(root, 'lib', new_file))
21-
}
22-
})
13+
child_process.execSync(`ninja -C lib -f prebuilt${sys_extension}.ninja -t clean && ninja -C lib -f prebuilt${sys_extension}.ninja`,root_config)
2314
}
2415
if(!is_windows){
2516
require('./runtimeDeps.js').updateRelease()

0 commit comments

Comments
 (0)