mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.61k stars 1.63k forks source link

Problems using LLVM in a non CPP project. #5951

Open streaksu opened 5 years ago

streaksu commented 5 years ago

Hello, my issue is the following: I wanted to use meson to build my D language project, a compiler targetting LLVM IR. LLVM has a C interface that requires no effort to use with some FFI, but meson doesnt really support this use, forcing cpp to be present in the languages of the compiler, but that is not the main issue. I would recommend having llvm using only the output of llvm-config --libs instead of the full flags reported for c and c++ compilers that I guess it currently uses.

The main issue is that, when configuring a package in D that has llvm as dependency, and a add_languages('cpp') to silence the errors regarding this language not being present, one gets the following errors:

The Meson build system
Version: 0.45.1
Source dir: blablabla
Build dir: blablabla/a
Build type: native build
Project name: porcelainc
Native D compiler: ldc2 (llvm 1.8.0 "LDC - the LLVM D compiler (1.8.0):")
Build machine cpu family: x86_64
Build machine cpu: x86_64
Native C++ compiler: c++ (clang 6.0.0-1ubuntu2 "clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)")
Configuring compiler.d using configuration
Found llvm-config: /usr/bin/llvm-config (6.0.0)
Dependency LLVM found: YES
Program cc found: YES (/usr/bin/cc)
Build targets in project: 1
Found ninja-1.8.2 at /usr/bin/ninja
Traceback (most recent call last):
  File "/usr/share/meson/mesonbuild/mesonmain.py", line 361, in run
    app.generate()
  File "/usr/share/meson/mesonbuild/mesonmain.py", line 150, in generate
    self._generate(env)
  File "/usr/share/meson/mesonbuild/mesonmain.py", line 207, in _generate
    g.generate(intr)
  File "/usr/share/meson/mesonbuild/backend/ninjabackend.py", line 219, in generate
    self.generate_target(t, outfile)
  File "/usr/share/meson/mesonbuild/backend/ninjabackend.py", line 470, in generate_target
    elem = self.generate_link(target, outfile, outname, obj_list, linker, pch_objects)
  File "/usr/share/meson/mesonbuild/backend/ninjabackend.py", line 2491, in generate_link
    commands += linker.thread_link_flags(self.environment)
AttributeError: 'LLVMDCompiler' object has no attribute 'thread_link_flags'

that does not allow me to go any further.

Is there any way to do this with meson, is this a bug that has to be fixed? Thanks in advance!

dcbaker commented 5 years ago

Currently we use a very small subset of the output from --cppflags, as well as --libs with --link-shared or --link-static You do need some of the cppflags to successfully link, but we try to throw away the ones that are bogus (thought it appears LLVM has stopped adding quite so much garbage to cppflags).

As for the C++ thing, we don't really have a good way in meson to signal that you are going to use the C API (and it's pretty limited compared to the C++ one), but I understand why you'd need the C interfaces from D.

The actual error you're running into looks like a legitimate bug though.

dcbaker commented 5 years ago

You are using a pretty old version of meson, and there has been a lot of work in the D compilers since then. Could you try 0.51.2 or master?

edit: fix typo

streaksu commented 5 years ago

Using 0.51.2 fixes the meson error, but since the Cpp flags are passed for compilation to the D compiler in use, it just cannot compile.