bsb-native
Bsb-native is like bsb, but compiles to native OCaml instead.
Install
- Add
"bsb-native": "bsansouci/bsb-native"
as a devDependency to your package.json
- Add a
bsconfig.json
like you would for bsb. Bsb-native uses the same schema, located here
For example:
{
"name" : "NameOfLibrary",
"sources" : "src",
"entries": [{
"kind": "bytecode",
"main": "Index"
}]
}
Run
./node_modules/.bin/bsb
(or add an npm script to simply run bsb
)
Useful flags
The -make-world
flag builds all of the dependencies.
The -w
enabled the watch mode which will rebuild on any source file change.
The -backend [js|bytecode|native]
flag tells bsb-native
to build all entries in the bsconfig.json
to either js
, bytecode
or native
.
The build artifacts are put into the folder lib/bs
. The bytecode executable would be at lib/bs/bytecode/index.byte
and the native one at lib/bs/native/index.native
.
Multi-target
bsb-native
actually supports building Reason/OCaml to JS as well as to native/bytecode. What that enables is code that is truly cross platform, that depends on a JS implementation of a library or a native implementation, and bsb-native will build the right implementation depending on what you target.
For example, you can write code that depends on the module Reasongl, and bsb-native will use ReasonglNative
as the implementation for Reasongl when building to native/bytecode or it'll use ReasonglWeb
when building to JS.
Currently the way this works is to have each platform specific dependency expose a module with the same name and rely on the field allowed-build-kinds
in the bsconfig.json
to tell bsb-native which one of platform specific dep you want to build, given that you want to build the whole project to a specific target. Say you target JS, then ReasonglWeb will get built which exposes its own Reasongl module.