Skip to content

Commit 1b6cf4a

Browse files
committed
Update README-dev.md
1 parent 142811b commit 1b6cf4a

File tree

1 file changed

+137
-26
lines changed

1 file changed

+137
-26
lines changed

README-dev.md

Lines changed: 137 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ npm run build
4646

4747
This command downloads the artifacts from github if they are missing and
4848
compiles the TypeScript source files, making them ready for use. The compiled
49-
OCaml and WebAssembly artifacts are cached for each commit where ci is run.These
50-
artifacts are stored under `src/bindings/compiled` and
49+
OCaml and WebAssembly artifacts are cached for each commit where CI is run.
50+
These artifacts are stored under `src/bindings/compiled` and
5151
`src/bindings/mina-transaction/gen` and contain the artifacts needed for both
5252
nodejs and web builds. These files only have to be regenerated if there are
5353
changes to the OCaml or Rust source files.
@@ -59,27 +59,27 @@ Unfortunately you generally won't be able to run
5959
won't have been built for them, so make sure to run it on main before you start
6060
making changes. In a fresh git repo `npm run build` also works.
6161

62-
Keep in mind that merging a newer version of o1js may include Ocaml and rust
62+
Keep in mind that merging a newer version of o1js may include OCaml and Rust
6363
changes so you may need to redownload the artifacts. When this happens, as long
64-
as you aren't making changes to the Ocaml and rust yourself, you can run
64+
as you aren't making changes to the OCaml and Rust yourself, you can run
6565
`REV=<commit you just merged> npm run build:bindings-download`, this will
6666
download the bindings for the commit you merged which should be the same as the
6767
ones you need.
6868

6969
### Internal contributors
7070

71-
If you have an open pr `npm run build:bindings-download` should work on any
72-
commit where ci has run or is running. If ci is still running it uses
71+
If you have an open PR `npm run build:bindings-download` should work on any
72+
commit where CI has run or is running. If CI is still running it uses
7373
`gh run watch` to show you the progress.
7474

75-
If your pr has a merge conflict, in which case CI will not run on each new
76-
commit, or you just don't have a pr you may can run
75+
If your PR has a merge conflict, in which case CI will not run on each new
76+
commit, or you just don't have a PR you may can run
7777
`npm run build:bindings-remote`. This will trigger our self-hosted runner to
7878
build the bindings for your commit and download them once it finishes.
7979

8080
## Building with nix
8181

82-
Much like the mina repo, we use the nix registry to conveniently handle git
82+
Much like the Mina repo, we use the nix registry to conveniently handle git
8383
submodules. You can enter the devshell with `./pin.sh` and
8484
`nix develop o1js#default` or by using direnv with the `.envrc` provided. This
8585
devshell provides all the dependencies required for npm scripts including
@@ -88,9 +88,10 @@ devshell provides all the dependencies required for npm scripts including
8888
## Building Bindings
8989

9090
To regenerate the OCaml and WebAssembly artifacts, you can do so within the o1js
91-
repo. The [bindings](https://github.com/o1-labs/o1js-bindings) and
92-
[Mina](https://github.com/MinaProtocol/mina) repos are both submodules of o1js
93-
so you can build them from within the o1js repo.
91+
repo. The [Mina](https://github.com/MinaProtocol/mina) repo is a submodule of
92+
o1js, and [proof-systems](https://github.com/o1-labs/proof-systems) is a
93+
submodule of [Mina](https://github.com/MinaProtocol/mina), so you can build them
94+
recursively from within the o1js repo.
9495

9596
o1js depends on OCaml code that is transpiled to JavaScript using
9697
[Js_of_ocaml](https://github.com/ocsigen/js_of_ocaml) and Rust code that is
@@ -115,16 +116,34 @@ you can build the bindings:
115116
npm run build:bindings-all
116117
```
117118

118-
This command builds the OCaml and Rust artifacts and copies them to the
119-
`src/bindings/compiled` directory.
119+
This command builds the OCaml and Rust Node & Web artifacts and copies them to
120+
the `src/bindings/compiled` directory.
121+
122+
You can also build only the OCaml and Rust Node bindings for local development
123+
by running:
124+
125+
```sh
126+
npm run build:bindings-node
127+
```
120128

121129
### Build Scripts
122130

123131
The root build script which kicks off the build process is under
124132
`src/bindings/scripts/update-o1js-bindings.sh`. This script is responsible for
125-
building the Node.js and web artifacts for o1js, and places them under
133+
building the Node.js and Web artifacts for o1js, and places them under
126134
`src/bindings/compiled`, to be used by o1js.
127135

136+
However, when first setting up your o1js development environment, simply run npm
137+
run:
138+
139+
```sh
140+
npm run build
141+
```
142+
143+
This command generates the Node bindings and compiles the project to JavaScript,
144+
allowing you to run both the existing examples and any new files as described
145+
[here](./src/examples/README.md).
146+
128147
### OCaml Bindings
129148

130149
o1js depends on Pickles, snarky, and parts of the Mina transaction logic, all of
@@ -134,12 +153,19 @@ natively. The OCaml bindings are located under `src/bindings`. See the
134153
for more information.
135154

136155
To compile the OCaml code, a build tool called Dune is used. Dune is a build
137-
system for OCaml projects, and is used in addition with Js_of_ocaml to compile
138-
the OCaml code to JavaScript. The dune file that is responsible for compiling
139-
the OCaml code is located under `src/bindings/ocaml/dune`. There are two build
140-
targets: `o1js_node` and `o1js_web`, which compile the Mina dependencies as well
141-
as link the wasm artifacts to build the Node.js and web artifacts, respectively.
142-
The output file is `o1js_node.bc.js`, which is used by o1js.
156+
system for OCaml projects, and is used in addition with Js_of_ocaml (JSOO) to
157+
compile the OCaml code to JavaScript. The dune file that is responsible for
158+
compiling the OCaml code is located under `src/bindings/ocaml/dune`. There are
159+
two build targets: `o1js_node` and `o1js_web`, which compile the Mina
160+
dependencies as well as link the wasm artifacts to build the Node.js and Web
161+
artifacts, respectively. The output file is `o1js_node.bc.js`, which is used by
162+
o1js.
163+
164+
For internal development and debugging, you can manually build the JSOO bindings
165+
for Node and Web using npm run `build:jsoo:node` and `npm run build:jsoo:web`,
166+
respectively. However, for typical local development, running the standard build
167+
commands automatically generates these bindings as part of the overall build
168+
process.
143169

144170
### WebAssembly Bindings
145171

@@ -162,6 +188,12 @@ For the Wasm build, the output files are:
162188
- `plonk_wasm.js`: JavaScript file that wraps the Wasm code for use in Node.js.
163189
- `plonk_wasm.d.ts`: TypeScript definition file for plonk_wasm.js.
164190

191+
Similarly, for internal development and debugging, you can manually build the
192+
WASM bindings for Node and Web using `npm run build:wasm:node` and
193+
`npm run build:wasm:web`, respectively. For typical local development, however,
194+
running the standard build commands automatically generates these bindings as
195+
part of the overall build process.
196+
165197
### Generated Constant Types
166198

167199
In addition to building the OCaml and Rust code, the build script also generates
@@ -176,7 +208,14 @@ files.
176208
o1js uses these types to ensure that the constants used in the protocol are
177209
consistent with the OCaml source files.
178210

179-
### Bindings check in ci
211+
This process is already performed as part of the bindings build, but you can
212+
regenerate the constant types separately by running:
213+
214+
```sh
215+
npm run build:bindings-transaction-layout
216+
```
217+
218+
### Bindings check in CI
180219

181220
If the bindings check fails in CI it will upload a patch you can use to update
182221
the bindings without having to rebuild locally. This can also be helpful when
@@ -188,9 +227,9 @@ To use this patch:
188227
- Go to the `patch-upload` job and expand the logs for `Upload patch`
189228
- Download the file linked in the last line of the logs ie.
190229
`Artifact download URL: https://github.com/o1-labs/o1js/actions/runs/12401083741/artifacts/2339952965`
191-
- unzip it
192-
- navigate to `src/bindings`
193-
- run `git apply path/to/bindings.patch`
230+
- Unzip it
231+
- Navigate to `src/bindings`
232+
- Run `git apply path/to/bindings.patch`
194233

195234
## Development
196235

@@ -260,7 +299,79 @@ to comply with the style:
260299
for all diffed files. Enable it by running `git config husky.optin true`
261300

262301
> [!NOTE] You can opt-out of linting in a PR by tagging it with skip-lint, in
263-
> case the linting script is legitimately blocking an important PR
302+
> case the linting script is legitimately blocking an important PR.
303+
304+
### Build Guide
305+
306+
To build the **o1js** project, simply run:
307+
308+
```sh
309+
npm run build
310+
```
311+
312+
This command builds the **Node bindings** and compiles the project’s TypeScript
313+
sources into JavaScript.
314+
315+
If you want to build **o1js** for both **Node** and **Web**, run:
316+
317+
```sh
318+
npm run build:bindings-all
319+
```
320+
321+
This script builds the bindings for **both** environments and compiles the
322+
project to JavaScript for Node and Web as well.
323+
324+
These are the two main build scripts.
325+
For more fine-grained local development and debugging, you can use the following
326+
targeted scripts.
327+
328+
---
329+
330+
#### TypeScript Build Scripts
331+
332+
| Command | Description |
333+
| ------------------------ | ------------------------------------------------------------------------------------------------------------ |
334+
| `npm run build:dev` | Builds the TypeScript source files and outputs the compiled JavaScript to the `dist/` directory. |
335+
| `npm run build` | Builds the full project for Node.js, ensuring all bindings are present and compiling the code to JavaScript. |
336+
| `npm run build:web` | Builds the project for Web (browser) usage, only generating a browser-compatible bundle. |
337+
| `npm run build:examples` | Compiles the example files located under `src/examples/`. |
338+
339+
---
340+
341+
#### Bindings Build Scripts
342+
343+
| Command | Description |
344+
| ------------------------------------------- | ------------------------------------------------------------------------------------------ |
345+
| `npm run build:bindings-node` | Builds the OCaml and Rust Node bindings used by o1js. |
346+
| `npm run build:bindings-transaction-layout` | Regenerates the TypeScript constant and transaction layout definitions from OCaml sources. |
347+
| `npm run build:wasm` | Builds all WebAssembly (WASM) bindings for both Node and Web. |
348+
| `npm run build:wasm:node` | Builds the Kimchi WASM bindings for Node.js. |
349+
| `npm run build:wasm:web` | Builds and optimizes the Kimchi WASM bindings for Web browsers. |
350+
| `npm run build:jsoo` | Builds all Js_of_OCaml (JSOO) bindings for both Node and Web. |
351+
| `npm run build:jsoo:node` | Builds the Js_of_OCaml Node bindings. |
352+
| `npm run build:jsoo:web` | Builds the Js_of_OCaml Web bindings. |
353+
354+
**Additional Utilities:**
355+
356+
| Command | Description |
357+
| --------------------------------- | -------------------------------------------------------------------- |
358+
| `npm run check:bindings` | Checks for existing prebuilt bindings (downloads them if available). |
359+
| `npm run build:bindings-download` | Downloads prebuilt bindings directly from the CI artifacts. |
360+
| `npm run build:bindings-remote` | Builds bindings remotely or in a containerized CI environment. |
361+
362+
---
363+
364+
#### Clean Scripts
365+
366+
You can also clean generated artifacts using the following scripts:
367+
368+
| Command | Description |
369+
| ------------------------- | ------------------------------------------------------------------------------------------------------ |
370+
| `npm run clean` | Removes build outputs such as `dist/` and Node bindings artifacts. |
371+
| `npm run clean:all` | Removes Node build artifacts generated by the o1js build process as well as test-related output files. |
372+
| `npm run clean:artifacts` | Removes compiled bindings and intermediate artifacts from OCaml, Kimchi, and proof-systems builds. |
373+
374+
---
264375

265376
### Running Tests
266377

0 commit comments

Comments
 (0)