Commit Graph

90 Commits

Author SHA1 Message Date
Dylan Baker e7f0890cb9 compilers: move get_dependency_gen_args to base Compiler
So that every subclass doesn't have to reimplement it. Especially since
the Gnu implementation moved out of the CCompiler and into the
GnuLikeCompiler mixin
2020-10-01 15:05:00 -07:00
Dylan Baker 2c0fbe161d compilers: make is_cross part of the base Compiler class
Every class needs to set this, so it should be part of the base. For
classes that require is_cross, the positional argument remains in their
signature. For those that don't, they just allow the base class to set
their value to it's default of False.
2020-09-24 12:14:13 -07:00
Dylan Baker 98416e7f75 compilers: put name_string method in base compiler
Every language had the exact same implementation
2020-09-24 12:14:13 -07:00
Pierrick Bouvier 1900720353 D: fix include order
Commit 93c3ec7e introduced a new way to handle deduplication with
compiler args. This resulted in D includes to be reversed.
2020-08-30 18:56:24 +03:00
Dylan Baker 93c3ec7e2d compilers: Return CompilerArgs from compiler instance
Since the CompileArgs class already needs to know about the compiler,
and we really need at least per-lanaguage if not per-compiler
CompilerArgs classes, let's get the CompilerArgs instance from the
compiler using a method.
2020-06-22 12:06:10 -07:00
Dylan Baker 9d0ad66c29 compilers: Split CompilerArgs into a separate module
I've also moved this out of the compilers pacakge because we're soon
going to need it in linkers, and that creates some serious spagetti
2020-06-22 12:06:10 -07:00
Dylan Baker 29ef4478df compilers/d: Add b_ndebug support
D lang compilers have an option -release (or similar) which turns off
asserts, contracts, and other runtime type checking. This patch wires
that up to the b_ndebug flag.

Fixes #7082
2020-05-20 14:20:26 -07:00
Jussi Pakkanen 751ea3df72
Merge pull request #7103 from dankegel/bug4027-rpath-remember
Let .pc files and LDFLAGS provide rpaths.
2020-05-18 23:17:34 +03:00
Dylan Baker 6fe68edbf8 compilers/d: Enable pgo for GDC 2020-05-18 19:29:18 +03:00
Dan Kegel d7235c5905 Let .pc files specify rpath.
Fixes #4027
2020-05-16 20:25:58 +00:00
Dylan Baker fe3f7676e9 compilers/d: Add missing method for dmd and ldc
This allows coverage to be generated, although we can't yet do anything
useful with it.
2020-04-10 12:46:55 -07:00
Dylan Baker 0f8d73848a compilers/d: Implement coverage for GDC
Since GDC a GNU compiler, we just need to pass the normal GNU options
and coverage is generated.

Related: ##5669
2020-04-10 12:35:25 -07:00
Dylan Baker e1060f5772 compilers: Link D runtime/libphobs dynamically on !Windows
Fixes: #6786
2020-03-19 19:04:43 +02:00
Dylan Baker 9c9dcbb1a8 compilers/d: Support linker selection with gdc
This should have worked before, but the inheritance order was backwards,
so we got the DCompiler before the GnuCompiler, and the base Compiler
methods overrode the Gnu methods.
2020-03-12 13:21:04 -07:00
Dylan Baker 92e80d54e5 compilers/d: Properly pass -soname args 2020-03-11 09:27:10 -07:00
Dylan Baker f136084609 compilers/d: Fix rpath generation with LDC and DMD 2020-03-11 09:26:20 -07:00
Dylan Baker fe86c594c6 Allow invoking the linker directly through dmd
DMD is awful in a lot of ways. To change the linker you set an
environment variable, which is pretty much impossible for us.
2020-03-09 16:55:08 -07:00
Dylan Baker 1fe153a3a5 Allow invoking link.exe and lld-link.exe through ldc2
Like it wants
2020-03-09 13:19:03 -07:00
Dylan Baker f404c679cf compilers/d: Fix get_allow_undefined_link_args on macOS
DMD and LDC are a real pain to use as linkers. On Unices they invoke the C
compiler as the linker, just like meson does. This means we have to figure out
what C compiler they're using and try to pass valid arguments to that compiler
if the D compiler doesn't understand the linker arguments we want to pass. In
this case that means gcc or clang. We can use-the -Xcc to pass arguments
directly to the C compiler without dmd/ldc getting involved, so we'll use that.
2020-03-06 12:11:26 -08:00
Dylan Baker c0fd20f164 compilers/d: Remove CompilerIsLInkerMixin
This was never really true of the D compilers, it made them more
complicated than necessary and was incorrect in many cases. Removing it
causes no regressions on Linux, at least in our rather limited test
cases).
2020-03-06 12:11:26 -08:00
Daniel Mensinger 09b53c534f types: import typing as T (fixes #6333) 2020-01-08 15:28:17 +01:00
Dylan Baker ee6e249f65 compilers: move language attribute to the class level
We know that if a compiler class inherits CCompiler it's language will
be C, so doing this at the class level makes more sense.
2019-12-12 09:35:30 -08:00
Daniel Mensinger fe853ee516 lgtm: fix Missing call to __init__ during object initialization
Either mark the missing calls as intentional, or explicetly call
the right __init__ method and avoid mixing super() and explicit
base calss calls.
2019-12-05 00:22:10 +02:00
Eric Le Bihan 815563841a Fix cross-compilation of D programs
Since version 9.1, GCC provides support for the D programming language. Thus it
is easy to build a cross-compiler for D, such as aarch64-unknown-linux-gnu-gdc.

However to cross-compile a Meson project using D, using a cross build definition
such as the following is not enough:

```
[binaries]
d = '/path/to/aarch64-unknown-linux-gnu-gdc'
exe_wrapper = '/path/to/qemu-aarch64-static'

[properties]
needs_exe_wrapper = true

[host_machine]
system = 'linux'
cpu_family = 'aarch64'
cpu = 'cortex-a53'
endian = 'little'
```

Indeed, "exe_wrapper" is not be taken into account. Build will fail with:

```
Executables created by D compiler /path/to/aarch64-uknown-linux-gnu-gdc are not runnable.
```

This patch fixes this by reworking:

- detect_d_compiler() to properly get exe_wrapper and D compilers and detect the
one available.
- Dcompiler to properly handle exe_wrapper.
2019-11-19 16:32:12 +02:00
Jussi Pakkanen 4c96aa34cb Add -L= to soname linker argument, too. 2019-11-06 22:12:41 +02:00
GoaLitiuM 31d397187d d: Fix various linking issues on Windows 2019-10-21 16:24:39 +03:00
Andrei Alexeyev 5dfd054c32 Workaround broken get_allow_undefined_link_args in DmdLikeCompilerMixin
Previously it worked by accident because BasicLinkerIsCompilerMixin had
that method misspelled.
2019-10-14 13:04:34 -07:00
Andrei Alexeyev af2c1e4eb7 Revert "Remove BasicLinkerIsCompilerMixin from LDC and DMD"
This reverts commit 04d6a439457d76b9cf4c4f98fce238219366e241.
2019-10-14 13:04:34 -07:00
Andrei Alexeyev 5e3eff9d72 Remove BasicLinkerIsCompilerMixin from LDC and DMD
These compilers invoke external linkers and have the appropriate .linker
property set. Therefore, BasicLinkerIsCompilerMixin appears to be
misplaced.

It used to work by chance, because BasicLinkerIsCompilerMixin failed to
override the get_allow_undefined_link_args method. The D compilers do
not provide their own get_allow_undefined_link_args, because they expect
to inherit it from Compiler, which simply delegates it to the linker.

Now that BasicLinkerIsCompilerMixin correctly overrides that method with
a stub, it broke compilers that relied on the buggy behavior.
2019-10-14 13:04:34 -07:00
Dylan Baker afbed79baa compilers: replace uses of mesonlib.is_<os>() with self.info.is_<os>()
Since these are cross compilation safe, while the former is not.
2019-10-07 12:08:20 -07:00
Dylan Baker 0c22798b1a compilers: replace CompilerType with MachineInfo
Now that the linkers are split out of the compilers this enum is
only used to know what platform we're compiling for. Which is
what the MachineInfo class is for
2019-10-07 12:08:20 -07:00
Daniel Mensinger c6938bd579
Handle -idirafter in unix_args_to_native 2019-10-03 10:06:03 +02:00
Dylan Baker 0efab591da compilers: Move the compiler argument to proxy linker flags to the compiler class
Instead of the DynamicLinker returning a hardcoded value like
`-Wl,-foo`, it now is passed a value that could be '-Wl,', or could be
something '-Xlinker='

This makes a few things cleaner, and will make it possible to fix using
clang (not clang-cl) on windows, where it invokes either link.exe or
lld-link.exe instead of a gnu-ld compatible linker.
2019-08-30 00:01:32 +03:00
Dylan Baker 06dcbd50ee compilers: Dispatch to dynamic linker class
Most of the cuda code is from Olexa Bilaniuk.
Most of the PGI code is from Michael Hirsc
2019-08-14 13:13:23 -07:00
Dylan Baker 90e43dbdfe re-architect the D compiler abstractions
We support 3 D compilers, DMD, LDC, and GDC. DMD is the reference
compiler, and LDC attempts to largely mirror it's command line usage.
GDC does not, it instead acts like GCC (which makes sense). The current
abstraction puts DMD behavior in the base D compiler and then overrides
then in the GnuDCompiler class.

This is messy, but it becomes more problematic when splitting the linker
and compiler abstractions apart.

I've opted to instead split the DCompiler class into two separate
classes. The DCompiler implements core D functinoality, and
DmdLikeCompilerMixin, which implements the DMD and LDC command line
arguments. I've then mxed that into the DmdDCompiler and LLVMDCompiler
classes, and mixed the GnuCompiler into the GnuDCompiler class to get
Gnu command line behavior.
2019-08-14 13:13:22 -07:00
Dylan Baker cd5360821a compilers: split gnu and gnulike compilers out of compilers
I debated a bit whether both classes really belong in the same module,
and decided that they do because the share a number of helpers.
2019-07-15 10:59:22 -07:00
myfreeweb efea48788a Ignore -D* and -fstack-protector* args for D compilers
Fixes #5369
2019-07-11 22:32:39 +03:00
John Ericson 07777e15d4 Purge `is_cross` and friends without changing user interfaces
In most cases instead pass `for_machine`, the name of the relevant
machines (what compilers target, what targets run on, etc). This allows
us to use the cross code path in the native case, deduplicating the
code.

As one can see, environment got bigger as more information is kept
structured there, while ninjabackend got a smaller. Overall a few amount
of lines were added, but the hope is what's added is a lot simpler than
what's removed.
2019-06-09 13:13:25 -04:00
Daniel Mensinger c61ae46461
Moved caching into a seperate function 2019-04-28 14:33:22 +02:00
Daniel Mensinger 971dfd664b
Added some cahced values 2019-04-28 14:33:21 +02:00
Daniel Mensinger c9bd84fd25
Cache compile results in coredata 2019-04-28 14:31:49 +02:00
Ari Vuollet 5ee2fb6ede d: Fix linker errors with shared libraries on Windows 2019-04-03 19:59:24 +03:00
jml1795 a9e63568fe Add warning level zero 2019-02-19 00:06:27 +02:00
Matthias Klumpp 2cede4d6c9 d: Translate the -isystem flag for LDC and DMD 2019-02-18 22:11:19 +02:00
Luís Ferreira b90f196f17 d: fix linker due to argument errors
- revert some changes on d2483d4412 commit.

Signed-off-by: Luís Ferreira <lsferreira169@gmail.com>
2019-02-05 11:13:05 +00:00
John Ericson 19f81d3e33 Never access environment.properties downstream
Instead use coredata.compiler_options.<machine>. This brings the cross
and native code paths closer together, since both now use that.

Command line options are interpreted just as before, for backwards
compatibility. This does introduce some funny conditionals. In the
future, I'd like to change the interpretation of command line options so

 - The logic is cross-agnostic, i.e. there are no conditions affected by
   `is_cross_build()`.

 - Compiler args for both the build and host machines can always be
   controlled by the command line.

 - Compiler args for both machines can always be controlled separately.
2019-02-02 13:59:14 -05:00
Daniel Mensinger 9eca2e46a0
Added more compiler option support 2019-01-06 12:19:33 +01:00
Daniel Mensinger 9742927903
Absolute path generation refactoring 2019-01-06 12:19:32 +01:00
Dylan Baker de175aac00 compilers: Use keyword only arguments for compiler interfaces
Because we need to inherit them in some cases, and python's
keyword-or-positional arguments make this really painful, especially
with inheritance. They do this in two ways:

1) If you want to intercept the arguments you need to check for both a
   keyword and a positional argument, because you could get either. Then
   you need to make sure that you only pass one of those down to the
   next layer.

2) After you do that, if the layer below you decides to do the same
   thing, but uses the other form (you used keyword by the lower level
   uses positional or vice versa), then you'll get a TypeError since two
   layers down got the argument as both a positional and a keyword.

All of this is bad. Fortunately python 3.x provides a mechanism to solve
this, keyword only arguments. These arguments cannot be based
positionally, the interpreter will give us an error in that case.

I have made a best effort to do this correctly, and I've verified it
with GCC, Clang, ICC, and MSVC, but there are other compilers like Arm
and Elbrus that I don't have access to.
2018-11-13 00:40:13 +02:00
Jon Turney bb31a8c1c7
Only add link arguments when needed in Compiler object methods
Currently, ComplierHolder.determine_args() unconditionally adds the link
arguments to the commmand, even if we aren't linking, because it doesn't
have access to the mode (preprocess, compile, link) that
_get_compiler_check_args() will use.

This leads to command lines like:

'cl testfile.c /nologo /showIncludes /c /Fooutput.obj /Od kernel32.lib
user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib
uuid.lib comdlg32.lib advapi32.lib'

which clang-cl considers invalid; MSVS cl accepts this, ignoring the
unneeded libraries

Change from passing extra_args down to _get_compiler_check_args(), to
passing down a callback to CompilerHolder.determine_args() (with a bound
kwargs argument), so it can consult mode and kwargs to determine the args to
use.
2018-11-04 15:42:06 +00:00