Skip to content

Commit

Permalink
fix type checking for declare_dependency to allow linking to executable
Browse files Browse the repository at this point in the history
We have to handle this, because Windows needs to link to the implib of
the executable (???) in order to create a shared module. This is
explicitly checked for and handled in the backend, and creating a build
target with `link_with: some_exe` still works, even. But updating
declare_dependency to typed_kwargs neglected to take that into account,
so creating a convenience interface for those same arguments failed.
  • Loading branch information
eli-schwartz committed Jun 21, 2022
1 parent a20523a commit b05d7db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .. import compilers
from ..build import (EnvironmentVariables, EnvInitValueType, CustomTarget, BuildTarget,
CustomTargetIndex, ExtractedObjects, GeneratedList, IncludeDirs,
BothLibraries, SharedLibrary, StaticLibrary, Jar)
BothLibraries, SharedLibrary, StaticLibrary, Jar, Executable)
from ..coredata import UserFeatureOption
from ..dependencies import Dependency, InternalDependency
from ..interpreterbase.decorators import KwargInfo, ContainerTypeInfo
Expand Down Expand Up @@ -400,9 +400,9 @@ def _output_validator(outputs: T.List[str]) -> T.Optional[str]:
_link_with_error = '''can only be self-built targets, external dependencies (including libraries) must go in "dependencies".'''

# Allow Dependency for the better error message? But then in other cases it will list this as one of the allowed types!
LINK_WITH_KW: KwargInfo[T.List[T.Union[BothLibraries, SharedLibrary, StaticLibrary, CustomTarget, CustomTargetIndex, Jar]]] = KwargInfo(
LINK_WITH_KW: KwargInfo[T.List[T.Union[BothLibraries, SharedLibrary, StaticLibrary, CustomTarget, CustomTargetIndex, Jar, Executable]]] = KwargInfo(
'link_with',
ContainerTypeInfo(list, (BothLibraries, SharedLibrary, StaticLibrary, CustomTarget, CustomTargetIndex, Jar, Dependency)),
ContainerTypeInfo(list, (BothLibraries, SharedLibrary, StaticLibrary, CustomTarget, CustomTargetIndex, Jar, Executable, Dependency)),
listify=True,
default=[],
validator=lambda x: _link_with_error if isinstance(x, Dependency) else None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ endif

dl = meson.get_compiler('c').find_library('dl', required: false)
e = executable('prog', 'prog.c', dependencies: dl, export_dynamic: true)
e_dep = declare_dependency(link_with: e)

m = shared_module('module', 'module.c', link_with: e)
m2 = shared_module('module2', 'module.c', dependencies: e_dep)

test('test', e, args: m.full_path())
test('test2', e, args: m2.full_path())

0 comments on commit b05d7db

Please sign in to comment.