Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiler.links for vala #13125

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions mesonbuild/compilers/vala.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
import typing as T

from .. import mlog
from .. import mesonlib
from ..mesonlib import EnvironmentException, version_compare, LibType, OptionKey
from .compilers import CompileCheckMode, Compiler
from ..arglist import CompilerArgs

if T.TYPE_CHECKING:
from ..coredata import KeyedOptionDictType
from ..envconfig import MachineInfo
from ..environment import Environment
from ..mesonlib import MachineChoice
from ..dependencies import Dependency

class ValaCompiler(Compiler):

Expand All @@ -25,6 +29,7 @@ def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoic
super().__init__([], exelist, version, for_machine, info, is_cross=is_cross)
self.version = version
self.base_options = {OptionKey('b_colorout')}
self.force_link = False

def needs_static_linker(self) -> bool:
return False # Because compiles into C.
Expand All @@ -41,6 +46,20 @@ def get_output_args(self, outputname: str) -> T.List[str]:
def get_compile_only_args(self) -> T.List[str]:
return [] # Because compiles into C.

def get_compiler_args_for_mode(self, mode: CompileCheckMode) -> T.List[str]:
args: T.List[str] = []
if mode is CompileCheckMode.LINK and self.force_link:
return args
args += self.get_always_args()
if mode is CompileCheckMode.COMPILE:
args += self.get_compile_only_args()
elif mode is CompileCheckMode.PREPROCESS:
args += self.get_preprocess_only_args()
return args

def get_preprocess_only_args(self) -> T.List[str]:
return []

def get_pic_args(self) -> T.List[str]:
return []

Expand Down Expand Up @@ -119,3 +138,24 @@ def thread_flags(self, env: 'Environment') -> T.List[str]:

def thread_link_flags(self, env: 'Environment') -> T.List[str]:
return []

def get_option_link_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
return []

def links(self, code: 'mesonlib.FileOrString', env: 'Environment', *,
compiler: T.Optional['Compiler'] = None,
extra_args: T.Union[None, T.List[str], CompilerArgs, T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None,
disable_cache: bool = False) -> T.Tuple[bool, bool]:
self.force_link = True
bcorby marked this conversation as resolved.
Show resolved Hide resolved
if compiler:
with compiler._build_wrapper(code, env, dependencies=dependencies, want_output=True) as r:
objfile = mesonlib.File.from_absolute_file(r.output_name)
result = self.compiles(objfile, env, extra_args=extra_args,
dependencies=dependencies, mode=CompileCheckMode.LINK, disable_cache=True)
self.force_link = False
return result
result = self.compiles(code, env, extra_args=extra_args,
dependencies=dependencies, mode=CompileCheckMode.LINK, disable_cache=disable_cache)
self.force_link = False
return result
24 changes: 24 additions & 0 deletions test cases/vala/29 compiler.links/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
project('link-test', ['c', 'vala'], version: '0.1')

valac = meson.get_compiler('vala')

code = '''void main() {
const double PI3 = 1.047197551196597746154214461093167628;
var a = GLib.Math.cos (PI3);
stdout.printf ("%f\n", a); }'''

# test 1; code should link
code_links = valac.links(
code,
args: '--Xcc=-lm',
name: 'links with math library? == YES',
)
assert (code_links, 'Math library should link successfully.')

# test 2; code should not link
code_links = valac.links(
code,
args: '--Xcc=-lfake_library_90DFE450330A',
name: 'links with fake library? == NO',
)
assert (not code_links, 'Fake library should not link successfully.')
Loading