···1717 `git status`)
181819192. Configure your source tree by running:
2020-2121- ./configure
2020++
2121+[source,sh]
2222+----
2323+./configure
2424+----
222523263. Bring your system to a stable state. Concretely, this means that the
2427 boot/ directory should contain a version of ocamlrun and all the
2528 \*.cm* files of the standard library. This stable state can be reached
2629 by running
2727-2828- make world
3030++
3131+[source,sh]
3232+----
3333+make world
3434+----
2935+
3036(Actually, running `make coldstart` should be enough but `make world` is
3137safer. Similarly, `make world.opt` will also bring you to such a stable
···3743 represented or anything else in the format of .cmi files, etc.
384439455. Run:
4040-4141- make coreall
4646++
4747+[source,sh]
4848+----
4949+make coreall
5050+----
4251+
4352This will rebuild runtime/ocamlrun, ocamlc, etc.
445345546. (optional) The new system can now be tested:
4646-4747- echo 'let _ = print_string "Hello world!\n"' > foo.ml
4848- ./boot/ocamlrun ./ocamlc -I ./stdlib foo.ml
4949- ./runtime/ocamlrun a.out
5555++
5656+[source,sh]
5757+----
5858+echo 'let _ = print_string "Hello world!\n"' > foo.ml
5959+./boot/ocamlrun ./ocamlc -I ./stdlib foo.ml
6060+./runtime/ocamlrun a.out
6161+----
506251637. We now know the system works and can thus build the new boot/
5264 binaries:
5353-5454- make bootstrap
6565++
6666+[source,sh]
6767+----
6868+make bootstrap
6969+----
55705671== Problems
5772···779278932. Create a temporary stub with the old primitive's name. This stub simply
7994 passes its arguments on to the new primitive:
8080-8181- CAMLprim value caml_old_primitive(value a1, value a2) {
8282- return caml_new_primitive(a1, a2);
8383- }
9595++
9696+[source,c]
9797+----
9898+CAMLprim value caml_old_primitive(value a1, value a2) {
9999+ return caml_new_primitive(a1, a2);
100100+}
101101+----
84102851033. Deal with the addition of the new primitive:
8686-8787- make coldstart
104104++
105105+[source,sh]
106106+----
107107+make coldstart
108108+----
88109891104. Ensure the system still works:
9090-9191- make coreall
111111++
112112+[source,sh]
113113+----
114114+make coreall
115115+----
92116931175. Now remove the old primitive stub and issue:
9494-9595- make bootstrap
118118++
119119+[source,sh]
120120+----
121121+make bootstrap
122122+----
9612397124It is desirable for bootstraps to be easily repeatable, so you should commit
98125changes after step 4.
···1021291. Start with a working build of the compiler eg `./configure && make world`
1031301041312. Remove uses of the primitive, but not the primitive itself. Then ensure the system still works:
105105-106106- make coreall
132132++
133133+[source,sh]
134134+----
135135+make coreall
136136+----
1071371081383. Then, and only then, remove the primitive, and run:
109109-110110- make coreall
111111- make bootstrap
139139++
140140+[source,sh]
141141+----
142142+make coreall
143143+make bootstrap
144144+----
112145113146== Bootstrap test script
114147···119152a primitive from the runtime. It then makes sure the bootstrap still
120153works after these changes. This script can be run locally as follows:
121154122122- OCAML_ARCH=linux ./tools/ci/inria/bootstrap
155155+[source,sh]
156156+----
157157+OCAML_ARCH=linux ./tools/ci/inria/bootstrap
158158+----
+20
HACKING.adoc
···121213131. Create a new git branch to store your changes.
1414+
1515+[source,sh]
1516----
1617git checkout -b my-modification
1718----
···252626272. Consult link:INSTALL.adoc[] for build instructions. Here is the gist of it:
2728+
2929+[source,sh]
2830----
2931./configure
3032make -j 4
···36383. Try the newly built compiler binaries `ocamlc`, `ocamlopt` or their
3739`.opt` version. To try the toplevel, use:
3840+
4141+[source,sh]
3942----
4043make runtop
4144----
···444745485. Run the testsuite from time to time.
4649+
5050+[source,sh]
4751----
4852make tests
4953----
···156160comments in `.mli` files in the compiler codebase, you can observe the
157161result by running
158162163163+[source,sh]
159164----
160165make html_doc
161166----
···233238option.) You should also use the `-x` option to include the hash of
234239the original commit in the commit message.
235240241241+[source,sh]
236242----
237243git cherry-pick -x -m 1 <merge-commit-hash>
238244----
···253259If you are working on a development version of the compiler, you can create an
254260opam switch from it by running the following from the development repository:
255261262262+[source,sh]
256263-----
257264opam switch create . --empty
258265opam install .
···262269git repository, you can build a switch directly (without cloning their
263270work locally) by pinning:
264271272272+[source,sh]
265273----
266274opam switch create my-switch-name --empty
267275opam pin add ocaml-variants git+https://$REPO#branch
···280288way is to run the normal commands for the switch initialization, with the extra
281289`--inplace-build` flag:
282290291291+[source,sh]
283292-----
284293opam switch create . --empty
285294opam install . --inplace-build
···291300You will then need to install the compiler, either from the working directory
292301(that you must build yourself) or using the regular sandboxed builds.
293302303303+[source,sh]
294304-----
295305# Example with regular opam build
296306opam switch create . --empty
···298308./configure --prefix=$(opam var prefix) # put extra configuration args here
299309-----
300310311311+[source,sh]
301312-----
302313# Example with installation from the current directory
303314opam switch create . --empty
···331342This will make opam remove the previously installed version of the compiler
332343(if any), then install the new one in its stead.
333344345345+[source,sh]
334346-----
335347# reinstall the compiler, and rebuild all opam packages
336348opam custom-install ocaml-variants -- make install
···345357changing even slightly one of the core libraries' files, you will likely
346358get inconsistent assumptions errors later.
347359360360+[source,sh]
348361-----
349362# reinstall the compiler, leaving the opam packages untouched -- unsafe!
350363opam custom-install --no-recompilations ocaml-variants -- make install
···364377and just before the `opam install ocaml command`.
365378Full example:
366379380380+[source,sh]
367381-----
368382opam switch create . --empty
369383./configure --prefix=$(opam var prefix) --disable-ocamldoc --disable-ocamltest
···475489Once you've built a natively-compiled `ocamlc.opt`, you can use it to
476490speed up future builds by copying it to `boot`:
477491492492+[source,sh]
478493----
479494cp ocamlc.opt boot/
480495----
···498513version installed with merlin and dune, you can just run the following from the
499514compiler sources:
500515516516+[source,sh]
501517----
502518./configure # if not already done
503519make clean && dune build @libs
···629645machine, you can use the configuration values and run command taken from
630646link:tools/ci/actions/runner.sh[]:
631647648648+[source,sh]
632649----
633650bash -ex tools/ci/actions/runner.sh configure
634651----
···742759branch. In order to use "precheck" to test parallel build on a custom
743760branch, add this at the beginning of tools/ci-build:
744761762762+[source,sh]
745763----
746764OCAML_JOBS=10
747765----
···762780763781To recreate the `winpthreads` repository from upstream, you can do:
764782783783+[source,sh]
765784----
766785git clone -o upstream https://git.code.sf.net/p/mingw-w64/mingw-w64 winpthreads
767786cd winpthreads
···773792As subtree splitting is deterministic, repeating these operations later will
774793allow to update `master`, for instance by:
775794795795+[source,sh]
776796----
777797git fetch upstream
778798git checkout upstream/master
+66-29
INSTALL.adoc
···53535454From the top directory, do:
55555656- ./configure
5656+[source,sh]
5757+----
5858+./configure
5959+----
57605861This generates the three configuration files `Makefile.config`,
5962`runtime/caml/m.h` and `runtime/caml/s.h`.
60636164The `configure` script accepts options that can be discovered by running:
62656363- ./configure --help
6666+[source,sh]
6767+----
6868+./configure --help
6969+----
64706571Some options or variables like LDLIBS may not be taken into account
6672by the OCaml build system at the moment. Please report an issue if you
···6975Examples:
70767177* Standard installation in `/usr/{bin,lib,man}` instead of `/usr/local`:
7272- ./configure --prefix=/usr
7373-7878++
7979+[source,sh]
8080+----
8181+./configure --prefix=/usr
8282+----
74837584* On a Linux x86-64 host, to build a 32-bit version of OCaml:
7676-7777- ./configure --build=x86_64-pc-linux-gnu --host=i686-linux-gnu
8585++
8686+[source,sh]
8787+----
8888+./configure --build=x86_64-pc-linux-gnu --host=i686-linux-gnu
8989+----
78907991* For AIX 7.x with the IBM compiler `xlc`:
8080-8181- ./configure CC=xlc
9292++
9393+[source,sh]
9494+----
9595+./configure CC=xlc
9696+----
8297+
8398By default, build is 32-bit. For 64-bit build, please set environment variable `OBJECT_MODE=64`
8499 for _both_ `configure` and `make world` phases. Note, if this variable is set for only one phase,
85100 your build will break (`ocamlrun` segfaults).
8686-+
101101+87102* For Solaris/Illumos on SPARC machines with Sun PRO compiler only 64-bit
88103 bytecode target is supported (32-bit fails due to alignment issues; the optimization
89104 is preset to `-O4` for inlining):
9090-9191- ./configure CC="cc -m64"
105105++
106106+[source,sh]
107107+----
108108+./configure CC="cc -m64"
109109+----
92110+
93111If something goes wrong during the automatic configuration, or if the generated
94112files cause errors later on, then look at the template files:
9595-9696- Makefile.config.in
9797- Makefile.build_config.in
9898- runtime/caml/m.h.in
9999- runtime/caml/s.h.in
113113++
114114+----
115115+Makefile.config.in
116116+Makefile.build_config.in
117117+runtime/caml/m.h.in
118118+runtime/caml/s.h.in
119119+----
100120+
101121for guidance on how to edit the generated files by hand.
102122103123== Building the compiler
104124105125From the top directory, do:
106106-107107- make
126126+[source,sh]
127127+----
128128+make
129129+----
108130109131This builds the OCaml compiler for the first time. This phase is
110132fairly verbose; consider redirecting the output to a file:
111133112112- make > make.log 2>&1 # in sh
113113- make >& make.log # in csh
134134+[source,sh]
135135+----
136136+make > make.log 2>&1 # in sh
137137+make >& make.log # in csh
138138+----
114139115140== (Optional) Running the testsuite
116141117142To be sure everything works well, you can run the test suite
118143 that comes with the compiler. To do so, do:
119144120120- make tests
145145+[source,sh]
146146+----
147147+make tests
148148+----
121149122150== Installing the compiler
123151···143171144172From the top directory, become superuser and do:
145173146146- make install
174174+[source,sh]
175175+----
176176+make install
177177+----
147178148179Installation is complete. Time to clean up. From the toplevel directory,
149180 do:
150181151151- make clean
182182+[source,sh]
183183+----
184184+make clean
185185+----
152186153187After installation, do *not* strip the `ocamldebug` executables.
154188 This is a mixed-mode executable (containing both compiled C
···217251setting the `TARGET_LIBDIR` variable. For instance, with the GCC MinGW cross
218252compiler installed, one may use:
219253220220-....
254254+[source,sh]
255255+----
221256./configure --prefix=$PWD/cross --target=x86_64-w64-mingw32 TARGET_LIBDIR='C:\somedir' ...
222257make crossopt -j
223258make installcross
224224-....
259259+----
225260226261Notes:
227262···239274If you have built a cross compiler to a Unix target, you can simply run as
240275usual:
241276242242-....
277277+[source,sh]
278278+----
243279cross/bin/ocamlopt.opt -o test test.ml
244244-....
280280+----
245281246282If you have built a Unix-to-Windows cross compiler, you must first make sure
247283that `ocamlopt` can find the `flexlink` executable in `$PATH` when it needs to
248284link. Bootstrapping `flexdll` builds a `flexlink.exe` (note the `.exe`!), so you
249285can:
250286251251-....
287287+[source,sh]
288288+----
252289ln -s flexlink.exe cross/bin/flexlink
253290(export PATH="$PWD/cross/bin:$PATH"; ocamlopt.opt.exe -o test.exe test.ml)
254254-....
291291+----
255292256293or any other possibility to make sure `ocamlopt` can invoke `flexlink`.
+53-17
README.win32.adoc
···118118Once you have started a Command Prompt, you can verify that you have the
119119compiler you are expecting simply by running:
120120121121- cl
122122- Microsoft (R) C/C++ Optimizing Compiler Version 19.38.33133 for x64
123123- ...
121121+[source,console]
122122+----
123123+> cl
124124+Microsoft (R) C/C++ Optimizing Compiler Version 19.38.33133 for x64
125125+...
126126+----
124127125128You then need to start Cygwin from this Command Prompt. Assuming you have
126129installed it to its default location of `C:\cygwin64`, simply run:
127130128128- C:\cygwin64\bin\mintty -
131131+[source,bat]
132132+----
133133+C:\cygwin64\bin\mintty -
134134+----
129135130136(note the space and hyphen at the end of the command).
131137···139145the beginning of `PATH`, before Cygwin's `/usr/bin`. You can automate this from
140146the top-level of the OCaml distribution by running:
141147142142- eval $(tools/msvs-promote-path)
148148+[source,sh]
149149+----
150150+eval $(tools/msvs-promote-path)
151151+----
143152144153If you forget to do this, `make` will fail relatively
145154quickly as it will be unable to link `ocamlrun`.
146155147156For 64-bit, now run:
148157149149- ./configure --build=x86_64-pc-cygwin --host=x86_64-pc-windows
158158+[source,sh]
159159+----
160160+./configure --build=x86_64-pc-cygwin --host=x86_64-pc-windows
161161+----
150162151163or, for 32-bit:
152164153153- ./configure --build=x86_64-pc-cygwin --host=i686-pc-windows
165165+[source,sh]
166166+----
167167+./configure --build=x86_64-pc-cygwin --host=i686-pc-windows
168168+----
154169155170If you wish to compile with Clang, add `CC=clang-cl`.
156171157172Finally, use `make` to build the system, e.g.
158173159159- make
160160- make install
174174+[source,sh]
175175+----
176176+make
177177+make install
178178+----
161179162180After installing, it is not necessary to keep the Cygwin installation (although
163181you may require it to build additional third party libraries and tools). You
···211229212230For 64-bit, now run:
213231214214- ./configure --build=x86_64-pc-cygwin --host=x86_64-w64-mingw32
232232+[source,sh]
233233+----
234234+./configure --build=x86_64-pc-cygwin --host=x86_64-w64-mingw32
235235+----
215236216237or, for 32-bit:
217238218218- ./configure --build=x86_64-pc-cygwin --host=i686-w64-mingw32
239239+[source,sh]
240240+----
241241+./configure --build=x86_64-pc-cygwin --host=i686-w64-mingw32
242242+----
219243220244Finally, use `make` to build the system, e.g.
221245222222- make
223223- make install
246246+[source,sh]
247247+----
248248+make
249249+make install
250250+----
224251225252After installing, you will need to ensure that `ocamlopt` (or `ocamlc -custom`)
226253can access the C compiler. You can do this either by using OCaml from Cygwin's
···249276 https://github.com/ocaml/flexdll/releases
250277 * Cloning the git repository by running:
251278+
252252- git clone https://github.com/ocaml/flexdll.git
279279+[source,sh]
280280+----
281281+git clone https://github.com/ocaml/flexdll.git
282282+----
253283254284 * If you are compiling from a git clone of the OCaml repository, instead of
255285 using a sources tarball, you can run:
256286+
257257- git submodule update --init
287287+[source,sh]
288288+----
289289+git submodule update --init
290290+----
258291259292OCaml is then compiled normally for the port you require.
260293261261- make
262262- make install
294294+[source,sh]
295295+----
296296+make
297297+make install
298298+----
263299264300 * `make install` will install FlexDLL by placing `flexlink.exe`
265301 (and the default manifest file for the Microsoft port) in `bin/` and the
+2
parsing/HACKING.adoc
···3434This rule is rather slow to run, and can safely be run in parallel, so
3535we recommend using `-j` (without a number) to maximize parallelism:
36363737+[source,sh]
3738----
3839make -j build-all-asts
3940----
···5657 completely (unless you plan to check further changes) -- you can
5758 run `make clean-all-asts` to remove them.
58596060+[source,sh]
5961----
6062# save pre-change ASTs
6163make -j build-all-asts
+7-1
runtime/HACKING.adoc
···10101111If you want to use the bytecode compiler:
12121313+[source,sh]
1314----
1415# build the runtime
1516make runtime -j
···23242425If you want to use the native compiler:
25262727+[source,sh]
2628----
2729# build the native runtime
2830make runtimeopt -j
···4547link:https://ocaml.org/manual/runtime.html#s:ocamlrun-options[].
4648You can enable all printing with
47495050+[source,sh]
4851----
4952OCAMLRUNPARAM="v=0xffffffff" ./test
5053----
···5861Another useful OCAMLRUNPARAM setting is `V=1`, which enables
5962additional sanity checks on the heap during major GC cycles.
60636464+[source,sh]
6165----
6266OCAMLRUNPARAM="V=1" ./test
6367----
···8589`coredumpctl dump` will show you information about the last "core
8690dump".
87919292+[source,console]
8893----
8989-$ $ coredumpctl dump
9494+$ coredumpctl dump
9095 PID: 678260 (Domain0)
9196 UID: 1000 (gasche)
9297 GID: 1000 (gasche)
···108113109114You can get a full backtrace using `echo bt | coredumpctl debug`:
110115116116+[source,console]
111117----
112118$ echo bt | coredumpctl debug
113119[...]
+4-1
utils/HACKING.adoc
···5454Since https://github.com/ocaml/ocaml/pull/12652/[PR #12652], simply run
5555the following command to bump the magic numbers to version xyz:
56565757- tools/bump-magic-numbers xyz
5757+[source,sh]
5858+----
5959+tools/bump-magic-numbers xyz
6060+----
58615962Once the bootstrap during which the magic numbers have been bumped
6063has been completed, the following files need to be committed: