Skip to content

Commit ab0969d

Browse files
oxbsansouci
authored andcommitted
create default native init package (rescript-lang#24)
* replace the basic theme Reason project with the bsb-native example * note behavior to create a new project * add back bs-dependencies to basic template bsconfig; code review nits * add back code review nit; rebase off master
1 parent 64bbcc5 commit ab0969d

File tree

7 files changed

+55
-52
lines changed

7 files changed

+55
-52
lines changed

README.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Bsb-native is a fork of [bsb](http://bucklescript.github.io/bucklescript/Manual.
88
2) Add a `bsconfig.json` like you would for bsb. Bsb-native uses the same schema, located [here](http://bucklescript.github.io/bucklescript/docson/#build-schema.json) with small additions like `entries`.
99
3) run `npm install`
1010

11-
For [example](https://github.com/bsansouci/BetterErrors/tree/bsb-support):
11+
An [example bsconfig.json](https://github.com/bsansouci/BetterErrors/tree/bsb-support):
1212
```json
1313
{
1414
"name" : "NameOfLibrary",
@@ -25,6 +25,16 @@ For [example](https://github.com/bsansouci/BetterErrors/tree/bsb-support):
2525

2626
That will pickup the first entry's `backend` and build all entries to that `backend`. e.g if you have multiple `bytecode` targets, they'll all get built but not the `js` ones nor `native` ones. If you want to build to all targets you need to run the build command multiple times with different `-backend`.
2727

28+
## Initialize a new package
29+
30+
Bsb-native comes with a basic init package to get you started. To create a package named Hello run:
31+
32+
```sh
33+
bsb -init Hello
34+
```
35+
36+
And a folder named `Hello` will be created with a basic project layout. If you want to initialize an already created folder, use `.` as the last argument.
37+
2838
## Useful flags
2939
The `-make-world` flag builds all of the dependencies and the project.
3040

@@ -37,7 +47,7 @@ The `-backend [js|bytecode|native]` flag tells `bsb-native` to build all entries
3747
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` for example.
3848

3949
## Opam packages
40-
Yes `bsb-native` supports opam packages (see [ocamlfind example](https://github.com/bsansouci/bsb-native-example/tree/opam-example)).
50+
Yes `bsb-native` supports opam packages (see [ocamlfind example](https://github.com/bsansouci/bsb-native-example/tree/opam-example)).
4151
**BUT** you need to be on the switch `4.02.3+buckle-master` (which you can get to by running `opam switch 4.02.3+buckle-master`).
4252
```js
4353
{
@@ -54,11 +64,11 @@ Yes `bsb-native` supports opam packages (see [ocamlfind example](https://github.
5464
## bsconfig.json schema
5565
```js
5666
{
57-
// All of the bsb fields will work as expected. Here are just the added
67+
// All of the bsb fields will work as expected. Here are just the added
5868
// features.
5969

6070
// Entries is an array of targets to be built.
61-
// When running `bsb -backend bytecode`, bsb will filter this array for
71+
// When running `bsb -backend bytecode`, bsb will filter this array for
6272
// all the entries compiling to bytecode and compile _all_ of those.
6373
"entries": [{
6474
"backend": "bytecode", // can be "bytecode" (ocamlc), "js" (bsc) or "native" (ocamlopt),
@@ -67,22 +77,22 @@ Yes `bsb-native` supports opam packages (see [ocamlfind example](https://github.
6777

6878
// Array of opam dependencies.
6979
"ocamlfind-dependencies": ["lwt.unix"],
70-
71-
// Array of built-in ocaml dependencies that are not Pervasives (ie not
80+
81+
// Array of built-in ocaml dependencies that are not Pervasives (ie not
7282
// linked by default).
7383
// This is useful for making a ppx, where you need "compiler-libs".
74-
// All of these except "compiler-libs" is linked by default, so you don't
75-
// have to worry about it. That said it does increase the binary size so
84+
// All of these except "compiler-libs" is linked by default, so you don't
85+
// have to worry about it. That said it does increase the binary size so
7686
// you can remove unused things here.
7787
"ocaml-dependencies": ["bigarray", "unix", "threads", "compiler-libs"],
78-
79-
// Array of flags to pass the OCaml compiler. This shouldn't be needed for
88+
89+
// Array of flags to pass the OCaml compiler. This shouldn't be needed for
8090
// most things.
8191
"ocaml-flags": ["-bin-annot"],
8292

83-
// This allows you to write JS specific packages (for example) and depend
93+
// This allows you to write JS specific packages (for example) and depend
8494
// on them without bsb choking on them when building to another platform.
85-
// If you have `MyLibJs` which exposes a module `Bla`, and `MyLibNative`
95+
// If you have `MyLibJs` which exposes a module `Bla`, and `MyLibNative`
8696
// which also exposes `Bla`, the compiler will use the native `Bla` when
8797
// compiling to native and the JS `Bla` when compiling to JS thanks to this
8898
// flag.
@@ -95,7 +105,7 @@ Yes `bsb-native` supports opam packages (see [ocamlfind example](https://github.
95105
"static-libraries": ["lib/c/my_lib.o"],
96106

97107
// Command invoked first, before bsb tries to build anything else.
98-
// Useful for building C code linked into the exec using
108+
// Useful for building C code linked into the exec using
99109
// `static-libraries`.
100110
"build-script": "make",
101111

@@ -123,4 +133,3 @@ include
123133
}];
124134
```
125135
inside a file called `MyModule` (for example). Then when you build to JS that module will use the `MyModule_Js` implementation. Same for native/bytecode. This is deeply integrated into bsb-native to make everything easier.
126-

jscomp/bsb/templates/basic/.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
*.annot
1919
*.cmj
2020
*.bak
21-
lib/bs
2221
*.mlast
2322
*.mliast
2423
.vscode
25-
.merlin
24+
.merlin
25+
26+
lib/bs
27+
node_modules

jscomp/bsb/templates/basic/README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
bsb-native-example
2+
---
13

4+
This is a quick demo project to showcase [bsb-native](https://github.com/bsansouci/bsb-native).
25

3-
# Build
4-
```
5-
npm run build
6-
```
6+
For publishing on opam see [opam_of_packagejson](https://github.com/bsansouci/opam_of_packagejson/) as a helper.
77

8-
# Watch
98

10-
```
11-
npm run watch
12-
```
9+
## Install
10+
`npm i`
1311

12+
## Build bytecode
13+
`npm run build`
1414

15-
# Editor
16-
If you use `vscode`, Press `Windows + Shift + B` it will build automatically
15+
To build other targets (like native or js) you can call bsb directly (or add a npm script) with the `-backend` flag, like `./node_nodules/.bin/bsb -backend native` or `./node_nodules/.bin/bsb -backend js`.
16+
17+
## Run
18+
`./lib/bs/bytecode/index.byte`
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
{
22
"name": "${bsb:name}",
33
"version": "${bsb:proj-version}",
4-
"sources": {
5-
"dir" : "src",
6-
"subdirs" : true
7-
},
8-
"package-specs": {
9-
"module": "commonjs",
10-
"in-source": true
11-
},
12-
"suffix": ".bs.js",
4+
"sources": "src",
5+
"entries": [{
6+
"backend": "bytecode",
7+
"main-module": "Index"
8+
},{
9+
"backend": "native",
10+
"main-module": "Index"
11+
}],
1312
"bs-dependencies": [
14-
// add your bs-dependencies here
13+
// add your bs-dependencies here
1514
],
16-
"warnings": {
17-
"error" : "+101"
18-
}
19-
}
15+
"refmt": 3
16+
}

jscomp/bsb/templates/basic/package.json

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22
"name": "${bsb:name}",
33
"version": "${bsb:proj-version}",
44
"scripts": {
5-
"clean": "bsb -clean-world",
65
"build": "bsb -make-world",
7-
"watch": "bsb -make-world -w"
6+
"clean": "bsb -clean-world",
7+
"start": "./lib/bs/bytecode/index.byte"
88
},
9-
"keywords": [
10-
"BuckleScript"
11-
],
12-
"author": "",
13-
"license": "MIT",
149
"devDependencies": {
15-
"bs-platform": "^${bsb:bs-version}"
10+
"bs-platform": "bsansouci/bsb-native"
1611
}
17-
}
12+
}

jscomp/bsb/templates/basic/src/demo.ml

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print_endline("Hello world");

0 commit comments

Comments
 (0)