Skip to content

Commit

Permalink
fix using a CustomTargetIndex for vs_module_defs
Browse files Browse the repository at this point in the history
Because `CustomTargetIndex`es don't have a `subdir` property, but they do
implement the `get_subdir()` method
  • Loading branch information
dcbaker committed Sep 26, 2023
1 parent c98ae2b commit ff21d87
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 7 deletions.
8 changes: 8 additions & 0 deletions docs/markdown/snippets/vs_module_defs_customtargetindex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## vs_module_defs keyword now supports indexes of custom_target

This means you can do something like:
```meson
defs = custom_target('generate_module_defs', ...)
shared_library('lib1', vs_module_defs : defs[0])
shared_library('lib2', vs_module_defs : defs[2])
```
2 changes: 2 additions & 0 deletions docs/yaml/functions/shared_library.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ kwargs:
Specify a Microsoft module definition file for controlling symbol exports,
etc., on platforms where that is possible (e.g. Windows).
*(Since 1.3.0)* indexes of custom_target are supported
rust_abi:
type: str
since: 1.3.0
Expand Down
2 changes: 2 additions & 0 deletions docs/yaml/functions/shared_module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ kwargs:
Specify a Microsoft module definition file for controlling symbol exports,
etc., on platforms where that is possible (e.g. Windows).
*(Since 1.3.0)* indexes of custom_target are supported
rust_abi:
type: str
since: 1.3.0
Expand Down
6 changes: 3 additions & 3 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2333,13 +2333,13 @@ def process_kwargs(self, kwargs):
elif isinstance(path, File):
# When passing a generated file.
self.vs_module_defs = path
elif isinstance(path, CustomTarget):
elif isinstance(path, (CustomTarget, CustomTargetIndex)):
# When passing output of a Custom Target
self.vs_module_defs = File.from_built_file(path.subdir, path.get_filename())
self.vs_module_defs = File.from_built_file(path.get_subdir(), path.get_filename())
else:
raise InvalidArguments(
'Shared library vs_module_defs must be either a string, '
'a file object or a Custom Target')
'a file object, a Custom Target, or a Custom Target Index')
self.process_link_depends(path)

rust_abi = kwargs.get('rust_abi')
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/interpreter/kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class _SharedLibMixin(TypedDict):
darwin_versions: T.Optional[T.Tuple[str, str]]
soversion: T.Optional[str]
version: T.Optional[str]
vs_module_defs: T.Optional[T.Union[str, File, build.CustomTarget]]
vs_module_defs: T.Optional[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex]]


class SharedLibrary(_BuildTarget, _SharedLibMixin):
Expand All @@ -356,7 +356,7 @@ class SharedLibrary(_BuildTarget, _SharedLibMixin):

class SharedModule(_BuildTarget):

vs_module_defs: T.Optional[T.Union[str, File, build.CustomTarget]]
vs_module_defs: T.Optional[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex]]


class Library(_BuildTarget, _SharedLibMixin):
Expand Down
5 changes: 3 additions & 2 deletions mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,10 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus
since='1.3.0',
validator=in_set_validator({'rust', 'c'}))

_VS_MODULE_DEFS_KW: KwargInfo[T.Union[str, File, CustomTarget]] = KwargInfo(
_VS_MODULE_DEFS_KW: KwargInfo[T.Union[str, File, CustomTarget, CustomTargetIndex]] = KwargInfo(
'vs_module_defs',
(str, File, CustomTarget, NoneType),
(str, File, CustomTarget, CustomTargetIndex, NoneType),
since_values={CustomTargetIndex: '1.3.0'}
)

# Applies to all build_target like classes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ def_file = custom_target('gen_def',
output: 'somedll.def')

shlib = shared_library('somedll', 'somedll.c', vs_module_defs: def_file)

shared_library('somedll2', 'somedll.c', vs_module_defs: def_file[0])

0 comments on commit ff21d87

Please sign in to comment.