Aug 12, 2019

Announcing BuckleScript 5.1.0

Hongbo Zhang
Compiler & Build System

Important: This is an archived blog post, kept for historical reasons. Please note that this information might be outdated.

New Release

bs-platform 5.1.0 (for OCaml 4.02.3) and 6.1.0 (for OCaml 4.06.1) is ready for testing.

You can install it via npm i -g bs-platform@5.1.0 (or npm i -g bs-platform@6.1.0-dev.6).

A detailed list of changes is available here

Some feature enhancements are described as follows:

Introducing bsc to public

bsc is the underlying compiler which is invoked by bsb. In this release we simplified it a bit so that it can be used directly by customers for simple tasks. It is available after you have bs-platform installed.

Suppose you have a file called test.re:

RE
let rec fib = n => switch (n) { | 0 | 1 => 1 | n => fib(n - 1) + fib(n - 2) }; Js.log(fib(0));

You can compile it directly via bsc test.re, producing the following output:

JS
bucklescript.github.io>bsc test.re // Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE 'use strict'; function fib(n) { if (n === 0 || n === 1) { return 1; } else { return fib(n - 1 | 0) + fib(n - 2 | 0) | 0; } } console.log(fib(0)); exports.fib = fib; /* Not a pure module */

You can also get the inferred signature directly via bsc -i test.re

RE
let fib: int => int;

Or even better, you can do a one liner in bsc, via -e option.

bucklescript>bsc -i -e 'let id = x => x' let id: 'a => 'a;

Note: bsc supports vanilla OCaml syntax as well, this is only recommended for toying around, for serious development, bsb is recommended.

bstracing to visualize build profile

After you finish the build process, you can run bstracing directly. This generates a data file called tracing_${hour}_${minute}_${second}.json which can be loaded into chrome via chrome://tracing.

Below is a profile image that shows the tracing graph for a large project:

And you can zoom-in to see more details:

Support of ppx with arguments

We extended the schema to support ppx with arguments:

JSON
{ "ppx-specs": { "type": "array", "items": { "oneOf" : [ { "type": "string" // single command }, { "type" : "array", // command with args "items": { "type" : "string" } } ] } } }

Respect NODE_PATH when resolving dependent modules

Previously, bsb was tied to npm package structures by searching node_modules. In this release, bsb also tries to search paths listed in NODE_PATH so that bsb is no longer tied to the npm or yarn package manager.

Build performance improvement

Yes, performance is increased with each release!

Quite a lot of work was spent in house-keeping this release. We changed the internal data representation to a more compact format. Here is the result of using bstracing to show a comparison of clean building a large project around (2 * 5 * 5 * 5 * 5 = 1250 files):

Version 5.0.6 (around 4.8s)

Version 5.1.0 (around 4.2s)

Happy hacking!

Want to read more?
Back to Overview