Skip to content

Latest commit

 

History

History
137 lines (99 loc) · 3.65 KB

Compiler-options.adoc

File metadata and controls

137 lines (99 loc) · 3.65 KB

Extended compiler options

This section is only for people who want roll their own build system instead of using the recommended build system: [BuckleScript build system: bsb], in general, it is safe to skip this section. It also adds some tips for people who debug the compiler.

BuckleScript inherits the command line arguments of the OCaml compiler. It also adds several flags:

-bs-main (single directory build)

bsc.exe -bs-main Main

bsc.exe will build module Main and all its dependencies and when it finishes, it will run node main.js.

bsc.exe -c -bs-main Main

The same as above, but will not run node.

-bs-files

So that you can do

bsc.exe -c -bs-files *.ml *.mli

the compiler will sort the order of input files before starting compilation.

BuckleScript supports two compilation modes: script mode and package mode. In package mode, you have to provide package.json on top and set the options -bs-package-name, -bs-package-output. In script mode, such flags are not needed.

-bs-package-name

The project name of your project. The user is suggested to make it consistent with the name field in package.json

-bs-package-output

The format is module_system:oupt/path/relative/to/package.json Currently supported module systesms are: commonjs, amdjs and es6.

For example, when you want to use the es6 module system, you can do things like this:

bsc.exe -bs-package-name your_package -bs-package-output es6:lib/es6 -c xx.ml
Note
The user can supply multiple -bs-package-output at the same time.

For example:

bsc.exe -bs-package-name name -bs-package-output commonjs:lib/js  -bs-package-output amdjs:lib/amdjs -c x.ml

It will generate x.js in lib/js as a commonjs module, lib/amdjs as an amdjs module at the same time.

You would then need a bundler for the different module systems: webpack supports commonjs and amdjs while google closure compiler supports all.

-bs-no-warn-ffi-type

Turn off warnings on FFI type declarations.

-bs-eval

Example
bsc.exe -dparsetree -drawlambda -bs-eval 'Js.log "hello"'
[ // (1)
  structure_item (//toplevel//[1,0+0]..[1,0+14])
    Pstr_eval
    expression (//toplevel//[1,0+0]..[1,0+14])
      Pexp_apply
      expression (//toplevel//[1,0+0]..[1,0+6])
        Pexp_ident "Js.log" (//toplevel//[1,0+0]..[1,0+6])
      [
        <label> ""
          expression (//toplevel//[1,0+7]..[1,0+14])
            Pexp_constant Const_string("hello",None)
      ]
]
// (2)
(setglobal Bs_internal_eval! (seq (js_dump "hello") (makeblock 0)))
// Generated by BUCKLESCRIPT VERSION 1.0.2 , PLEASE EDIT WITH CARE
'use strict';


console.log("hello");

/*  Not a pure module */
  1. Output by flag -dparsetree

  2. Output by flag -drawlambda

For this flag, it will not create any intermediate file, which is useful for learning or troubleshooting.

-bs-no-builtin-ppx-ml, -bs-no-builtin-ppx-mli

If the user doesn’t use any bs specific annotations, the user can explicitly turn it off. Another use case is that users can use -ppx explicitly as below:

bsc.exe -c -ppx bsppx.exe -bs-no-builtin-ppx-ml c.ml

-bs-no-version-header

Don’t print version header.