Skip to content

Commit

Permalink
split extra-objects
Browse files Browse the repository at this point in the history
  • Loading branch information
emillon committed Jul 11, 2024
1 parent 2aba524 commit 9d680c4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
29 changes: 29 additions & 0 deletions doc/reference/extra-objects.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Extra Objects
-------------

It's possible to specify native object files to be packaged with OCaml
libraries or linked into OCaml executables. Do this by using the
``extra_objects`` field of the ``library`` or ``executable`` stanzas.
For example:

.. code:: dune
(executable
(public_name main)
(extra_objects foo bar))
(rule
(targets foo.o bar.o)
(deps foo.c bar.c)
(action (run ocamlopt %{deps})))
This example builds an executable which is linked against a pair of native
object files, ``foo.o`` and ``bar.o``. The ``extra_objects`` field takes a
list of object names, which correspond to the object file names with their path
and extension omitted.

In this example, the sources corresponding to the objects (``foo.c`` and
``bar.c``) are assumed to be present in the same directory as the OCaml source
code, and a custom ``rule`` is used to compile the C source code into object
files using ``ocamlopt``. This is not necessary; one can instead compile foreign
object files manually and place them next to the OCaml source code.
29 changes: 1 addition & 28 deletions doc/reference/foreign.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,10 @@ Foreign Archives

See :doc:`foreign-archives`.

.. _extra-objects:

Extra Objects
-------------

It's possible to specify native object files to be packaged with OCaml
libraries or linked into OCaml executables. Do this by using the
``extra_objects`` field of the ``library`` or ``executable`` stanzas.
For example:

.. code:: dune
(executable
(public_name main)
(extra_objects foo bar))
(rule
(targets foo.o bar.o)
(deps foo.c bar.c)
(action (run ocamlopt %{deps})))
This example builds an executable which is linked against a pair of native
object files, ``foo.o`` and ``bar.o``. The ``extra_objects`` field takes a
list of object names, which correspond to the object file names with their path
and extension omitted.

In this example, the sources corresponding to the objects (``foo.c`` and
``bar.c``) are assumed to be present in the same directory as the OCaml source
code, and a custom ``rule`` is used to compile the C source code into object
files using ``ocamlopt``. This is not necessary; one can instead compile foreign
object files manually and place them next to the OCaml source code.
See :doc:`extra-objects`.

.. _flags-flow:

Expand Down
1 change: 1 addition & 0 deletions doc/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ These documents specify the various features and languages present in Dune.
foreign
foreign-stubs
foreign-archives
extra-objects

.. grid-item::

Expand Down

0 comments on commit 9d680c4

Please sign in to comment.