Skip to content

Commit 3fac0a4

Browse files
committed
suport prebuilt linux/mac compiler now, testing
1 parent 576ccf9 commit 3fac0a4

File tree

3 files changed

+62
-47
lines changed

3 files changed

+62
-47
lines changed

jscomp/Makefile

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
ifdef WIN32
2-
EXE := .exe
3-
endif
4-
ifndef EXE
5-
EXE := # empty
6-
endif
1+
72
.SECONDARY:
83
NATIVE=ocamlopt.opt$(EXE)
94
BYTE=ocamlc.opt$(EXE)

scripts/install.js

+38-18
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ function setUpNinja() {
6262
};
6363

6464

65-
var ninja_os_path = path.join(ninja_build_dir,'ninja' + sys_extension )
65+
var ninja_os_path = path.join(ninja_build_dir, 'ninja' + sys_extension)
6666
if (fs.existsSync(ninja_bin_output) && test_ninja_compatible(ninja_bin_output)) {
6767
console.log("ninja binary is already cached: ", ninja_bin_output)
68-
}
68+
}
6969
else if (fs.existsSync(ninja_os_path)) {
7070
fs.renameSync(ninja_os_path, ninja_bin_output)
7171
if (test_ninja_compatible(ninja_bin_output)) {
@@ -92,10 +92,7 @@ function matchedCompilerExn() {
9292
throw ""
9393
}
9494
}
95-
96-
97-
function non_windows_npm_release() {
98-
95+
function tryToProvideOCamlCompiler() {
9996
try {
10097
if (process.env.BS_ALWAYS_BUILD_YOUR_COMPILER) {
10198
throw 'FORCED TO REBUILD'
@@ -114,29 +111,52 @@ function non_windows_npm_release() {
114111
console.log('configure again with local ocaml installed')
115112
matchedCompilerExn()
116113
console.log("config finished")
117-
}
118-
child_process.execSync(make + " world && " + make + " install", root_dir_config)
114+
}
119115
}
120116

121-
var build_util = require('./build_util.js')
122-
setUpNinja()
123-
if (is_windows) {
124-
process.env.WIN32 = '1'
125-
console.log("Installing on Windows")
117+
function non_windows_npm_release() {
118+
119+
if (checkPrebuilt()) {
120+
child_process.execSync(make + " libs && " + make + " install", root_dir_config)
121+
} else {
122+
tryToProvideOCamlCompiler()
123+
child_process.execSync(make + " world && " + make + " install", root_dir_config)
124+
}
125+
}
126+
function checkPrebuilt() {
127+
try {
128+
if(fs.existsSync(path.join(lib_dir,'bsc.exe'))){
129+
console.log('Found bsc.exe, assume it was already built')
130+
return true // already built before
131+
}
132+
var version = child_process.execFileSync(path.join(lib_dir, 'bsc' + sys_extension), ['-v'])
133+
console.log("checkoutput:", String(version))
134+
return copyBinToExe()
135+
} catch (e) {
136+
console.log("No working prebuilt compiler")
137+
return false
138+
}
139+
}
140+
141+
function copyBinToExe() {
126142
var indeed_windows_release = 0
127143
fs.readdirSync(lib_dir).forEach(function (f) {
128-
var last_index = f.lastIndexOf('.win')
144+
var last_index = f.lastIndexOf(sys_extension)
129145
if (last_index !== -1) {
130-
var new_file = f.slice(0, -4) + ".exe"
146+
var new_file = f.slice(0, - sys_extension.length) + ".exe"
131147
build_util.poor_copy_sync(path.join(lib_dir, f), path.join(lib_dir, new_file));
132148
// we do have .win file which means windows npm release
133149
++indeed_windows_release
134150
}
135151

136152
})
137-
if (indeed_windows_release > 1) {
138-
// Make it more fault tolerant
139-
// =1 can still be okay (only ninja.win in this case)
153+
return indeed_windows_release > 1
154+
}
155+
var build_util = require('./build_util.js')
156+
157+
setUpNinja()
158+
if (is_windows) {
159+
if (copyBinToExe()) {
140160
child_process.execFileSync(
141161
path.join(__dirname, 'win_build.bat'),
142162
{ cwd: path.join(root_dir, 'jscomp'), stdio: [0, 1, 2] }

scripts/prebuilt.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,7 @@ console.log("Working dir", working_dir)
1515
var jscomp_dir_config = { cwd: jscomp, stdio: [0, 1, 2] }
1616
var root_config = { cwd: root, stdio: [0, 1, 2] }
1717
process.env.BS_RELEASE_BUILD = 'true'
18-
function buildCompiler() {
19-
child_process.execSync('make -j1 -B -C lib all', root_config)
2018

21-
if(is_windows){
22-
fs.writeFileSync(
23-
path.join(__dirname,
24-
'win_build.bat'),
25-
getLibCommands(),
26-
'utf8'
27-
)
28-
}
29-
30-
// rename exe to .win
31-
fs.readdirSync(path.join(root, 'lib')).forEach(function (f) {
32-
var last_index = f.lastIndexOf('.exe')
33-
if (last_index !== -1) {
34-
var new_file = f.slice(0, -4) + sys_extension
35-
console.log(f + " --> " + new_file)
36-
fs.renameSync(path.join(root, 'lib', f), path.join(root, 'lib', new_file))
37-
}
38-
})
39-
}
40-
41-
buildCompiler()
4219
function getLibCommands() {
4320
var result =
4421
child_process.execSync(
@@ -89,5 +66,28 @@ function getLibCommands() {
8966
}
9067

9168

69+
function buildCompiler() {
70+
child_process.execSync('make -j1 -B -C lib all', root_config)
9271

72+
if(is_windows){
73+
fs.writeFileSync(
74+
path.join(__dirname,
75+
'win_build.bat'),
76+
getLibCommands(),
77+
'utf8'
78+
)
79+
}
80+
81+
// rename exe to .win
82+
fs.readdirSync(path.join(root, 'lib')).forEach(function (f) {
83+
var last_index = f.lastIndexOf('.exe')
84+
if (last_index !== -1) {
85+
var new_file = f.slice(0, -4) + sys_extension
86+
console.log(f + " --> " + new_file)
87+
fs.renameSync(path.join(root, 'lib', f), path.join(root, 'lib', new_file))
88+
}
89+
})
90+
}
91+
92+
buildCompiler()
9393

0 commit comments

Comments
 (0)