forked from ocaml/dune
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: split foreign.rst (ocaml#10718)
Signed-off-by: Etienne Millon <[email protected]>
- Loading branch information
Showing
11 changed files
with
129 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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 contrast, ``(rule)`` manipulates file names, so the | ||
extension needs to be provided). | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Foreign Archives | ||
---------------- | ||
|
||
Foreign archives are a way to link archives that are separately compiled. | ||
|
||
They are particularly useful when embedding a library written in a foreign | ||
language and/or built with another build system. See :ref:`foreign-sandboxing` | ||
for more details. | ||
|
||
To use this feature, use the ``foreign_archives`` field of the corresponding | ||
``library`` or ``executable`` stanza. For example: | ||
|
||
.. code:: dune | ||
(library | ||
(name lib) | ||
(foreign_stubs (language c) (names src1 src2)) | ||
(foreign_stubs (language cxx) (names src3) (flags -O2)) | ||
(foreign_archives arch1 some/dir/arch2)) | ||
Here, in addition to :doc:`foreign-stubs`, we also specify foreign archives | ||
``arch1`` and ``arch2``, where the latter is stored in a subdirectory | ||
``some/dir``. | ||
|
||
You can build a foreign archive manually, e.g., using a custom ``rule`` as | ||
described in :ref:`foreign-sandboxing`, or ask Dune to build it via the | ||
``foreign_library`` stanza: | ||
|
||
.. code:: dune | ||
(foreign_library | ||
(archive_name arch1) | ||
(language c) | ||
(enabled_if true) | ||
(names src4 src5) | ||
(include_dir headers)) | ||
This asks Dune to compile C source files ``src4`` and ``src5`` with | ||
headers tracked in the ``headers`` directory and put the resulting | ||
object files into an archive ``arch1``, whose full name is typically | ||
``libarch1.a`` for static linking and ``dllarch1.so`` for dynamic | ||
linking. | ||
|
||
The ``foreign_library`` stanza supports all :doc:`foreign-stubs` fields. | ||
The ``archive_name`` field specifies the archive's name. You can refer | ||
to the same archive name from multiple OCaml libraries and executables, so a | ||
foreign archive is a bit like a foreign library, hence the name of the stanza. | ||
The ``enabled_if`` field has the same meaning as in the :doc:`dune/library` | ||
stanza. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Flags in Foreign Code | ||
--------------------- | ||
|
||
Depending on the :doc:`dune-project/use_standard_c_and_cxx_flags` option, | ||
the base ``:standard`` set of flags for C will contain only ``ocamlc_cflags`` or | ||
both ``ocamlc_cflags`` and ``ocamlc_cppflags``. | ||
|
||
There are multiple levels where one can declare custom flags (using the | ||
:doc:`ordered-set-language`), and each level inherits the flags of the previous | ||
one in its `:standard` set: | ||
|
||
- In the global :doc:`dune-workspace/env` definition of a | ||
:doc:`dune-workspace/index` file | ||
- In the :doc:`per-context env <dune-workspace/context>` definitions in a | ||
:doc:`dune-workspace/index` file | ||
- In the :doc:`dune/env` definition of a :doc:`dune/index` file | ||
- In a :doc:`foreign_stubs <foreign-stubs>`, :doc:`foreign_library | ||
<foreign-archives>` or :doc:`extra_objects <extra-objects>` field of an | ||
executable or a library. | ||
|
||
The ``%{cc}`` :doc:`variable <../concepts/variables>` will contain the flags | ||
from the first three levels only. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters