summaryrefslogtreecommitdiff
path: root/mesonbuild/modules/rust.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2023-10-16 10:07:32 -0700
committerDylan Baker <dylan@pnwbakers.com>2024-02-23 09:48:32 -0800
commit05d49c6990aedb850266f22b40442af7a54e13fc (patch)
tree139893a88c8c89f5e6085220d88229c3d06540ad /mesonbuild/modules/rust.py
parent8ac434694395037e242318e6926c85c1fcccd9b8 (diff)
downloadmeson-05d49c6990aedb850266f22b40442af7a54e13fc.tar.gz
modules/rust: Allow explicitly setting the language to bind
This may be of particular use when a header is .h but should be treated as a C++ header instead of a C header.
Diffstat (limited to 'mesonbuild/modules/rust.py')
-rw-r--r--mesonbuild/modules/rust.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/mesonbuild/modules/rust.py b/mesonbuild/modules/rust.py
index caa1be296..4978f1205 100644
--- a/mesonbuild/modules/rust.py
+++ b/mesonbuild/modules/rust.py
@@ -13,7 +13,10 @@ from .. import mlog
from ..build import (BothLibraries, BuildTarget, CustomTargetIndex, Executable, ExtractedObjects, GeneratedList,
CustomTarget, InvalidArguments, Jar, StructuredSources, SharedLibrary)
from ..compilers.compilers import are_asserts_disabled, lang_suffixes
-from ..interpreter.type_checking import DEPENDENCIES_KW, LINK_WITH_KW, SHARED_LIB_KWS, TEST_KWS, OUTPUT_KW, INCLUDE_DIRECTORIES, SOURCES_VARARGS
+from ..interpreter.type_checking import (
+ DEPENDENCIES_KW, LINK_WITH_KW, SHARED_LIB_KWS, TEST_KWS, OUTPUT_KW,
+ INCLUDE_DIRECTORIES, SOURCES_VARARGS, NoneType, in_set_validator
+)
from ..interpreterbase import ContainerTypeInfo, InterpreterException, KwargInfo, typed_kwargs, typed_pos_args, noPosargs, permittedKwargs
from ..mesonlib import File
@@ -27,7 +30,7 @@ if T.TYPE_CHECKING:
from ..programs import ExternalProgram, OverrideProgram
from ..interpreter.type_checking import SourcesVarargsType
- from typing_extensions import TypedDict
+ from typing_extensions import TypedDict, Literal
class FuncTest(_kwargs.BaseTest):
@@ -44,6 +47,7 @@ if T.TYPE_CHECKING:
input: T.List[SourceInputs]
output: str
dependencies: T.List[T.Union[Dependency, ExternalLibrary]]
+ language: T.Optional[Literal['c', 'cpp']]
class RustModule(ExtensionModule):
@@ -187,6 +191,7 @@ class RustModule(ExtensionModule):
listify=True,
required=True,
),
+ KwargInfo('language', (str, NoneType), since='1.4.0', validator=in_set_validator({'c', 'cpp'})),
INCLUDE_DIRECTORIES.evolve(since_values={ContainerTypeInfo(list, str): '1.0.0'}),
OUTPUT_KW,
DEPENDENCIES_KW.evolve(since='1.0.0'),
@@ -243,7 +248,15 @@ class RustModule(ExtensionModule):
# bindgen assumes that C++ headers will be called .hpp. We want to
# ensure that anything Meson considers a C++ header is treated as one.
- language = 'cpp' if os.path.splitext(name)[1][1:] in lang_suffixes['cpp'] else 'c'
+ language = kwargs['language']
+ if language is None:
+ ext = os.path.splitext(name)[1][1:]
+ if ext in lang_suffixes['cpp']:
+ language = 'cpp'
+ elif ext == 'h':
+ language = 'c'
+ else:
+ raise InterpreterException(f'Unknown file type extension for: {name}')
# We only want include directories and defines, other things may not be valid
cargs = state.get_option('args', state.subproject, lang=language)
@@ -252,8 +265,6 @@ class RustModule(ExtensionModule):
if a.startswith(('-I', '/I', '-D', '/D', '-U', '/U')):
clang_args.append(a)
- # bindgen assumes that C++ headers will be called .hpp. We want to
- # ensure that anything Meson considers a C++ header is treated as one.
if language == 'cpp':
clang_args.extend(['-x', 'c++'])