Skip to content

Commit 73f7aa7

Browse files
committedJun 5, 2021
tweak to support arm64
node ./scripts/prebuilt.js -no-clean -use-env-compiler
1 parent b39896c commit 73f7aa7

File tree

4 files changed

+52
-22
lines changed

4 files changed

+52
-22
lines changed
 

‎rescript

+17-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ var os = require("os");
1212
var path = require("path");
1313
var fs = require("fs");
1414
var bsconfig = "bsconfig.json";
15-
var bsb_exe = path.join(__dirname, process.platform, "rescript.exe");
15+
16+
/**
17+
*
18+
* @type{string}
19+
*/
20+
var bin_path = path.join(__dirname, process.platform === 'darwin' && process.arch === 'arm64' ? process.platform + process.arch : process.platform)
21+
22+
/**
23+
* @type{string}
24+
*/
25+
var bsb_exe = path.join(bin_path, "rescript.exe");
1626

1727
var LAST_BUILD_START = 0;
1828
var LAST_FIRED_EVENT = 0;
@@ -175,7 +185,7 @@ function releaseBuild() {
175185
if (is_building) {
176186
try {
177187
fs.unlinkSync(lockFileName);
178-
} catch (err) {}
188+
} catch (err) { }
179189
is_building = false;
180190
}
181191
}
@@ -206,7 +216,11 @@ if (
206216
maybe_subcommand !== "info"
207217
// delegate to native
208218
) {
209-
var bsc_exe = path.join(__dirname, process.platform, "bsc.exe");
219+
/**
220+
* @type {string}
221+
*/
222+
var bsc_exe = path.join(bin_path, "bsc.exe")
223+
210224
switch (maybe_subcommand) {
211225
case "format":
212226
require("./scripts/rescript_format.js").main(

‎scripts/install.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ if (supported_os.indexOf(process.platform) < 0) {
2424
}
2525
var is_windows = process.platform === "win32";
2626

27-
var ninja_bin_output = path.join(root_dir, process.platform, "ninja.exe");
27+
var my_target = process.platform === 'darwin' && process.arch === 'arm64' ? process.platform + process.arch : process.platform;
28+
var bin_path =
29+
path.join(root_dir, my_target);
30+
31+
var ninja_bin_output = path.join(bin_path, "ninja.exe");
2832
var use_env_compiler = process.argv.includes("-use-env-compiler");
33+
var force_compiler_rebuild = process.argv.includes('-force-compiler-rebuild');
34+
var force_lib_rebuild = process.argv.includes('-force-lib-rebuild');
2935
/**
3036
* Make sure `ninja_bin_output` exists
3137
* The installation of `ninja.exe` is re-entrant, since we always pre-check if it is already installed
@@ -109,12 +115,12 @@ function ensureExists(dir) {
109115
* @returns {string|undefined}
110116
*/
111117
function checkPrebuiltBscCompiler() {
112-
if (process.env.BS_TRAVIS_CI) {
118+
if (process.env.BS_TRAVIS_CI || force_compiler_rebuild) {
113119
return;
114120
}
115121
try {
116122
var version = String(
117-
cp.execFileSync(path.join(root_dir, process.platform, "bsc.exe"), ["-v"])
123+
cp.execFileSync(path.join(bin_path, "bsc.exe"), ["-v"])
118124
);
119125

120126
var myOCamlVersion = version.substr(
@@ -143,7 +149,7 @@ function buildLibs(stdlib) {
143149
ensureExists(path.join(lib_dir, "es6"));
144150
process.env.NINJA_IGNORE_GENERATOR = "true";
145151
var releaseNinja = `
146-
bsc = ../${process.platform}/bsc.exe
152+
bsc = ../${my_target}/bsc.exe
147153
stdlib = ${stdlib}
148154
subninja runtime/release.ninja
149155
subninja others/release.ninja
@@ -223,7 +229,7 @@ provideCompiler();
223229

224230
var stdlib = "stdlib-406";
225231

226-
if (process.env.BS_TRAVIS_CI) {
232+
if (process.env.BS_TRAVIS_CI || force_lib_rebuild) {
227233
buildLibs(stdlib);
228234
require("./installUtils.js").install();
229235
}

‎scripts/ninjaFactory.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
// # test case of our optimizations
66
// # build bsdep.exe: cc bsdep.mli bsdep.ml
77
// ../native/4.06.1/bin/ocamlopt.opt -c -O2 -nodynlink -I 4.06.1 -g -w a+32 4.06.1/whole_compiler.mli 4.06.1/whole_compiler.ml &> warning.log
8+
9+
/**
10+
* @type{string}
11+
*/
12+
var targetDir = process.platform === 'darwin' && process.arch === 'arm64' ? process.platform + process.arch : process.arch
13+
14+
815
/**
916
*
1017
* @param {{ocamlopt : string ; INCL : string, isWin : boolean}} config
@@ -21,15 +28,11 @@ rule cc
2128
config.isWin ? "" : "&& strip $out"
2229
}
2330
description = Making $out
24-
# build bspp.exe: cc bspp.mli bspp.ml
25-
# build ../${process.platform}/bsb$ext: cc $INCL/bsb.mli $INCL/bsb.ml
26-
# flags = $flags -unboxed-types unix.cmxa str.cmxa
27-
build ../${process.platform}/rescript$ext: cc $INCL/rescript.mli $INCL/rescript.ml
31+
build ../${targetDir}/rescript$ext: cc $INCL/rescript.mli $INCL/rescript.ml
2832
flags = $flags -unboxed-types unix.cmxa str.cmxa
29-
o ../${process.platform}/bsb_helper$ext: cc $INCL/bsb_helper.mli $INCL/bsb_helper.ml
33+
build ../${targetDir}/bsb_helper$ext: cc $INCL/bsb_helper.mli $INCL/bsb_helper.ml
3034
flags = $flags -unboxed-types -w -a
31-
32-
o ../${process.platform}/bsc$ext: cc $INCL/whole_compiler.mli $INCL/whole_compiler.ml
35+
build ../${targetDir}/bsc$ext: cc $INCL/whole_compiler.mli $INCL/whole_compiler.ml
3336
flags = $flags -w A-4-9-48-40-45-41-44-50-21-30-32-34-37-27-60-42
3437
`;
3538
}

‎scripts/prebuilt.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,43 @@ function rebuild() {
5151
});
5252
}
5353

54+
var use_env_compiler = process.argv.includes('-use-env-compiler')
55+
var bin_path =
56+
path.join(__dirname, '..', process.platform === 'darwin' && process.arch === 'arm64' ? process.platform + process.arch : process.platform)
57+
5458
function buildCompiler() {
5559
// for 4.02.3 it relies on OCAMLLIB to find stdlib path
5660
// for 4.06.1 OCAMLLIB is another PATH
5761
// delete process.env.OCAMLLIB
5862
var prebuilt = "prebuilt.ninja";
5963
var content = require("./ninjaFactory.js").libNinja({
6064
ocamlopt: is_windows
61-
? `ocamlopt.opt.exe`
62-
: `../native/${ocamlVersion}/bin/ocamlopt.opt`,
65+
? `ocamlopt.opt.exe` :
66+
(use_env_compiler ? `ocamlopt.opt`
67+
: `../native/${ocamlVersion}/bin/ocamlopt.opt`),
6368
INCL: ocamlVersion,
6469
isWin: is_windows,
6570
});
6671

6772
fs.writeFileSync(path.join(root, "lib", prebuilt), content, "ascii");
68-
process.env.PATH = `${path.join(__dirname, "..", process.platform)}${
69-
path.delimiter
70-
}${process.env.PATH}`;
73+
// This is for ninja access
74+
process.env.PATH = `${bin_path}${path.delimiter}${process.env.PATH}`;
7175
let ninjaPath = `ninja.exe`;
76+
console.log(`start build`)
7277
cp.execSync(
7378
`${ninjaPath} -C lib -f ${prebuilt} -v -t clean && ${ninjaPath} -v -C lib -f ${prebuilt}`,
7479
root_config
7580
);
81+
console.log('compiler built done')
7682
}
7783
if (!is_windows) {
78-
if (!process.argv.includes("-noclean")) {
84+
if (!process.argv.includes("-no-clean")) {
7985
require("./pack").updateThemes();
8086
rebuild();
87+
require("./ninja.js").updateRelease();
8188
}
8289

83-
require("./ninja.js").updateRelease();
90+
8491
}
8592

8693
function createOCamlTar() {

0 commit comments

Comments
 (0)
Please sign in to comment.