Skip to content

Commit b69ae9e

Browse files
committed
Document PROG-options
1 parent cd636ac commit b69ae9e

File tree

3 files changed

+258
-153
lines changed

3 files changed

+258
-153
lines changed

doc/cabal-package-description-file.rst

Lines changed: 158 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,147 +1310,6 @@ Example:
13101310
end <- getCurrentTime
13111311
putStrLn $ "fib 20 took " ++ show (diffUTCTime end start)
13121312
1313-
1314-
Foreign libraries
1315-
^^^^^^^^^^^^^^^^^
1316-
1317-
Foreign libraries are system libraries intended to be linked against
1318-
programs written in C or other "foreign" languages. They
1319-
come in two primary flavours: dynamic libraries (``.so`` files on Linux,
1320-
``.dylib`` files on OSX, ``.dll`` files on Windows, etc.) are linked against
1321-
executables when the executable is run (or even lazily during
1322-
execution), while static libraries (``.a`` files on Linux/OSX, ``.lib``
1323-
files on Windows) get linked against the executable at compile time.
1324-
1325-
Foreign libraries only work with GHC 7.8 and later.
1326-
1327-
A typical stanza for a foreign library looks like
1328-
1329-
::
1330-
1331-
foreign-library myforeignlib
1332-
type: native-shared
1333-
lib-version-info: 6:3:2
1334-
1335-
if os(Windows)
1336-
options: standalone
1337-
mod-def-file: MyForeignLib.def
1338-
1339-
other-modules: MyForeignLib.SomeModule
1340-
MyForeignLib.SomeOtherModule
1341-
build-depends: base >=4.7 && <4.9
1342-
hs-source-dirs: src
1343-
c-sources: csrc/MyForeignLibWrapper.c
1344-
default-language: Haskell2010
1345-
1346-
1347-
.. pkg-section:: foreign-library name
1348-
:since: 2.0
1349-
:synopsis: Foreign library build information.
1350-
1351-
Build information for `foreign libraries`_.
1352-
1353-
.. pkg-field:: type: foreign library type
1354-
1355-
Cabal recognizes ``native-static`` and ``native-shared`` here, although
1356-
we currently only support building `native-shared` libraries.
1357-
1358-
.. pkg-field:: options: foreign library option list
1359-
1360-
Options for building the foreign library, typically specific to the
1361-
specified type of foreign library. Currently we only support
1362-
``standalone`` here. A standalone dynamic library is one that does not
1363-
have any dependencies on other (Haskell) shared libraries; without
1364-
the ``standalone`` option the generated library would have dependencies
1365-
on the Haskell runtime library (``libHSrts``), the base library
1366-
(``libHSbase``), etc. Currently, ``standalone`` *must* be used on Windows
1367-
and *must not* be used on any other platform.
1368-
1369-
.. pkg-field:: mod-def-file: filename
1370-
1371-
This option can only be used when creating dynamic Windows libraries
1372-
(that is, when using ``native-shared`` and the ``os`` is ``Windows``). If
1373-
used, it must be a path to a *module definition file*. The details of
1374-
module definition files are beyond the scope of this document; see the
1375-
`GHC <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/win32-dlls.html>`_
1376-
manual for some details and some further pointers.
1377-
1378-
.. pkg-field:: lib-version-info: current:revision:age
1379-
1380-
This field is currently only used on Linux.
1381-
1382-
This field specifies a Libtool-style version-info field that sets
1383-
an appropriate ABI version for the foreign library. Note that the
1384-
three numbers specified in this field do not directly specify the
1385-
actual ABI version: ``6:3:2`` results in library version ``4.2.3``.
1386-
1387-
With this field set, the SONAME of the library is set, and symlinks
1388-
are installed.
1389-
1390-
How you should bump this field on an ABI change depends on the
1391-
breakage you introduce:
1392-
1393-
- Programs using the previous version may use the new version as
1394-
drop-in replacement, and programs using the new version can also
1395-
work with the previous one. In other words, no recompiling nor
1396-
relinking is needed. In this case, bump ``revision`` only, don't
1397-
touch current nor age.
1398-
- Programs using the previous version may use the new version as
1399-
drop-in replacement, but programs using the new version may use
1400-
APIs not present in the previous one. In other words, a program
1401-
linking against the new version may fail with "unresolved
1402-
symbols" if linking against the old version at runtime: set
1403-
revision to 0, bump current and age.
1404-
- Programs may need to be changed, recompiled, and relinked in
1405-
order to use the new version. Bump current, set revision and age
1406-
to 0.
1407-
1408-
Also refer to the Libtool documentation on the version-info field.
1409-
1410-
.. pkg-field:: lib-version-linux: version
1411-
1412-
This field is only used on Linux.
1413-
1414-
Specifies the library ABI version directly for foreign libraries
1415-
built on Linux: so specifying ``4.2.3`` causes a library
1416-
``libfoo.so.4.2.3`` to be built with SONAME ``libfoo.so.4``, and
1417-
appropriate symlinks ``libfoo.so.4`` and ``libfoo.so`` to be
1418-
installed.
1419-
1420-
Note that typically foreign libraries should export a way to initialize
1421-
and shutdown the Haskell runtime. In the example above, this is done by
1422-
the ``csrc/MyForeignLibWrapper.c`` file, which might look something like
1423-
1424-
.. code-block:: c
1425-
1426-
#include <stdlib.h>
1427-
#include "HsFFI.h"
1428-
1429-
HsBool myForeignLibInit(void){
1430-
int argc = 2;
1431-
char *argv[] = { "+RTS", "-A32m", NULL };
1432-
char **pargv = argv;
1433-
1434-
// Initialize Haskell runtime
1435-
hs_init(&argc, &pargv);
1436-
1437-
// do any other initialization here and
1438-
// return false if there was a problem
1439-
return HS_BOOL_TRUE;
1440-
}
1441-
1442-
void myForeignLibExit(void){
1443-
hs_exit();
1444-
}
1445-
1446-
With modern ghc regular libraries are installed in directories that contain
1447-
package keys. This isn't usually a problem because the package gets registered
1448-
in ghc's package DB and so we can figure out what the location of the library
1449-
is. Foreign libraries however don't get registered, which means that we'd have
1450-
to have a way of finding out where a platform library got installed (other than by
1451-
searching the ``lib/`` directory). Instead, we install foreign libraries in
1452-
``~/.local/lib``.
1453-
14541313
.. _build-info:
14551314

14561315
Build information
@@ -2014,6 +1873,8 @@ system-dependent values for these fields.
20141873
locate files listed in :pkg-field:`includes` and
20151874
:pkg-field:`install-includes`.
20161875

1876+
Directories here will be passed as ``-I<dir>`` flags to GHC.
1877+
20171878
.. pkg-field:: c-sources: filename list
20181879

20191880
A list of C source files to be compiled and linked with the Haskell
@@ -2050,7 +1911,7 @@ system-dependent values for these fields.
20501911
.. pkg-field:: extra-libraries: token list
20511912

20521913
A list of extra libraries to link with (when not linking fully static
2053-
executables).
1914+
executables). Libraries will be passed as ``-optl-l<lib>`` flags to GHC.
20541915

20551916
.. pkg-field:: extra-libraries-static: token list
20561917

@@ -2084,7 +1945,7 @@ system-dependent values for these fields.
20841945
.. pkg-field:: extra-lib-dirs: directory list
20851946

20861947
A list of directories to search for libraries (when not linking fully static
2087-
executables).
1948+
executables). Directories will be passed as ``-optl-L<dir>`` flags to GHC.
20881949

20891950
.. pkg-field:: extra-lib-dirs-static: directory list
20901951

@@ -2101,7 +1962,8 @@ system-dependent values for these fields.
21011962

21021963
.. pkg-field:: cc-options: token list
21031964

2104-
Command-line arguments to be passed to the C compiler. Since the
1965+
Command-line arguments to be passed to the Haskell compiler for the C
1966+
compiling phase (as ``-optc`` flags for GHC). Since the
21051967
arguments are compiler-dependent, this field is more useful with the
21061968
setup described in the section on `system-dependent parameters`_.
21071969

@@ -2110,12 +1972,14 @@ system-dependent values for these fields.
21101972
Command-line arguments for pre-processing Haskell code. Applies to
21111973
Haskell source and other pre-processed Haskell source like .hsc
21121974
.chs. Does not apply to C code, that's what cc-options is for.
1975+
Flags here will be passed as ``-optP`` flags to GHC.
21131976

21141977
.. pkg-field:: cxx-options: token list
21151978
:since: 2.2
21161979

2117-
Command-line arguments to be passed to the compiler when compiling
2118-
C++ code. The C++ sources to which these command-line arguments
1980+
Command-line arguments to be passed to the Haskell compiler for the C++
1981+
compiling phase (as ``-optcxx`` flags for GHC).
1982+
The C++ sources to which these command-line arguments
21191983
should be applied can be specified with the :pkg-field:`cxx-sources`
21201984
field. Command-line options for C and C++ can be passed separately to
21211985
the compiler when compiling both C and C++ sources by segregating the C
@@ -2127,20 +1991,22 @@ system-dependent values for these fields.
21271991
.. pkg-field:: cmm-options: token list
21281992
:since: 3.0
21291993

2130-
Command-line arguments to be passed to the compiler when compiling
1994+
Command-line arguments to be passed to the Haskell compiler when compiling
21311995
C-- code. See also :pkg-field:`cmm-sources`.
21321996

21331997
.. pkg-field:: asm-options: token list
21341998
:since: 3.0
21351999

2136-
Command-line arguments to be passed to the assembler when compiling
2137-
assembler code. See also :pkg-field:`asm-sources`.
2000+
Command-line arguments to be passed to the Haskell compiler (as ``-opta``
2001+
flags for GHC) when compiling assembler code. See also :pkg-field:`asm-sources`.
21382002

21392003
.. pkg-field:: ld-options: token list
21402004

2141-
Command-line arguments to be passed to the linker. Since the
2142-
arguments are compiler-dependent, this field is more useful with the
2143-
setup described in the section on `system-dependent parameters`_.
2005+
Command-line arguments to be passed to the Haskell compiler (as ``-optl``
2006+
flags for GHC) for the linking phase. Note that only executables (including
2007+
test-suites and benchmarks) are linked so this has no effect in libraries.
2008+
Since the arguments are compiler-dependent, this field is more useful with
2009+
the setup described in the section on `system-dependent parameters`_.
21442010

21452011
.. pkg-field:: hsc2hs-options: token list
21462012
:since: 3.6
@@ -2287,6 +2153,146 @@ system-dependent values for these fields.
22872153
in a different package dependency, or at least in a separate internal
22882154
library.
22892155

2156+
Foreign libraries
2157+
^^^^^^^^^^^^^^^^^
2158+
2159+
Foreign libraries are system libraries intended to be linked against
2160+
programs written in C or other "foreign" languages. They
2161+
come in two primary flavours: dynamic libraries (``.so`` files on Linux,
2162+
``.dylib`` files on OSX, ``.dll`` files on Windows, etc.) are linked against
2163+
executables when the executable is run (or even lazily during
2164+
execution), while static libraries (``.a`` files on Linux/OSX, ``.lib``
2165+
files on Windows) get linked against the executable at compile time.
2166+
2167+
Foreign libraries only work with GHC 7.8 and later.
2168+
2169+
A typical stanza for a foreign library looks like
2170+
2171+
::
2172+
2173+
foreign-library myforeignlib
2174+
type: native-shared
2175+
lib-version-info: 6:3:2
2176+
2177+
if os(Windows)
2178+
options: standalone
2179+
mod-def-file: MyForeignLib.def
2180+
2181+
other-modules: MyForeignLib.SomeModule
2182+
MyForeignLib.SomeOtherModule
2183+
build-depends: base >=4.7 && <4.9
2184+
hs-source-dirs: src
2185+
c-sources: csrc/MyForeignLibWrapper.c
2186+
default-language: Haskell2010
2187+
2188+
2189+
.. pkg-section:: foreign-library name
2190+
:since: 2.0
2191+
:synopsis: Foreign library build information.
2192+
2193+
Build information for `foreign libraries`_.
2194+
2195+
.. pkg-field:: type: foreign library type
2196+
2197+
Cabal recognizes ``native-static`` and ``native-shared`` here, although
2198+
we currently only support building `native-shared` libraries.
2199+
2200+
.. pkg-field:: options: foreign library option list
2201+
2202+
Options for building the foreign library, typically specific to the
2203+
specified type of foreign library. Currently we only support
2204+
``standalone`` here. A standalone dynamic library is one that does not
2205+
have any dependencies on other (Haskell) shared libraries; without
2206+
the ``standalone`` option the generated library would have dependencies
2207+
on the Haskell runtime library (``libHSrts``), the base library
2208+
(``libHSbase``), etc. Currently, ``standalone`` *must* be used on Windows
2209+
and *must not* be used on any other platform.
2210+
2211+
.. pkg-field:: mod-def-file: filename
2212+
2213+
This option can only be used when creating dynamic Windows libraries
2214+
(that is, when using ``native-shared`` and the ``os`` is ``Windows``). If
2215+
used, it must be a path to a *module definition file*. The details of
2216+
module definition files are beyond the scope of this document; see the
2217+
`GHC <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/win32-dlls.html>`_
2218+
manual for some details and some further pointers.
2219+
2220+
.. pkg-field:: lib-version-info: current:revision:age
2221+
2222+
This field is currently only used on Linux.
2223+
2224+
This field specifies a Libtool-style version-info field that sets
2225+
an appropriate ABI version for the foreign library. Note that the
2226+
three numbers specified in this field do not directly specify the
2227+
actual ABI version: ``6:3:2`` results in library version ``4.2.3``.
2228+
2229+
With this field set, the SONAME of the library is set, and symlinks
2230+
are installed.
2231+
2232+
How you should bump this field on an ABI change depends on the
2233+
breakage you introduce:
2234+
2235+
- Programs using the previous version may use the new version as
2236+
drop-in replacement, and programs using the new version can also
2237+
work with the previous one. In other words, no recompiling nor
2238+
relinking is needed. In this case, bump ``revision`` only, don't
2239+
touch current nor age.
2240+
- Programs using the previous version may use the new version as
2241+
drop-in replacement, but programs using the new version may use
2242+
APIs not present in the previous one. In other words, a program
2243+
linking against the new version may fail with "unresolved
2244+
symbols" if linking against the old version at runtime: set
2245+
revision to 0, bump current and age.
2246+
- Programs may need to be changed, recompiled, and relinked in
2247+
order to use the new version. Bump current, set revision and age
2248+
to 0.
2249+
2250+
Also refer to the Libtool documentation on the version-info field.
2251+
2252+
.. pkg-field:: lib-version-linux: version
2253+
2254+
This field is only used on Linux.
2255+
2256+
Specifies the library ABI version directly for foreign libraries
2257+
built on Linux: so specifying ``4.2.3`` causes a library
2258+
``libfoo.so.4.2.3`` to be built with SONAME ``libfoo.so.4``, and
2259+
appropriate symlinks ``libfoo.so.4`` and ``libfoo.so`` to be
2260+
installed.
2261+
2262+
Note that typically foreign libraries should export a way to initialize
2263+
and shutdown the Haskell runtime. In the example above, this is done by
2264+
the ``csrc/MyForeignLibWrapper.c`` file, which might look something like
2265+
2266+
.. code-block:: c
2267+
2268+
#include <stdlib.h>
2269+
#include "HsFFI.h"
2270+
2271+
HsBool myForeignLibInit(void){
2272+
int argc = 2;
2273+
char *argv[] = { "+RTS", "-A32m", NULL };
2274+
char **pargv = argv;
2275+
2276+
// Initialize Haskell runtime
2277+
hs_init(&argc, &pargv);
2278+
2279+
// do any other initialization here and
2280+
// return false if there was a problem
2281+
return HS_BOOL_TRUE;
2282+
}
2283+
2284+
void myForeignLibExit(void){
2285+
hs_exit();
2286+
}
2287+
2288+
With modern ghc regular libraries are installed in directories that contain
2289+
package keys. This isn't usually a problem because the package gets registered
2290+
in ghc's package DB and so we can figure out what the location of the library
2291+
is. Foreign libraries however don't get registered, which means that we'd have
2292+
to have a way of finding out where a platform library got installed (other than by
2293+
searching the ``lib/`` directory). Instead, we install foreign libraries in
2294+
``~/.local/lib``.
2295+
22902296
Configurations
22912297
^^^^^^^^^^^^^^
22922298

doc/cabal-project-description-file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ Program options
16611661

16621662
.. cfg-section:: program-options
16631663

1664-
Program options can be specified once for all local packages by means of the
1664+
:ref:`Program options<program_options>` can be specified once for all local packages by means of the
16651665
``program-options`` stanza. For example:
16661666

16671667
::

0 commit comments

Comments
 (0)