mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 18:04:46 +00:00
Bug 1302704 - part 3 - propagate information about CARGO_TARGET_DIR from the frontend into the backend; r=chmanchester
Rust libraries can set RUST_LIBRARY_TARGET_DIR so that they can share compilation artifacts with other libraries. This setting needs to be propagated to the backend so it can be communicated to Cargo.
This commit is contained in:
parent
22a91bfe53
commit
a13c8b0b74
@ -61,7 +61,7 @@ def Library(name):
|
||||
|
||||
|
||||
@template
|
||||
def RustLibrary(name, features=None):
|
||||
def RustLibrary(name, features=None, target_dir=None):
|
||||
'''Template for Rust libraries.'''
|
||||
Library(name)
|
||||
|
||||
@ -70,6 +70,9 @@ def RustLibrary(name, features=None):
|
||||
if features:
|
||||
RUST_LIBRARY_FEATURES = features
|
||||
|
||||
if target_dir:
|
||||
RUST_LIBRARY_TARGET_DIR = target_dir
|
||||
|
||||
|
||||
@template
|
||||
def SharedLibrary(name):
|
||||
|
@ -1251,7 +1251,13 @@ class RecursiveMakeBackend(CommonBackend):
|
||||
feature_var = 'HOST_RUST_LIBRARY_FEATURES'
|
||||
backend_file.write_once('%s := %s\n' % (libdef.LIB_FILE_VAR, libdef.import_name))
|
||||
backend_file.write('CARGO_FILE := $(srcdir)/Cargo.toml\n')
|
||||
backend_file.write('CARGO_TARGET_DIR := .\n')
|
||||
# Need to normalize the path so Cargo sees the same paths from all
|
||||
# possible invocations of Cargo with this CARGO_TARGET_DIR. Otherwise,
|
||||
# Cargo's dependency calculations don't work as we expect and we wind
|
||||
# up recompiling lots of things.
|
||||
target_dir = mozpath.join(backend_file.objdir, libdef.target_dir)
|
||||
target_dir = mozpath.normpath(target_dir)
|
||||
backend_file.write('CARGO_TARGET_DIR := %s\n' % target_dir)
|
||||
if libdef.features:
|
||||
backend_file.write('%s := %s\n' % (libdef.FEATURES_VAR, ' '.join(libdef.features)))
|
||||
|
||||
|
@ -959,6 +959,15 @@ VARIABLES = {
|
||||
RustLibrary template instead.
|
||||
"""),
|
||||
|
||||
'RUST_LIBRARY_TARGET_DIR': (unicode, unicode,
|
||||
"""Where CARGO_TARGET_DIR should point when compiling this library. If
|
||||
not set, it defaults to the current objdir. It should be a relative path
|
||||
to the current objdir; absolute paths should not be used.
|
||||
|
||||
This variable should not be used directly; you should be using the
|
||||
RustLibrary template instead.
|
||||
"""),
|
||||
|
||||
'HOST_RUST_LIBRARY_FEATURES': (List, list,
|
||||
"""Cargo features to activate for this host library.
|
||||
|
||||
|
@ -523,13 +523,14 @@ class RustLibrary(StaticLibrary):
|
||||
'dependencies',
|
||||
'deps_path',
|
||||
'features',
|
||||
'target_dir',
|
||||
)
|
||||
TARGET_SUBST_VAR = 'RUST_TARGET'
|
||||
FEATURES_VAR = 'RUST_LIBRARY_FEATURES'
|
||||
LIB_FILE_VAR = 'RUST_LIBRARY_FILE'
|
||||
|
||||
def __init__(self, context, basename, cargo_file, crate_type, dependencies,
|
||||
features, **args):
|
||||
features, target_dir, **args):
|
||||
StaticLibrary.__init__(self, context, basename, **args)
|
||||
self.cargo_file = cargo_file
|
||||
self.crate_type = crate_type
|
||||
@ -542,10 +543,12 @@ class RustLibrary(StaticLibrary):
|
||||
basename.replace('-', '_'),
|
||||
context.config.lib_suffix)
|
||||
self.dependencies = dependencies
|
||||
build_dir = cargo_output_directory(context, self.TARGET_SUBST_VAR)
|
||||
build_dir = mozpath.join(target_dir,
|
||||
cargo_output_directory(context, self.TARGET_SUBST_VAR))
|
||||
self.import_name = mozpath.join(build_dir, self.lib_name)
|
||||
self.deps_path = mozpath.join(build_dir, 'deps')
|
||||
self.features = features
|
||||
self.target_dir = target_dir
|
||||
|
||||
|
||||
class SharedLibrary(Library):
|
||||
|
@ -465,6 +465,8 @@ class TreeMetadataEmitter(LoggingMixin):
|
||||
' in [profile.%s] section') % (libname, profile_name),
|
||||
context)
|
||||
|
||||
cargo_target_dir = context.get('RUST_LIBRARY_TARGET_DIR', '.')
|
||||
|
||||
dependencies = set(config.get('dependencies', {}).iterkeys())
|
||||
|
||||
features = context.get(cls.FEATURES_VAR, [])
|
||||
@ -475,7 +477,7 @@ class TreeMetadataEmitter(LoggingMixin):
|
||||
context)
|
||||
|
||||
return cls(context, libname, cargo_file, crate_type, dependencies,
|
||||
features, **static_args)
|
||||
features, cargo_target_dir, **static_args)
|
||||
|
||||
|
||||
def _handle_linkables(self, context, passthru, generated_files):
|
||||
|
@ -764,7 +764,7 @@ class TestRecursiveMakeBackend(BackendTester):
|
||||
expected = [
|
||||
'RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libgkrust.a',
|
||||
'CARGO_FILE := $(srcdir)/Cargo.toml',
|
||||
'CARGO_TARGET_DIR := .',
|
||||
'CARGO_TARGET_DIR := %s' % env.topobjdir,
|
||||
]
|
||||
|
||||
self.assertEqual(lines, expected)
|
||||
@ -779,7 +779,7 @@ class TestRecursiveMakeBackend(BackendTester):
|
||||
expected = [
|
||||
'HOST_RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libhostrusttool.a',
|
||||
'CARGO_FILE := $(srcdir)/Cargo.toml',
|
||||
'CARGO_TARGET_DIR := .',
|
||||
'CARGO_TARGET_DIR := %s' % env.topobjdir,
|
||||
]
|
||||
|
||||
self.assertEqual(lines, expected)
|
||||
@ -794,7 +794,7 @@ class TestRecursiveMakeBackend(BackendTester):
|
||||
expected = [
|
||||
'HOST_RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libhostrusttool.a',
|
||||
'CARGO_FILE := $(srcdir)/Cargo.toml',
|
||||
'CARGO_TARGET_DIR := .',
|
||||
'CARGO_TARGET_DIR := %s' % env.topobjdir,
|
||||
'HOST_RUST_LIBRARY_FEATURES := musthave cantlivewithout',
|
||||
]
|
||||
|
||||
@ -810,7 +810,7 @@ class TestRecursiveMakeBackend(BackendTester):
|
||||
expected = [
|
||||
'RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libgkrust.a',
|
||||
'CARGO_FILE := $(srcdir)/Cargo.toml',
|
||||
'CARGO_TARGET_DIR := .',
|
||||
'CARGO_TARGET_DIR := %s' % env.topobjdir,
|
||||
'RUST_LIBRARY_FEATURES := musthave cantlivewithout',
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user