Bug 1465633 - Introduce a moz.build variable to pass -Os instead of other optimize flags when building with clang-cl.
MozReview-Commit-ID: J3TfnvHUZaQ
--- 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']