Bug 1319156 - part 1 - add features to RustLibrary objects and moz.build definitions; r=chmanchester

Ideally, people will just use the extra argument to RustLibrary to
define features for their library.
This commit is contained in:
Nathan Froyd 2016-12-02 11:39:15 -05:00
parent 8783deedb3
commit d861eee0f6
4 changed files with 24 additions and 3 deletions

View File

@ -61,11 +61,15 @@ def Library(name):
@template
def RustLibrary(name):
def RustLibrary(name, features=None):
'''Template for Rust libraries.'''
Library(name)
if not features:
features = []
IS_RUST_LIBRARY = True
RUST_LIBRARY_FEATURES = features
@template

View File

@ -952,6 +952,13 @@ VARIABLES = {
a Cargo.toml file that exists in this moz.build's directory.
"""),
'RUST_LIBRARY_FEATURES': (List, list,
"""Cargo features to activate for this library.
This variable should not be used directly; you should be using the
RustLibrary template instead.
"""),
'UNIFIED_SOURCES': (ContextDerivedTypedList(SourcePath, StrictOrderingOnAppendList), list,
"""Source code files that can be compiled together.

View File

@ -526,9 +526,11 @@ class RustLibrary(StaticLibrary):
'crate_type',
'dependencies',
'deps_path',
'features',
)
def __init__(self, context, basename, cargo_file, crate_type, dependencies, **args):
def __init__(self, context, basename, cargo_file, crate_type, dependencies,
features, **args):
StaticLibrary.__init__(self, context, basename, **args)
self.cargo_file = cargo_file
self.crate_type = crate_type
@ -544,6 +546,7 @@ class RustLibrary(StaticLibrary):
build_dir = cargo_target_directory(context)
self.import_name = mozpath.join(build_dir, self.lib_name)
self.deps_path = mozpath.join(build_dir, 'deps')
self.features = features
class SharedLibrary(Library):

View File

@ -513,8 +513,15 @@ class TreeMetadataEmitter(LoggingMixin):
dependencies = set(config.get('dependencies', {}).iterkeys())
features = context.get('RUST_LIBRARY_FEATURES', [])
unique_features = set(features)
if len(features) != len(unique_features):
raise SandboxValidationError(
'features for %s should not contain duplicates: %s' % (libname, features),
context)
return RustLibrary(context, libname, cargo_file, crate_type,
dependencies, **static_args)
dependencies, features, **static_args)
def _handle_linkables(self, context, passthru, generated_files):
linkables = []