Bug 1293253 - part 4 - add frontend objects for Rust programs; r=chmanchester
authorNathan Froyd <froydnj@mozilla.com>
Mon, 28 Nov 2016 11:20:39 -0500
changeset 324481 5586b76ab2a4c7b059485206e36217bc8c0bc4d2
parent 324480 009cffc985ab7e9b5736edfd6c68f9f5203915bb
child 324482 bc2b70ec392bff7672decd92483eed5553eb0310
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewerschmanchester
bugs1293253
milestone53.0a1
Bug 1293253 - part 4 - add frontend objects for Rust programs; r=chmanchester
python/mozbuild/mozbuild/frontend/data.py
--- a/python/mozbuild/mozbuild/frontend/data.py
+++ b/python/mozbuild/mozbuild/frontend/data.py
@@ -417,24 +417,57 @@ class SimpleProgram(BaseProgram):
 
 class HostSimpleProgram(HostMixin, BaseProgram):
     """Context derived container object for each program in
     HOST_SIMPLE_PROGRAMS"""
     SUFFIX_VAR = 'HOST_BIN_SUFFIX'
     KIND = 'host'
 
 
-def cargo_target_directory(context):
+def cargo_target_directory(context, target_var='RUST_TARGET'):
     # cargo creates several directories and places its build artifacts
     # in those directories.  The directory structure depends not only
     # on the target, but also what sort of build we are doing.
     rust_build_kind = 'release'
     if context.config.substs.get('MOZ_DEBUG'):
         rust_build_kind = 'debug'
-    return mozpath.join(context.config.substs['RUST_TARGET'], rust_build_kind)
+    return mozpath.join(context.config.substs[target_var], rust_build_kind)
+
+
+# Rust programs aren't really Linkable, since Cargo handles all the details
+# of linking things.
+class BaseRustProgram(ContextDerived):
+    __slots__ = (
+        'name',
+        'cargo_file',
+        'location',
+        'SUFFIX_VAR',
+        'KIND',
+        'TARGET_SUBST_VAR',
+    )
+
+    def __init__(self, context, name, cargo_file):
+        ContextDerived.__init__(self, context)
+        self.name = name
+        self.cargo_file = cargo_file
+        cargo_dir = cargo_target_directory(context, self.TARGET_SUBST_VAR)
+        exe_file = '%s%s' % (name, context.config.substs.get(self.SUFFIX_VAR, ''))
+        self.location = mozpath.join(cargo_dir, exe_file)
+
+
+class RustProgram(BaseRustProgram):
+    SUFFIX_VAR = 'BIN_SUFFIX'
+    KIND = 'target'
+    TARGET_SUBST_VAR = 'RUST_TARGET'
+
+
+class HostRustProgram(BaseRustProgram):
+    SUFFIX_VAR = 'HOST_BIN_SUFFIX'
+    KIND = 'host'
+    TARGET_SUBST_VAR = 'RUST_HOST_TARGET'
 
 
 class BaseLibrary(Linkable):
     """Generic context derived container object for libraries."""
     __slots__ = (
         'basename',
         'lib_name',
         'import_name',