Bug 1353810 - add a --enable-rust-debug option; r=chmanchester
authorNathan Froyd <froydnj@mozilla.com>
Wed, 12 Apr 2017 21:49:25 -0400
changeset 352757 5d8f0f741be4d603cc67c2ea3c0ddcb2d16e4216
parent 352756 e37c70b7fd23f4c5f6f41fb6b13feb39de3048c1
child 352758 00cd9d69ecde30cdc6510d81816d12c6256ad926
push id89124
push usernfroyd@mozilla.com
push dateThu, 13 Apr 2017 01:49:40 +0000
treeherdermozilla-inbound@5d8f0f741be4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1353810
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1353810 - add a --enable-rust-debug option; r=chmanchester For people working on Rust code, compiling in debug mode (Cargo's "dev" profile) is convenient: debug assertions are turned on, optimization is turned off, and parallel compilation inside of rustc itself can be used. These things make the build faster and the debugging experience more pleasant. To obtain that currently, one needs to --enable-debug at the Gecko toplevel, which turns on debug assertions for the entire browser, which makes things run unreasonably slowly. So it would be desirable to be able to turn *off* debug mode for the entirety of the browser, but turn on debug mode for the Rust code only. Hence this added switch, --enable-rust-debug, which does what it suggests and defaults to the value of --enable-debug. For our own sanity and because we judge it a non-existent use case, we do not support --enable-debug --disable-rust-debug.
config/rules.mk
layout/style/ServoBindings.cpp
moz.configure
python/mozbuild/mozbuild/frontend/data.py
xpcom/string/nsSubstring.cpp
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -901,17 +901,17 @@ endif
 $(foreach file,$(DUMP_SYMS_TARGETS),$(eval $(call syms_template,$(file),$(file)_syms.track)))
 
 ifdef MOZ_RUST
 cargo_host_flag := --target=$(RUST_HOST_TARGET)
 cargo_target_flag := --target=$(RUST_TARGET)
 
 # Permit users to pass flags to cargo from their mozconfigs (e.g. --color=always).
 cargo_build_flags = $(CARGOFLAGS)
-ifndef MOZ_DEBUG
+ifndef MOZ_DEBUG_RUST
 cargo_build_flags += --release
 endif
 cargo_build_flags += --frozen
 
 cargo_build_flags += --manifest-path $(CARGO_FILE)
 ifdef BUILD_VERBOSE_LOG
 cargo_build_flags += --verbose
 endif
@@ -931,18 +931,18 @@ endif
 # like to support: --{disable,enable}-optimize.  Since that would be four
 # choices, and Cargo only supports two, we choose to enable various
 # optimization levels in our Cargo.toml files all the time, and override the
 # optimization level here, if necessary.  (The Cargo.toml files already
 # specify debug-assertions appropriately for --{disable,enable}-debug.)
 ifndef MOZ_OPTIMIZE
 rustflags = -C opt-level=0
 # Unfortunately, -C opt-level=0 implies -C debug-assertions, so we need
-# to explicitly disable them when MOZ_DEBUG is not set.
-ifndef MOZ_DEBUG
+# to explicitly disable them when MOZ_DEBUG_RUST is not set.
+ifndef MOZ_DEBUG_RUST
 rustflags += -C debug-assertions=no
 endif
 rustflags_override = RUSTFLAGS='$(rustflags)'
 endif
 
 ifdef MOZ_MSVCBITS
 # If we are building a MozillaBuild shell, we want to clear out the
 # vcvars.bat environment variables for cargo builds. This is because
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -83,17 +83,17 @@ Gecko_NodeIsElement(RawGeckoNodeBorrowed
 }
 
 bool
 Gecko_IsInDocument(RawGeckoNodeBorrowed aNode)
 {
   return aNode->IsInComposedDoc();
 }
 
-#ifdef DEBUG
+#ifdef MOZ_DEBUG_RUST
 bool
 Gecko_FlattenedTreeParentIsParent(RawGeckoNodeBorrowed aNode)
 {
   // Servo calls this in debug builds to verify the result of its own
   // flattened_tree_parent_is_parent() function.
   return FlattenedTreeParentIsParent<nsIContent::eForStyle>(aNode);
 }
 #endif
--- a/moz.configure
+++ b/moz.configure
@@ -98,16 +98,30 @@ set_define('GTEST_HAS_CLONE',
 js_option('--enable-debug',
           nargs='?',
           help='Enable building with developer debug info '
                '(using the given compiler flags).')
 
 add_old_configure_assignment('MOZ_DEBUG',
                              depends('--enable-debug')(lambda v: bool(v)))
 
+imply_option('--enable-rust-debug',
+             depends('--enable-debug')(lambda v: bool(v) or None))
+
+js_option('--enable-rust-debug',
+          help='Build Rust code with debug assertions turned on.')
+
+@depends('--enable-rust-debug')
+def debug_rust(debug):
+    if debug:
+        return True
+
+set_config('MOZ_DEBUG_RUST', debug_rust)
+set_define('MOZ_DEBUG_RUST', debug_rust)
+
 include('build/moz.configure/pkg.configure')
 # Make this assignment here rather than in pkg.configure to avoid
 # requiring this file in unit tests.
 add_old_configure_assignment('PKG_CONFIG', pkg_config)
 
 include('build/moz.configure/toolchain.configure',
         when='--enable-compile-environment')
 include('build/moz.configure/memory.configure',
--- a/python/mozbuild/mozbuild/frontend/data.py
+++ b/python/mozbuild/mozbuild/frontend/data.py
@@ -420,17 +420,17 @@ class HostSimpleProgram(HostMixin, BaseP
     KIND = 'host'
 
 
 def cargo_output_directory(context, target_var):
     # 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'):
+    if context.config.substs.get('MOZ_DEBUG_RUST'):
         rust_build_kind = 'debug'
     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__ = (
--- a/xpcom/string/nsSubstring.cpp
+++ b/xpcom/string/nsSubstring.cpp
@@ -373,16 +373,20 @@ extern "C" {
 
 // This is a no-op on release, so we ifdef it out such that using it in release
 // results in a linker error.
 #ifdef DEBUG
 void Gecko_IncrementStringAdoptCount(void* aData)
 {
   MOZ_LOG_CTOR(aData, "StringAdopt", 1);
 }
+#elif defined(MOZ_DEBUG_RUST)
+void Gecko_IncrementStringAdoptCount(void *aData)
+{
+}
 #endif
 
 void Gecko_FinalizeCString(nsACString* aThis)
 {
   aThis->~nsACString();
 }
 
 void Gecko_AssignCString(nsACString* aThis, const nsACString* aOther)