Skip to content

Commit

Permalink
build: Support debug_rename and import_rename in exe, shlib and shmod
Browse files Browse the repository at this point in the history
Executables, shared libraries and shared modules may all install two
additional files, an import library and a debuginfo file. Provide new
keyword arguments, 'import_rename', and 'debug_rename' so that these
can be installed with names matching the output filename when
using the 'rename' keyword argument.

Signed-off-by: Keith Packard <[email protected]>
  • Loading branch information
keith-packard committed Dec 9, 2024
1 parent 4605db8 commit 68b3693
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 9 deletions.
16 changes: 16 additions & 0 deletions docs/yaml/functions/executable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,19 @@ kwargs:
This can be used to expose which functions a shared_module loaded by an
executable will be allowed to use.
import_rename:
type: str
since: 1.7.0
description: |
If specified, renames the import library during install. Nested
paths are allowed and they are joined with `install_dir`. If
the value is an empty string, then this feature is disabled.
debug_rename:
type: str
since: 1.7.0
description: |
If specified, renames the debuginfo file during install. Nested
paths are allowed and they are joined with `install_dir`. If
the value is an empty string, then this feature is disabled.
16 changes: 16 additions & 0 deletions docs/yaml/functions/shared_library.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,19 @@ kwargs:
Set the specific ABI to compile (when compiling rust).
- 'rust' (default): Create a "dylib" crate.
- 'c': Create a "cdylib" crate.
import_rename:
type: str
since: 1.7.0
description: |
If specified, renames the import library during install. Nested
paths are allowed and they are joined with `install_dir`. If
the value is an empty string, then this feature is disabled.
debug_rename:
type: str
since: 1.7.0
description: |
If specified, renames the debuginfo file during install. Nested
paths are allowed and they are joined with `install_dir`. If
the value is an empty string, then this feature is disabled.
16 changes: 16 additions & 0 deletions docs/yaml/functions/shared_module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,19 @@ kwargs:
Set the specific ABI to compile (when compiling rust).
- 'rust' (default): Create a "dylib" crate.
- 'c': Create a "cdylib" crate.
import_rename:
type: str
since: 1.7.0
description: |
If specified, renames the import library during install. Nested
paths are allowed and they are joined with `install_dir`. If
the value is an empty string, then this feature is disabled.
debug_rename:
type: str
since: 1.7.0
description: |
If specified, renames the debuginfo file during install. Nested
paths are allowed and they are joined with `install_dir`. If
the value is an empty string, then this feature is disabled.
4 changes: 2 additions & 2 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ def generate_target_install(self, d: InstallData) -> None:
implib_install_dir, first_outdir_name,
False, {}, set(), '', install_mode,
t.subproject, optional=isinstance(t, build.SharedModule),
tag='devel')
tag='devel', out_fname = t.get_import_rename())
d.targets.append(i)

if not should_strip and t.get_debug_filename():
Expand All @@ -1787,7 +1787,7 @@ def generate_target_install(self, d: InstallData) -> None:
first_outdir_name,
False, {}, set(), '',
install_mode, t.subproject,
optional=True, tag='devel')
optional=True, tag='devel', out_fname = t.get_debug_rename())
d.targets.append(i)
# Install secondary outputs. Only used for Vala right now.
if num_outdirs > 1:
Expand Down
54 changes: 51 additions & 3 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ class DFeatures(TypedDict):
rust_kwargs |
cs_kwargs)

known_exe_kwargs = known_build_target_kwargs | {'implib', 'export_dynamic', 'pie', 'vs_module_defs'}
known_shlib_kwargs = known_build_target_kwargs | {'version', 'soversion', 'vs_module_defs', 'darwin_versions', 'rust_abi'}
known_shmod_kwargs = known_build_target_kwargs | {'vs_module_defs', 'rust_abi'}
known_exe_kwargs = known_build_target_kwargs | {'implib', 'export_dynamic', 'pie', 'vs_module_defs', 'import_rename', 'debug_rename'}
known_shlib_kwargs = known_build_target_kwargs | {'version', 'soversion', 'vs_module_defs', 'darwin_versions', 'rust_abi', 'import_rename', 'debug_rename'}
known_shmod_kwargs = known_build_target_kwargs | {'vs_module_defs', 'rust_abi', 'import_rename', 'debug_rename'}
known_stlib_kwargs = known_build_target_kwargs | {'pic', 'prelink', 'rust_abi'}
known_jar_kwargs = known_exe_kwargs | {'main_class', 'java_resources'}

Expand Down Expand Up @@ -1995,6 +1995,10 @@ def __init__(
# Remember that this exe was returned by `find_program()` through an override
self.was_returned_by_find_program = False

# Get renames for import library and debuginfo file
self.import_rename = kwargs.get('import_rename')
self.debug_rename = kwargs.get('debug_rename')

self.vs_module_defs: T.Optional[File] = None
self.process_vs_module_defs_kw(kwargs)

Expand Down Expand Up @@ -2097,6 +2101,26 @@ def get_debug_filename(self) -> T.Optional[str]:
"""
return self.debug_filename

def get_import_rename(self)-> T.Optional[str]:
"""
The filename to be used while installing the import library
Returns None if no value was provided
"""
if self.import_rename:
return self.import_rename
return None

def get_debug_rename(self)-> T.Optional[str]:
"""
The filename to be used while installing the debug info
Returns None if no value was provided
"""
if self.debug_rename:
return self.debug_rename
return None

def is_linkable_target(self):
return self.is_linkwithable

Expand Down Expand Up @@ -2419,6 +2443,10 @@ def process_kwargs(self, kwargs):
# Visual Studio module-definitions file
self.process_vs_module_defs_kw(kwargs)

# Get renames for import library and debuginfo file
self.import_rename = kwargs.get('import_rename')
self.debug_rename = kwargs.get('debug_rename')

rust_abi = kwargs.get('rust_abi')
rust_crate_type = kwargs.get('rust_crate_type')
if rust_crate_type:
Expand Down Expand Up @@ -2484,6 +2512,26 @@ def get_aliases(self) -> T.List[T.Tuple[str, str, str]]:
aliases.append((self.basic_filename_tpl.format(self), ltversion_filename, tag))
return aliases

def get_import_rename(self)-> T.Optional[str]:
"""
The filename to be used while installing the import library
Returns None if no value was provided
"""
if self.import_rename:
return self.import_rename
return None

def get_debug_rename(self)-> T.Optional[str]:
"""
The filename to be used while installing the debug info
Returns None if no value was provided
"""
if self.debug_rename:
return self.debug_rename
return None

def type_suffix(self):
return "@sha"

Expand Down
9 changes: 8 additions & 1 deletion mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,8 @@ def _convert_darwin_versions(val: T.List[T.Union[str, int]]) -> T.Optional[T.Tup
convertor=lambda x: x.lower() if isinstance(x, str) else None,
validator=_validate_win_subsystem,
),
KwargInfo('debug_rename', str, default='', since='1.7.0'),
KwargInfo('import_rename', str, default='', since='1.7.0'),
]

# The total list of arguments used by Executable
Expand Down Expand Up @@ -753,6 +755,8 @@ def _convert_darwin_versions(val: T.List[T.Union[str, int]]) -> T.Optional[T.Tup
_DARWIN_VERSIONS_KW,
KwargInfo('soversion', (str, int, NoneType), convertor=lambda x: str(x) if x is not None else None),
KwargInfo('version', (str, NoneType), validator=_validate_shlib_version),
KwargInfo('debug_rename', str, default='', since='1.7.0'),
KwargInfo('import_rename', str, default='', since='1.7.0'),
]

# The total list of arguments used by SharedLibrary
Expand All @@ -766,7 +770,10 @@ def _convert_darwin_versions(val: T.List[T.Union[str, int]]) -> T.Optional[T.Tup

# Arguments exclusive to SharedModule. These are separated to make integrating
# them into build_target easier
_EXCLUSIVE_SHARED_MOD_KWS: T.List[KwargInfo] = []
_EXCLUSIVE_SHARED_MOD_KWS: T.List[KwargInfo] = [
KwargInfo('debug_rename', str, default='', since='1.7.0'),
KwargInfo('import_rename', str, default='', since='1.7.0'),
]

# The total list of arguments used by SharedModule
SHARED_MOD_KWS = [
Expand Down
8 changes: 7 additions & 1 deletion test cases/common/117 shared module/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ test('import test', e, args : m)
m2 = build_target('mymodule2', 'module.c', target_type: 'shared_module')
test('import test 2', e, args : m2)

import_rename = 'subdir/libmymodule.dll.a'
debug_rename = ''
if target_machine.system() == 'windows'
rename = 'subdir/libmymodule.dll'
debug_rename = 'subdir/libmymodule.pdb'
elif target_machine.system() == 'darwin'
rename = 'subdir/libmymodule.dylib'
elif target_machine.system() == 'cygwin'
rename = 'subdir/cygmymodule.dll'
debug_rename = 'subdir/cygmymodule.pdb'
else
rename = 'subdir/libmymodule.so'
endif
Expand All @@ -48,7 +52,9 @@ endif
m3 = shared_module('mymodule3', 'module.c',
install : true,
install_dir : join_paths(get_option('libdir'), 'modules'),
rename: rename)
rename: rename,
import_rename: import_rename,
debug_rename: debug_rename)
test('import test 3', e, args : m3)

# Shared module that does not export any symbols
Expand Down
4 changes: 2 additions & 2 deletions test cases/common/117 shared module/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{"type": "implibempty", "file": "usr/lib/modules/libnosyms"},
{"type": "pdb", "file": "usr/lib/modules/nosyms"},
{"type": "expr", "file": "usr/lib/modules/subdir/libmymodule?so"},
{"type": "implib", "file": "usr/lib/modules/libmymodule3"},
{"type": "pdb", "file": "usr/lib/modules/mymodule3"}
{"type": "implib", "file": "usr/lib/modules/subdir/libmymodule"},
{"type": "pdb", "file": "usr/lib/modules/subdir/mymodule"}
]
}

0 comments on commit 68b3693

Please sign in to comment.