Bug 1300835 - enable --disable-optimize --enable-debug to DTRT for Rust code; r=ted.mielczarek
authorNathan Froyd <froydnj@mozilla.com>
Mon, 21 Nov 2016 17:39:39 -0500
changeset 323701 dc554c8e9e6a4042bf99175b9b762c033ee8cd03
parent 323700 76e0b210a4fc83a1411dbedba91a27fd7e46143a
child 323702 c4749e8571cb10d6d3aef95f8a214118359ad2ba
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewersted.mielczarek
bugs1300835
milestone53.0a1
Bug 1300835 - enable --disable-optimize --enable-debug to DTRT for Rust code; r=ted.mielczarek
config/rules.mk
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -925,24 +925,36 @@ cargo_build_flags += --verbose
 # aren't already present. This essentially restores the default behavior
 # of cargo when running via `mach`.
 ifdef MACH_STDOUT_ISATTY
 ifeq (,$(findstring --color,$(cargo_build_flags)))
 cargo_build_flags += --color=always
 endif
 endif
 
+# Cargo currently supports only two interesting profiles for building:
+# development and release.  Those map (roughly) to --enable-debug and
+# --disable-debug in Gecko, respectively, but there's another axis that we'd
+# 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_override = RUSTFLAGS='-C opt-level=0'
+endif
+
 # Assume any system libraries rustc links against are already in the target's LIBS.
 #
 # We need to run cargo unconditionally, because cargo is the only thing that
 # has full visibility into how changes in Rust sources might affect the final
 # build.
 force-cargo-build:
 	$(REPORT_BUILD)
-	env CARGO_TARGET_DIR=. RUSTC=$(RUSTC) $(CARGO) build $(cargo_build_flags) --
+	env $(rustflags_override) CARGO_TARGET_DIR=. RUSTC=$(RUSTC) $(CARGO) build $(cargo_build_flags) --
 
 $(RUST_LIBRARY_FILE): force-cargo-build
 endif # CARGO_FILE
 endif # MOZ_RUST
 
 $(SOBJS):
 	$(REPORT_BUILD)
 	$(AS) -o $@ $(DEFINES) $(ASFLAGS) $($(notdir $<)_FLAGS) $(LOCAL_INCLUDES) -c $<