Compile rescript-compiler

Hi,
I would like to use ReScript, compilation of rescript-compiler (60a1c04e) failed at this step:

$ npm install # install some JS tools for testing purposes
.....
bsb: [1/4] ../linux/bsb_helper.exe
bsb: [2/4] ../linux/bsb.exe
bsb: [3/4] ../linux/bsc.exe
FAILED: ../linux/bsc.exe
/home/bp/rescript-compiler/native/4.06.1/bin/ocamlopt.opt -O2  -nodynlink -I 4.06.1 -g -w -a ../jscomp/stubs/ext_basic_hash_stubs.c -w A-4-9-48-40-45-41-44-50-21-30-32-34-37-27-60-42 -warn-error A      4.06.1/whole_compiler.mli 4.06.1/whole_compiler.ml -o ../linux/bsc.exe && strip ../linux/bsc.exe
File "ext_int.ml", line 32, characters 11-24:
Error: Integer literal exceeds the range of representable integers of type int
bsb: [4/4] ../linux/refmt.exe
FAILED: cannot make progress due to previous errors.
child_process.js:650
    throw err;
    ^

Error: Command failed: /home/bp/rescript-compiler/linux/ninja.exe -f release.ninja -v
    at checkExecSyncError (child_process.js:629:11)
    at Object.execFileSync (child_process.js:647:13)
    at provideCompiler (/home/bp/rescript-compiler/scripts/install.js:211:8)
    at Object.<anonymous> (/home/bp/rescript-compiler/scripts/install.js:222:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bs-platform@8.4.0 postinstall: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the bs-platform@8.4.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/bp/.npm/_logs/2020-12-29T11_21_02_660Z-debug.log

I tried npm install -g bs-platform first, but it fails too, this is why I’m trying to compile the sources.

Looks like you are trying to build the rescript compiler locally, so you need to set up your machine to compile the OCaml compiler / ReScript compiler from scratch. Otherwise you can’t really npm install the non-existing binaries.

Check out the CONTRIBUTING.md on how to do the initial compilation setup.

Edit:

oh wait, what was the error message when installing from npm?

(I never had any problem compiling OCaml on Linux (OCaml is only difficult to compile on windows).

Yes, I followed carefully the steps from CONTRIBUTING.md, the first 2 commands seem to run fine, the third one npm install seems to fail:

$ git submodule update --init # we vendor a fork of ocaml and a syntax repo
$ node scripts/buildocaml.js # buid the vendored ocaml compiler
$ npm install # install some JS tools for testing purposes
[...]
bsb: [1/4] ../linux/bsb_helper.exe
bsb: [2/4] ../linux/bsb.exe
bsb: [3/4] ../linux/bsc.exe
FAILED: ../linux/bsc.exe
/home/bp/rescript-compiler/native/4.06.1/bin/ocamlopt.opt -O2  -nodynlink -I 4.06.1 -g -w -a ../jscomp/stubs/ext_basic_hash_stubs.c -w A-4-9-48-40-45-41-44-50-21-30-32-34-37-27-60-42 -warn-error A      4.06.1/whole_compiler.mli 4.06.1/whole_compiler.ml -o ../linux/bsc.exe && strip ../linux/bsc.exe
File "ext_int.ml", line 32, characters 11-24:
Error: Integer literal exceeds the range of representable integers of type int
bsb: [4/4] ../linux/refmt.exe
FAILED: cannot make progress due to previous errors.
child_process.js:650
    throw err;
    ^

Error: Command failed: /home/bp/rescript-compiler/linux/ninja.exe -f release.ninja -v
    at checkExecSyncError (child_process.js:629:11)
    at Object.execFileSync (child_process.js:647:13)
    at provideCompiler (/home/bp/rescript-compiler/scripts/install.js:211:8)
    at Object.<anonymous> (/home/bp/rescript-compiler/scripts/install.js:222:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bs-platform@8.4.0 postinstall: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the bs-platform@8.4.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/bp/.npm/_logs/2020-12-29T11_21_02_660Z-debug.log

$ tail -20 /home/bp/.npm/_logs/2020-12-29T11_21_02_660Z-debug.log
5389 verbose stack Exit status 1
5389 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
5389 verbose stack     at EventEmitter.emit (events.js:198:13)
5389 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
5389 verbose stack     at ChildProcess.emit (events.js:198:13)
5389 verbose stack     at maybeClose (internal/child_process.js:982:16)
5389 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
5390 verbose pkgid bs-platform@8.4.0
5391 verbose cwd /home/bp/rescript-compiler
5392 verbose Linux 5.7.19-desktop-1.mga7
5393 verbose argv "/usr/bin/node" "/usr/bin/npm" "install"
5394 verbose node v10.22.1
5395 verbose npm  v6.14.6
5396 error code ELIFECYCLE
5397 error errno 1
5398 error bs-platform@8.4.0 postinstall: `node scripts/install.js`
5398 error Exit status 1
5399 error Failed at the bs-platform@8.4.0 postinstall script.
5399 error This is probably not a problem with npm. There is likely additional logging output above.
5400 verbose exit [ 1, true ]
# npm install -g bs-platform 
/usr/bin/bsb -> /usr/lib/node_modules/bs-platform/bsb
/usr/bin/bsc -> /usr/lib/node_modules/bs-platform/bsc
/usr/bin/bstracing -> /usr/lib/node_modules/bs-platform/lib/bstracing
/usr/bin/bsrefmt -> /usr/lib/node_modules/bs-platform/bsrefmt

> bs-platform@8.4.2 postinstall /usr/lib/node_modules/bs-platform
> node scripts/install.js

ninja not compatible? Error: Command failed: "/usr/lib/node_modules/bs-platform/linux/ninja.exe" --version
building ninja
fs.js:114
    throw err;
    ^

Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/bs-platform/vendor/ninja'
    at Object.mkdirSync (fs.js:757:3)
    at ensureExists (/usr/lib/node_modules/bs-platform/scripts/install.js:104:8)
    at build_ninja (/usr/lib/node_modules/bs-platform/scripts/install.js:39:5)
    at provideNinja (/usr/lib/node_modules/bs-platform/scripts/install.js:94:3)
    at Object.<anonymous> (/usr/lib/node_modules/bs-platform/scripts/install.js:220:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bs-platform@8.4.2 postinstall: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the bs-platform@8.4.2 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-12-29T19_02_33_811Z-debug.log

# tail /root/.npm/_logs/2020-12-29T19_02_33_811Z-debug.log
88 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "bs-platform"
89 verbose node v10.22.1
90 verbose npm  v6.14.6
91 error code ELIFECYCLE
92 error errno 1
93 error bs-platform@8.4.2 postinstall: `node scripts/install.js`
93 error Exit status 1
94 error Failed at the bs-platform@8.4.2 postinstall script.
94 error This is probably not a problem with npm. There is likely additional logging output above.
95 verbose exit [ 1, true ]

Or maybe there’s a binary executable ready for use?

it looks more like a directory access problem. You need to check if you installed npm / node correctly / check if the user has dir access, so that the postinstall script can move the platform relevant binary.

it seems you are compiling it on a 32-bit platform, can you do it on a 64-bit?

About npm install -g bs-platform, I run it under root, so it should be able to create any directory:

# npm install -g bs-platform
[...]
Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/bs-platform/vendor/ninja'
# mkdir -p /usr/lib/node_modules/bs-platform/vendor/ninja
# ls /usr/lib/node_modules/bs-platform/vendor/
ninja/

About compiling the sources,

FAILED: ../linux/bsc.exe
/home/bp/rescript-compiler/native/4.06.1/bin/ocamlopt.opt -O2  -nodynlink -I 4.06.1 -g -w -a ../jscomp/stubs/ext_basic_hash_stubs.c -w A-4-9-48-40-45-41-44-50-21-30-32-34-37-27-60-42 -warn-error A      4.06.1/whole_compiler.mli 4.06.1/whole_compiler.ml -o ../linux/bsc.exe && strip ../linux/bsc.exe
File "ext_int.ml", line 32, characters 11-24:
Error: Integer literal exceeds the range of representable integers of type int
bsb: [4/4] ../linux/refmt.exe

Is it possible to compile / install / use ReScript on a 32bit computer?

Error: Integer literal exceeds the range of representable integers of type int

This error look like trying to make 64 bits computations on 32 bit computer, isn’t it?

With the git version, I found this:

$ tail -12 jscomp/ext/ext_int.ml

type t = int

let compare (x : t) (y : t) = Pervasives.compare x y 

let equal (x : t) (y : t) = x = y

let move = 0x1_0000_0000
(* works only on 64 bit platform *)
let int32_unsigned_to_int (n : int32) : int =
     let i = Int32.to_int n in (if i < 0 then i + move else i)

But with release 8.4.2, I found this:

$ tail jscomp/ext/ext_int.ml

type t = int

let compare (x : t) (y : t) = Pervasives.compare x y 

let equal (x : t) (y : t) = x = y

Unfortunately the compilation steps explained in CONTRIBUTING.md are not working with the release tarball.

Indeed, I will probably be able to do it in a near or far future, but as long as my old computer still works, I’ll still use it :slight_smile:

I think that it’s possible to compile for a 32-bit target on a 64-bit platform.

$ ocaml
        OCaml version 4.11.1

# 0x1_0000_0000 ;;
Error: Integer literal exceeds the range of representable integers of type int

If you want ReScript to be packaged in Linux distributions, I think most distros still create packages for 32-bit platforms.

1 Like

We used to support 32 bits, but later some small things make it more and more difficult.
Modulo things you mentioned above, we embed the whole stdlib in the compiler so that compiler is a single file, this requires a special Marshal format which is cross platform only for 64 bits, if we need target 32 bits, we need keep a separate copy for that too

1 Like

Is there an older version I could use?
(I’ll try to check the git history)
Is an older version be good enough for use?

Hi, the 32 bit is never thoroughly tested, I feel sorry about this.

I should maybe consider this as an opportunity for contributing :slight_smile:

3 Likes

I git checkout 8.4.2 then following the build instructions I got an error message about file “lam_convert.ml” at line 415, then based on Hongbo’s informations, I edited lib/4.06.1/whole_compiler.ml to find the same line of the same file embeded, and changed the line for:

      | Max_wosize -> Lam.const (Const_int {value = 1073741823; comment = Some "Max_wosize"})

I just put a number that will not exceed the range of a representable 31-bit integer, I don’t know if this value is a good choice or not, but at least with only this single modification the compilation succeed until the end, and I get a rescript compiler that is able to produce a hello world.

If there are more tests that I can run to check if this build does what is expected from it, I will be happy to run it and provide feedback.