@ -5,7 +5,8 @@ short-description: Compiling D sources
# Compiling D applications
Meson has support for compiling D programs. A minimal `meson.build` file for D looks like this:
Meson has support for compiling D programs. A minimal `meson.build`
file for D looks like this:
```meson
project('myapp', 'd')
@ -15,8 +16,8 @@ executable('myapp', 'app.d')
## Compiling different versions
If you are using the [version()](https://dlang.org/spec/version.html) feature for conditional compilation, you can use it using the `d_module_versions`
target property:
If you are using the [version()](https://dlang.org/spec/version.html) feature for conditional compilation,
you can use it using the `d_module_versions`target property:
It is important to make the D sources install in a subdirectory in the include path, in this case `/usr/include/d/mylib/mylib`.
All D compilers include the `/usr/include/d` directory by default, and if your library would be installed into `/usr/include/d/mylib`, there
is a high chance that, when you compile your project again on a machine where you installed it, the compiler will prefer the old installed include over
the new version in the source tree, leading to very confusing errors.
This is an example of how to use the D library we just built and installed in an application:
It is important to make the D sources install in a subdirectory in the
include path, in this case `/usr/include/d/mylib/mylib`.
All D compilers include the `/usr/include/d` directory by default, and
if your library would be installed into `/usr/include/d/mylib`, there
is a high chance that, when you compile your project again on a
machine where you installed it, the compiler will prefer the old
installed include over the new version in the source tree, leading to
very confusing errors.
This is an example of how to use the D library we just built and
Please keep in mind that the library and executable would both need to be built with the exact same D compiler and D compiler version. The D ABI is not
stable across compilers and their versions, and mixing compilers will lead to problems.
Please keep in mind that the library and executable would both need to
be built with the exact same D compiler and D compiler version. The D
ABI is not stable across compilers and their versions, and mixing
compilers will lead to problems.
# Integrating with DUB
DUB is a fully integrated build system for D, but it is also a way to provide dependencies. Adding dependencies from the [D package registry](https://code.dlang.org/) is pretty straight forward.
You can find how to do this in [Dependencies](Dependencies.md#Dub). You can also automatically generate a `dub.json` file as explained in [Dlang](Dlang-module.md#generatedubfile).
DUB is a fully integrated build system for D, but it is also a way to
provide dependencies. Adding dependencies from the [D package registry](https://code.dlang.org/)
is pretty straight forward. You can find how to do this in
[Dependencies](Dependencies.md#Dub). You can also automatically
generate a `dub.json` file as explained in [Dlang](Dlang-module.md#generatedubfile).
Please understand that meson is only able to find dependencies that
exist in the local Dub repository. You need to manually fetch and
build the target dependencies.
For `urld`.
```
dub fetch urld
dub build urld
```
Other thing you need to keep in mind is that both meson and Dub need
to be using the same compiler. This can be achieved using Dub's
`-compiler` argument and/or manually setting the `DC` environment
variable when running meson.
```
dub build urld --compiler=dmd
DC="dmd" meson builddir
```
# Dependencies with custom lookup functionality
Some dependencies have specific detection logic.
@ -186,24 +218,6 @@ have been compiled for single-threaded use instead.
`method` may be `auto`, `config-tool`, `pkg-config` or `extraframework`.
## Dub
Use `method` to find dependencies with Dub. Just create a dependency as you would normally, but add `dub` as the dependency method.
```meson
urld_dep = dependency('urld', method: 'dub')
```
Please understand that meson is only able to find existing dependencies. You still need to manually fetch and build them with Dub.
```
dub fetch urld
dub build urld
```
Other thing you need to keep in mind is that both meson and Dub need to be using the same compiler. This can be achieved using Dub's `-compiler` argument and/or manually setting the `DC` environment variable when running meson.
```
dub build urld --compiler=dmd
DC="dmd" meson builddir
```
## GL
This finds the OpenGL library in a way appropriate to the platform.
@ -298,7 +312,7 @@ The `language` keyword may used.
Python3 is handled specially by meson:
1. Meson tries to use `pkg-config`.
1. If `pkg-config` fails meson uses a fallback:
2. If `pkg-config` fails meson uses a fallback:
- On Windows the fallback is the current `python3` interpreter.
- On OSX the fallback is a framework dependency from `/Library/Frameworks`.
You can manually edit a meson generated `dub.json` file or provide a initial one.
The module will only update the values specified in `generate_dub_file()`.
You can manually edit a meson generated `dub.json` file or provide a
initial one. The module will only update the values specified in
`generate_dub_file()`.
Although not required, you will need to have a `description` and `license` if you want to publish the package in the [D package registry](https://code.dlang.org/).
Other thing to keep in mind is that currently, the module ignores `configurations`, `subConfigurations`, and `buildTypes`.
You can configure that directly in `dub.json`.
Although not required, you will need to have a `description` and
`license` if you want to publish the package in the [D package registry](https://code.dlang.org/).