Skip to content

Commit 208edcf

Browse files
committed
Minimal changes to allow developing with esy
1 parent 00ad78c commit 208edcf

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

4061.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"source": "./esy.json",
3+
"override": {
4+
"resolutions": {
5+
"ocaml": "ulrikstrid/ocaml:package.json#443a110eb57d9ca841d4f027a3c6dbf8a12cba45"
6+
}
7+
}
8+
}

CONTRIBUTING.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The extension requires using an opam switch for ocaml 4.02.3, where `merlin` and
3434
```
3535
./script/ninja.js docs
3636
```
37+
3738
#### Edit file and test changes
3839

3940
In general, you'd edit files and rerun `./scripts/ninja.js build`.
@@ -70,6 +71,30 @@ git -C ocaml checkout 4.06.1+BS && node ./scripts/buildocaml.js
7071

7172
Note: clean up is necessary since the binary artifacts between versions of compiler may be incompatible.
7273

74+
### Using esy in development
75+
76+
You can use [esy](https://esy.sh) to develop bucklescript. By default esy will do "out of source builds" which means that all the changes will happen outside the current directory. To be able to bspack the needed files and get sources that you can commit you will have to change the following in the `esy.json`.
77+
78+
```diff
79+
-"buildsInSource": true,
80+
+"buildsInSource": "unsafe",
81+
```
82+
83+
When that is changed you just run the following command it will build everything you need.
84+
85+
esy
86+
87+
By default we depend on the 4.02.3+BS OCaml compiler. To be able to build with the 4.06.1+BS compiler we have a `4061.json` file that just extends the `esy.json` and overrides the OCaml dependency. To use this file instead you simply run this command instead.
88+
89+
esy @4061
90+
91+
If there are problems building try to run one of the following depending on what you're building
92+
93+
```
94+
esy clean
95+
esy @4061 clean
96+
```
97+
7398
## Test on a Dummy Project
7499

75100
Go somewhere else and do this:
@@ -86,7 +111,6 @@ And whenever you modify a file in bucklescript, run this:
86111
npm install -g .
87112
```
88113

89-
90114
## Change the Vendored OCaml Compiler
91115

92116
This section is reserved for when you're making a change to the vendored ocaml compiler itself, in `ocaml`, and then testing on super-errors changes at the same time. If you're doing this for whatever reason, then the previous quick iteration workflow wouldn't work. Here's what you have to do after each change:
@@ -109,6 +133,7 @@ Currently all tests are in `jscomp/test` directory and you should either add/mod
109133

110134
- Add the filename in `jscomp/test/test.mllib`
111135
- Add a test suite. The specification is in `jscomp/test/mt.ml`. For example some simple tests would be like:
136+
112137
```ocaml
113138
let suites : _ Mt.pair_suites =
114139
["hey", (fun _ -> Eq(true, 3 > 2));
@@ -216,7 +241,7 @@ Since BuckleScript is distributed under the terms of the [LGPL Version 3](LICENS
216241
are licensed under the same terms. In order for us to be able to accept your contributions,
217242
we will need explicit confirmation from you that you are able and willing to provide them under
218243
these terms, and the mechanism we use to do this is called a Developer's Certificate of Origin
219-
[DCO](DCO.md). This is very similar to the process used by the Linux(R) kernel, Samba, and many
244+
[DCO](DCO.md). This is very similar to the process used by the Linux(R) kernel, Samba, and many
220245
other major open source projects.
221246

222247
To participate under these terms, all that you must do is include a line like the following as the

esy.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
"ocaml": "4.02.3000+BS"
99
},
1010
"resolutions": {
11-
"ocaml": "ulrikstrid/ocaml:package.json#e433d5b3fbe8963ac98257d1ed3b32c01515e07d"
11+
"ocaml": "bucklescript/ocaml:package.json#698e60f3cd2f442f2013e79860ce2f7b0a9624cb"
12+
},
13+
"scripts": {
14+
"clean": "node ./scripts/ninja.js clean"
1215
},
1316
"esy": {
1417
"buildsInSource": true,
@@ -18,10 +21,17 @@
1821
["cp", "-r", "-f", "#{self.root / 'esy.json'}", "#{self.install}"],
1922
["cp", "-r", "-f", "#{self.root / 'package.json'}", "#{self.install}"],
2023
["cp", "-r", "-f", "#{self.root / 'jscomp'}", "#{self.install}"],
24+
["cp", "-r", "-f", "#{self.root / 'jscomp' / 'bin'}", "#{self.install}"],
2125
["cp", "-r", "-f", "#{self.root / 'lib'}", "#{self.install}"],
2226
["cp", "-r", "-f", "#{self.root / 'scripts'}", "#{self.install}"],
2327
["cp", "-r", "-f", "#{self.root / 'vendor'}", "#{self.install}"]
2428
],
29+
"buildDev": [
30+
["echo", "config"],
31+
["node", "./scripts/ninja.js", "config"],
32+
["echo", "build"],
33+
["node", "./scripts/ninja.js", "build"]
34+
],
2535
"buildEnv": {
2636
"ESY": "true"
2737
},

scripts/ninja.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ var useEnv = false;
115115
* Note ocamldep.opt has built-in macro handling OCAML_VERSION
116116
*/
117117
var getOcamldepFile = () => {
118-
if (useEnv) {
118+
if (useEnv || process.env.ESY === "true") {
119119
return `ocamldep.opt`;
120120
} else {
121121
return path.join(
@@ -1479,6 +1479,7 @@ function setSortedToString(xs) {
14791479
* @returns {string}
14801480
*/
14811481
function getVendorConfigNinja() {
1482+
if (process.env.ESY === "true") return getEnnvConfigNinja();
14821483
var prefix = `../native/${require("./buildocaml.js").getVersionPrefix()}/bin`;
14831484
return `
14841485
ocamlopt = ${prefix}/ocamlopt.opt
@@ -1492,6 +1493,7 @@ function getEnnvConfigNinja() {
14921493
ocamlopt = ocamlopt.opt
14931494
ocamllex = ocamllex.opt
14941495
ocamlmklib = ocamlmklib
1496+
ocaml = ocaml
14951497
`;
14961498
}
14971499

@@ -1750,7 +1752,7 @@ function main() {
17501752
switch (subcommand) {
17511753
case "build":
17521754
try {
1753-
cp.execFileSync(vendorNinjaPath, {
1755+
cp.execFileSync(path.resolve(jscompDir, vendorNinjaPath), {
17541756
encoding: "utf8",
17551757
cwd: jscompDir,
17561758
stdio: [0, 1, 2]

0 commit comments

Comments
 (0)