1313from . import ExtensionModule , ModuleReturnValue , ModuleInfo , ModuleObject
1414from .. import mesonlib , mlog
1515from ..build import (BothLibraries , BuildTarget , CustomTargetIndex , Executable , ExtractedObjects , GeneratedList ,
16- CustomTarget , InvalidArguments , Jar , StructuredSources , SharedLibrary , StaticLibrary )
16+ CustomTarget , InvalidArguments , Jar , StructuredSources , SharedLibrary , StaticLibrary ,
17+ SharedModule )
1718from ..compilers .compilers import are_asserts_disabled_for_subproject , lang_suffixes
1819from ..compilers .rust import RustSystemDependency
1920from ..dependencies import Dependency
2021from ..interpreter .type_checking import (
2122 DEPENDENCIES_KW , LINK_WITH_KW , LINK_WHOLE_KW , SHARED_LIB_KWS , TEST_KWS , TEST_KWS_NO_ARGS ,
2223 OUTPUT_KW , INCLUDE_DIRECTORIES , SOURCES_VARARGS , NoneType , in_set_validator ,
23- EXECUTABLE_KWS , LIBRARY_KWS , _BASE_LANG_KW
24+ EXECUTABLE_KWS , LIBRARY_KWS , SHARED_MOD_KWS , _BASE_LANG_KW
2425)
2526from ..interpreterbase import ContainerTypeInfo , InterpreterException , KwargInfo , typed_kwargs , typed_pos_args , noKwargs , noPosargs , permittedKwargs
2627from ..interpreter .interpreterobjects import Doctest
@@ -247,6 +248,7 @@ def __init__(self, rust_ws: RustWorkspace, package: cargo.PackageState) -> None:
247248 'dependencies' : self .dependencies_method ,
248249 'library' : self .library_method ,
249250 'proc_macro' : self .proc_macro_method ,
251+ 'shared_module' : self .shared_module_method ,
250252 'executable' : self .executable_method ,
251253 })
252254
@@ -313,7 +315,8 @@ def merge_kw_args(self, state: ModuleState, kwargs: T.Union[RustPackageExecutabl
313315 def _library_method (self , state : ModuleState , args : T .Tuple [
314316 T .Optional [T .Union [str , StructuredSources ]],
315317 T .Optional [StructuredSources ]], kwargs : RustPackageLibrary ,
316- static : bool , shared : bool ) -> T .Union [BothLibraries , SharedLibrary , StaticLibrary ]:
318+ static : bool , shared : bool ,
319+ shared_mod : bool = False ) -> T .Union [BothLibraries , SharedLibrary , StaticLibrary ]:
317320 tgt_args = self .validate_pos_args ('package.library' , args )
318321 if not self .package .manifest .lib :
319322 raise MesonException ("no [lib] section in Cargo package" )
@@ -333,6 +336,11 @@ def _library_method(self, state: ModuleState, args: T.Tuple[
333336 lib_args : T .Tuple [str , SourcesVarargsType ] = (tgt_name , [sources ])
334337 self .merge_kw_args (state , kwargs )
335338
339+ if shared_mod :
340+ return state ._interpreter .build_target (state .current_node , lib_args ,
341+ T .cast ('_kwargs.SharedModule' , kwargs ),
342+ SharedModule )
343+
336344 if static and shared :
337345 return state ._interpreter .build_both_libraries (state .current_node , lib_args , kwargs )
338346 elif shared :
@@ -400,6 +408,28 @@ def proc_macro_method(self, state: 'ModuleState', args: T.Tuple[
400408 raise MesonException ("not a procedural macro crate" )
401409 return self ._proc_macro_method (state , args , kwargs )
402410
411+ @typed_pos_args ('package.shared_module' , optargs = [(str , StructuredSources ), StructuredSources ])
412+ @typed_kwargs (
413+ 'package.shared_module' ,
414+ * SHARED_MOD_KWS ,
415+ DEPENDENCIES_KW ,
416+ LINK_WITH_KW ,
417+ LINK_WHOLE_KW ,
418+ _BASE_LANG_KW .evolve (name = 'rust_args' ),
419+ )
420+ def shared_module_method (self , state : 'ModuleState' , args : T .Tuple [
421+ T .Optional [T .Union [str , StructuredSources ]],
422+ T .Optional [StructuredSources ]], kwargs : RustPackageLibrary ) -> SharedModule :
423+ if not self .package .manifest .lib :
424+ raise MesonException ("no [lib] section in Cargo package" )
425+ if 'cdylib' not in self .package .manifest .lib .crate_type :
426+ raise MesonException ("not a cdylib crate" )
427+
428+ kwargs ['rust_abi' ] = None
429+ kwargs ['rust_crate_type' ] = 'cdylib'
430+ result = self ._library_method (state , args , kwargs , shared = True , static = False , shared_mod = True )
431+ return T .cast ('SharedModule' , result )
432+
403433 @typed_pos_args ('package.executable' , optargs = [(str , StructuredSources ), StructuredSources ])
404434 @typed_kwargs (
405435 'package.executable' ,
0 commit comments