Skip to content

Commit

Permalink
Bug 1353810 - add a --enable-rust-debug option; r=chmanchester
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
froydnj committed Apr 13, 2017
1 parent 6f4c78c commit 2989feb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
6 changes: 3 additions & 3 deletions config/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ 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
Expand Down Expand Up @@ -936,8 +936,8 @@ endif
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)'
Expand Down
2 changes: 1 addition & 1 deletion layout/style/ServoBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Gecko_IsInDocument(RawGeckoNodeBorrowed aNode)
return aNode->IsInComposedDoc();
}

#ifdef DEBUG
#ifdef MOZ_DEBUG_RUST
bool
Gecko_FlattenedTreeParentIsParent(RawGeckoNodeBorrowed aNode)
{
Expand Down
14 changes: 14 additions & 0 deletions moz.configure
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ js_option('--enable-debug',
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.
Expand Down
2 changes: 1 addition & 1 deletion python/mozbuild/mozbuild/frontend/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def cargo_output_directory(context, target_var):
# 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)

Expand Down
4 changes: 4 additions & 0 deletions xpcom/string/nsSubstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ 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)
Expand Down

0 comments on commit 2989feb

Please sign in to comment.