Skip to content

Commit 78e4f5d

Browse files
authored
Merge pull request #3854 from ulrikstrid/develop-with-esy
Minimal changes to allow developing with esy
2 parents 91b5cfe + 7c2bcee commit 78e4f5d

File tree

4 files changed

+61
-6
lines changed

4 files changed

+61
-6
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": "bucklescript/ocaml:package.json#4582c3fcce632aaa0f9794f5518bf5d9ad4a6385"
6+
}
7+
}
8+
}

CONTRIBUTING.md

Lines changed: 26 additions & 1 deletion
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 (experimental)
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));

esy.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"resolutions": {
1111
"ocaml": "bucklescript/ocaml:package.json#698e60f3cd2f442f2013e79860ce2f7b0a9624cb"
1212
},
13+
"scripts": {
14+
"clean": "node ./scripts/ninja.js clean"
15+
},
1316
"esy": {
1417
"buildsInSource": true,
1518
"build": [
@@ -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: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var othersTarget = pseudoTarget("others");
2828
var stdlibTarget = pseudoTarget("$stdlib");
2929

3030
var vendorNinjaPath = path.join(
31+
__dirname,
3132
"..",
3233
"vendor",
3334
"ninja",
@@ -115,7 +116,7 @@ var useEnv = false;
115116
* Note ocamldep.opt has built-in macro handling OCAML_VERSION
116117
*/
117118
var getOcamldepFile = () => {
118-
if (useEnv) {
119+
if (useEnv || process.env.ESY === "true") {
119120
return `ocamldep.opt`;
120121
} else {
121122
return path.join(
@@ -1479,6 +1480,7 @@ function setSortedToString(xs) {
14791480
* @returns {string}
14801481
*/
14811482
function getVendorConfigNinja() {
1483+
if (process.env.ESY === "true") return getEnnvConfigNinja();
14821484
var prefix = `../native/${require("./buildocaml.js").getVersionPrefix()}/bin`;
14831485
return `
14841486
ocamlopt = ${prefix}/ocamlopt.opt
@@ -1492,6 +1494,7 @@ function getEnnvConfigNinja() {
14921494
ocamlopt = ocamlopt.opt
14931495
ocamllex = ocamllex.opt
14941496
ocamlmklib = ocamlmklib
1497+
ocaml = ocaml
14951498
`;
14961499
}
14971500

@@ -1782,10 +1785,19 @@ function main() {
17821785

17831786
break;
17841787
case "cleanbuild":
1785-
console.log(`run cleaning first`)
1786-
cp.execSync(`node ${__filename} clean`,{cwd:__dirname,stdio:[0,1,2]})
1787-
cp.execSync(`node ${__filename} config`,{cwd:__dirname,stdio:[0,1,2]})
1788-
cp.execSync(`node ${__filename} build`,{cwd:__dirname,stdio:[0,1,2]})
1788+
console.log(`run cleaning first`);
1789+
cp.execSync(`node ${__filename} clean`, {
1790+
cwd: __dirname,
1791+
stdio: [0, 1, 2]
1792+
});
1793+
cp.execSync(`node ${__filename} config`, {
1794+
cwd: __dirname,
1795+
stdio: [0, 1, 2]
1796+
});
1797+
cp.execSync(`node ${__filename} build`, {
1798+
cwd: __dirname,
1799+
stdio: [0, 1, 2]
1800+
});
17891801
break;
17901802
case "docs":
17911803
console.log(`building docs`);

0 commit comments

Comments
 (0)