From 68b3693ba8ce7277938f8fe4d500499520a6d8c8 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 9 Dec 2024 13:48:36 -0800 Subject: [PATCH] build: Support debug_rename and import_rename in exe, shlib and shmod 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 --- docs/yaml/functions/executable.yaml | 16 ++++++ docs/yaml/functions/shared_library.yaml | 16 ++++++ docs/yaml/functions/shared_module.yaml | 16 ++++++ mesonbuild/backend/backends.py | 4 +- mesonbuild/build.py | 54 +++++++++++++++++-- mesonbuild/interpreter/type_checking.py | 9 +++- .../common/117 shared module/meson.build | 8 ++- test cases/common/117 shared module/test.json | 4 +- 8 files changed, 118 insertions(+), 9 deletions(-) diff --git a/docs/yaml/functions/executable.yaml b/docs/yaml/functions/executable.yaml index abbc5feee909..86392b403d82 100644 --- a/docs/yaml/functions/executable.yaml +++ b/docs/yaml/functions/executable.yaml @@ -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. diff --git a/docs/yaml/functions/shared_library.yaml b/docs/yaml/functions/shared_library.yaml index f633aca966fe..df45f158eb69 100644 --- a/docs/yaml/functions/shared_library.yaml +++ b/docs/yaml/functions/shared_library.yaml @@ -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. diff --git a/docs/yaml/functions/shared_module.yaml b/docs/yaml/functions/shared_module.yaml index 6b94e56add4a..02d1e73a7f66 100644 --- a/docs/yaml/functions/shared_module.yaml +++ b/docs/yaml/functions/shared_module.yaml @@ -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. diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index a51d801ce8c9..44857a8775e5 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -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(): @@ -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: diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 526fe990317d..64fc60a958d0 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -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'} @@ -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) @@ -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 @@ -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: @@ -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" diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py index 9f86ec53f5c8..8cc2118c1431 100644 --- a/mesonbuild/interpreter/type_checking.py +++ b/mesonbuild/interpreter/type_checking.py @@ -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 @@ -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 @@ -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 = [ diff --git a/test cases/common/117 shared module/meson.build b/test cases/common/117 shared module/meson.build index 3fa7847d94bf..a97bfbc179bf 100644 --- a/test cases/common/117 shared module/meson.build +++ b/test cases/common/117 shared module/meson.build @@ -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 @@ -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 diff --git a/test cases/common/117 shared module/test.json b/test cases/common/117 shared module/test.json index dc32c311a703..2847a4887805 100644 --- a/test cases/common/117 shared module/test.json +++ b/test cases/common/117 shared module/test.json @@ -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"} ] }