Bug 1465633 - Introduce a moz.build variable to pass -Os instead of other optimize flags when building with clang-cl. draft
authorChris Manchester <cmanchester@mozilla.com>
Mon, 04 Jun 2018 14:48:10 -0700
changeset 803838 28e7d1b0b47c16e2a854120e3a575c69ae3d3f62
parent 802528 42880a726964a0bd66e2f636931e8322eae86ef7
push id112207
push userbmo:cmanchester@mozilla.com
push dateMon, 04 Jun 2018 21:48:31 +0000
bugs1465633
milestone62.0a1
Bug 1465633 - Introduce a moz.build variable to pass -Os instead of other optimize flags when building with clang-cl. MozReview-Commit-ID: J3TfnvHUZaQ
python/mozbuild/mozbuild/frontend/context.py
python/mozbuild/mozbuild/frontend/emitter.py
--- a/python/mozbuild/mozbuild/frontend/context.py
+++ b/python/mozbuild/mozbuild/frontend/context.py
@@ -1221,16 +1221,21 @@ VARIABLES = {
 
     'IS_RUST_LIBRARY': (bool, bool,
         """Whether the current library defined by this moz.build is built by Rust.
 
         The library defined by this moz.build should have a build definition in
         a Cargo.toml file that exists in this moz.build's directory.
         """),
 
+    'CLANG_CL_OPTIMIZE_FOR_SIZE': (bool, bool,
+        """Optimize code in this directory for size when compiling with clang-cl.
+        Passes -Os instead of other optimize flags.
+        """),
+
     '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.
         """),
 
     'RUST_LIBRARY_TARGET_DIR': (unicode, unicode,
--- a/python/mozbuild/mozbuild/frontend/emitter.py
+++ b/python/mozbuild/mozbuild/frontend/emitter.py
@@ -1030,16 +1030,20 @@ class TreeMetadataEmitter(LoggingMixin):
         for v in ['CMFLAGS', 'CMMFLAGS']:
             if v in context and context[v]:
                 passthru.variables['MOZBUILD_' + v] = context[v]
 
         for v in ['CXXFLAGS', 'CFLAGS']:
             if v in context and context[v]:
                 computed_flags.resolve_flags('MOZBUILD_%s' % v, context[v])
 
+        clang_cl_optimize_for_size = context['CLANG_CL_OPTIMIZE_FOR_SIZE']
+        if clang_cl_optimize_for_size and context.config.substs.get('CLANG_CL'):
+            computed_flags.resolve_flags('OPTIMIZE', ['-Os'])
+
         for v in ['HOST_CXXFLAGS', 'HOST_CFLAGS']:
             if v in context and context[v]:
                 computed_host_flags.resolve_flags('MOZBUILD_%s' % v, context[v])
 
         if 'LDFLAGS' in context and context['LDFLAGS']:
             computed_link_flags.resolve_flags('MOZBUILD', context['LDFLAGS'])
 
         deffile = context['DEFFILE']