summaryrefslogtreecommitdiffstats
path: root/www/firefox/files/patch-rust-option
blob: e60e11b111ee666b1bf19d3b03921da50ad535e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
Revert bug 1284816, bug 1341967, bug 1336153 to postpone bustage on non-x86 archs.

diff --git browser/confvars.sh browser/confvars.sh
index d8dcd99c2757..740d9d3e5fcf 100755
--- browser/confvars.sh
+++ browser/confvars.sh
@@ -30,6 +30,7 @@ if test "$OS_ARCH" = "WINNT"; then
   fi
 fi
 
+MOZ_RUST_MP4PARSE=1
 if test "$NIGHTLY_BUILD"; then
   MOZ_RUST_URLPARSE=1
 fi
diff --git build/moz.configure/rust.configure build/moz.configure/rust.configure
index 267d989f1597..f709820e60ae 100644
--- build/moz.configure/rust.configure
+++ build/moz.configure/rust.configure
@@ -4,10 +4,20 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-# Rust is required by `rust_compiler` below. We allow_missing here
-# to propagate failures to the better error message there.
-rustc = check_prog('RUSTC', ['rustc'], allow_missing=True)
-cargo = check_prog('CARGO', ['cargo'], allow_missing=True)
+option('--disable-rust', help='Don\'t include Rust language sources')
+
+@depends('--enable-rust')
+def rust_compiler_names(value):
+    if value:
+        return ['rustc']
+
+@depends('--enable-rust')
+def cargo_binary_names(value):
+    if value:
+        return ['cargo']
+
+rustc = check_prog('RUSTC', rust_compiler_names, allow_missing=True)
+cargo = check_prog('CARGO', cargo_binary_names, allow_missing=True)
 
 @depends_if(rustc)
 @checking('rustc version', lambda info: info.version)
@@ -43,9 +53,12 @@ def cargo_info(cargo):
         version=Version(version),
     )
 
-@depends(rustc_info, cargo_info)
+@depends('--enable-rust', rustc_info, cargo_info)
 @imports(_from='textwrap', _import='dedent')
-def rust_compiler(rustc_info, cargo_info):
+def rust_compiler(value, rustc_info, cargo_info):
+    if not value:
+        return None
+
     if not rustc_info:
         die(dedent('''\
         Rust compiler not found.
@@ -97,6 +110,9 @@ def rust_compiler(rustc_info, cargo_info):
 
     return True
 
+set_define('MOZ_RUST', rust_compiler)
+set_config('MOZ_RUST', rust_compiler)
+
 @template
 def rust_triple_alias(host_or_target):
     """Template defining the alias used for rustc's --target flag.
@@ -227,7 +243,8 @@ set_config('RUST_HOST_TARGET', rust_host_triple)
 
 @depends(rust_target_triple)
 def rust_target_env_name(triple):
-    return triple.upper().replace('-','_')
+    if triple:
+        return triple.upper().replace('-','_')
 
 # We need this to form various Cargo environment variables, as there is no
 # uppercase function in make, and we don't want to shell out just for
@@ -235,5 +252,6 @@ def rust_target_env_name(triple):
 set_config('RUST_TARGET_ENV_NAME', rust_target_env_name)
 
 # Until we remove all the other Rust checks in old-configure.
+add_old_configure_assignment('MOZ_RUST', rust_compiler)
 add_old_configure_assignment('RUSTC', rustc)
 add_old_configure_assignment('RUST_TARGET', rust_target_triple)
diff --git config/rules.mk config/rules.mk
index 94cc5556e3d0..7b143ebc5146 100644
--- config/rules.mk
+++ config/rules.mk
@@ -900,6 +900,7 @@ 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)
 
@@ -1055,6 +1056,7 @@ force-cargo-host-program-build:
 
 $(HOST_RUST_PROGRAMS): force-cargo-host-program-build
 endif # HOST_RUST_PROGRAMS
+endif # MOZ_RUST
 
 $(SOBJS):
 	$(REPORT_BUILD)
diff --git dom/media/MediaPrefs.h dom/media/MediaPrefs.h
index 4dcc659222a4..559334d89fd1 100644
--- dom/media/MediaPrefs.h
+++ dom/media/MediaPrefs.h
@@ -183,7 +183,7 @@ private:
   DECL_MEDIA_PREF("media.ogg.flac.enabled",                   FlacInOgg, bool, false);
   DECL_MEDIA_PREF("media.flac.enabled",                       FlacEnabled, bool, true);
 
-#if !defined(RELEASE_OR_BETA)
+#if defined(MOZ_RUST_MP4PARSE) && !defined(RELEASE_OR_BETA)
   DECL_MEDIA_PREF("media.rust.test_mode",                     RustTestMode, bool, false);
 #endif
 
diff --git dom/media/gtest/moz.build dom/media/gtest/moz.build
index c66ac4a9437f..e2203c0a4321 100644
--- dom/media/gtest/moz.build
+++ dom/media/gtest/moz.build
@@ -22,7 +22,6 @@ UNIFIED_SOURCES += [
     'TestMozPromise.cpp',
     'TestMP3Demuxer.cpp',
     'TestMP4Demuxer.cpp',
-    'TestRust.cpp',
     'TestTrackEncoder.cpp',
     'TestVideoSegment.cpp',
     'TestVideoUtils.cpp',
@@ -36,6 +35,9 @@ if CONFIG['MOZ_WEBM_ENCODER']:
         'TestWebMWriter.cpp',
     ]
 
+if CONFIG['MOZ_RUST']:
+    UNIFIED_SOURCES += ['TestRust.cpp',]
+
 TEST_HARNESS_FILES.gtest += [
     '../test/gizmo-frag.mp4',
     '../test/gizmo.mp4',
diff --git media/libcubeb/src/moz.build media/libcubeb/src/moz.build
index c65b53b80f63..8953f646e831 100644
--- media/libcubeb/src/moz.build
+++ media/libcubeb/src/moz.build
@@ -32,7 +32,8 @@ if CONFIG['MOZ_PULSEAUDIO']:
         'cubeb_pulse.c',
     ]
     DEFINES['USE_PULSE'] = True
-    DEFINES['USE_PULSE_RUST'] = True
+    if CONFIG['MOZ_RUST']:
+        DEFINES['USE_PULSE_RUST'] = True
 
 if CONFIG['MOZ_JACK']:
     SOURCES += [
diff --git media/libstagefright/binding/DecoderData.cpp media/libstagefright/binding/DecoderData.cpp
index 109ea329d154..a06e533b1e62 100644
--- media/libstagefright/binding/DecoderData.cpp
+++ media/libstagefright/binding/DecoderData.cpp
@@ -13,9 +13,11 @@
 #include "mozilla/ArrayUtils.h"
 #include "include/ESDS.h"
 
+#ifdef MOZ_RUST_MP4PARSE
 // OpusDecoder header is really needed only by MP4 in rust
 #include "OpusDecoder.h"
 #include "mp4parse.h"
+#endif // MOZ_RUST_MP4PARSE
 
 using namespace stagefright;
 using mozilla::media::TimeUnit;
@@ -177,6 +179,7 @@ MP4VideoInfo::Update(const MetaData* aMetaData, const char* aMimeType)
   FindData(aMetaData, kKeyAVCC, mExtraData);
 }
 
+#ifdef MOZ_RUST_MP4PARSE
 static void
 UpdateTrackProtectedInfo(mozilla::TrackInfo& aConfig,
                          const mp4parse_sinf_info& aSinf)
@@ -263,6 +266,7 @@ MP4VideoInfo::Update(const mp4parse_track_info* track,
     mExtraData->AppendElements(video->extra_data.data, video->extra_data.length);
   }
 }
+#endif // MOZ_RUST_MP4PARSE
 
 bool
 MP4VideoInfo::IsValid() const
diff --git media/libstagefright/binding/MP4Metadata.cpp media/libstagefright/binding/MP4Metadata.cpp
index 5c3810d99a38..5d14dfd8b8a9 100644
--- media/libstagefright/binding/MP4Metadata.cpp
+++ media/libstagefright/binding/MP4Metadata.cpp
@@ -20,14 +20,18 @@
 #include "mp4_demuxer/MP4Metadata.h"
 #include "mp4_demuxer/Stream.h"
 #include "MediaPrefs.h"
+#ifdef MOZ_RUST_MP4PARSE
 #include "mp4parse.h"
+#endif // MOZ_RUST_MP4PARSE
 
 #include <limits>
 #include <stdint.h>
 #include <vector>
 
 
+#ifdef MOZ_RUST_MP4PARSE
 struct FreeMP4Parser { void operator()(mp4parse_parser* aPtr) { mp4parse_free(aPtr); } };
+#endif // MOZ_RUST_MP4PARSE
 
 using namespace stagefright;
 using mozilla::media::TimeUnit;
@@ -105,6 +109,7 @@ private:
   bool mCanSeek;
 };
 
+#ifdef MOZ_RUST_MP4PARSE
 // Wrap an mp4_demuxer::Stream to remember the read offset.
 
 class RustStreamAdaptor {
@@ -151,6 +156,7 @@ private:
   RustStreamAdaptor mRustSource;
   mozilla::UniquePtr<mp4parse_parser, FreeMP4Parser> mRustParser;
 };
+#endif // MOZ_RUST_MP4PARSE
 
 class IndiceWrapperStagefright : public IndiceWrapper {
 public:
@@ -187,6 +193,7 @@ IndiceWrapperStagefright::GetIndice(size_t aIndex, Index::Indice& aIndice) const
   return true;
 }
 
+#ifdef MOZ_RUST_MP4PARSE
 // the owner of mIndice is rust mp4 paser, so lifetime of this class
 // SHOULD NOT longer than rust parser.
 class IndiceWrapperRust : public IndiceWrapper
@@ -232,9 +239,11 @@ IndiceWrapperRust::GetIndice(size_t aIndex, Index::Indice& aIndice) const
   aIndice.sync = indice->sync;
   return true;
 }
+#endif // MOZ_RUST_MP4PARSE
 
 MP4Metadata::MP4Metadata(Stream* aSource)
  : mStagefright(MakeUnique<MP4MetadataStagefright>(aSource))
+#ifdef MOZ_RUST_MP4PARSE
  , mRust(MakeUnique<MP4MetadataRust>(aSource))
  , mPreferRust(MediaPrefs::EnableRustMP4Parser())
  , mReportedAudioTrackTelemetry(false)
@@ -242,6 +251,7 @@ MP4Metadata::MP4Metadata(Stream* aSource)
 #ifndef RELEASE_OR_BETA
  , mRustTestMode(MediaPrefs::RustTestMode())
 #endif
+#endif // MOZ_RUST_MP4PARSE
 {
 }
 
@@ -274,8 +284,11 @@ MP4Metadata::GetNumberTracks(mozilla::TrackInfo::TrackType aType) const
   MP4Metadata::ResultAndTrackCount numTracks =
     mStagefright->GetNumberTracks(aType);
 
+#ifdef MOZ_RUST_MP4PARSE
   if (!mRust) {
+#endif // MOZ_RUST_MP4PARSE
     return numTracks;
+#ifdef MOZ_RUST_MP4PARSE
   }
 
   MP4Metadata::ResultAndTrackCount numTracksRust =
@@ -350,8 +363,10 @@ MP4Metadata::GetNumberTracks(mozilla::TrackInfo::TrackType aType) const
   // Same non-error numbers, just return any.
   // (Choosing Rust here, in case it carries a warning, we'd want to know that.)
   return numTracksRust;
+#endif // MOZ_RUST_MP4PARSE
 }
 
+#ifdef MOZ_RUST_MP4PARSE
 bool MP4Metadata::ShouldPreferRust() const {
   if (!mRust) {
     return false;
@@ -389,6 +404,7 @@ bool MP4Metadata::ShouldPreferRust() const {
   // Otherwise, fall back.
   return false;
 }
+#endif // MOZ_RUST_MP4PARSE
 
 static const char*
 GetDifferentField(const mozilla::TrackInfo& info,
@@ -443,6 +459,7 @@ MP4Metadata::GetTrackInfo(mozilla::TrackInfo::TrackType aType,
   MP4Metadata::ResultAndTrackInfo info =
     mStagefright->GetTrackInfo(aType, aTrackNumber);
 
+#ifdef MOZ_RUST_MP4PARSE
   if (!mRust) {
     return info;
   }
@@ -514,6 +531,7 @@ MP4Metadata::GetTrackInfo(mozilla::TrackInfo::TrackType aType,
   if (mPreferRust) {
     return infoRust;
   }
+#endif // MOZ_RUST_MP4PARSE
 
   return info;
 }
@@ -528,6 +546,7 @@ MP4Metadata::ResultAndCryptoFile
 MP4Metadata::Crypto() const
 {
   MP4Metadata::ResultAndCryptoFile crypto = mStagefright->Crypto();
+#ifdef MOZ_RUST_MP4PARSE
   MP4Metadata::ResultAndCryptoFile rustCrypto = mRust->Crypto();
 
 #ifndef RELEASE_OR_BETA
@@ -548,6 +567,7 @@ MP4Metadata::Crypto() const
   if (mPreferRust) {
     return rustCrypto;
   }
+#endif // MOZ_RUST_MP4PARSE
 
   return crypto;
 }
@@ -556,17 +576,22 @@ MP4Metadata::ResultAndIndice
 MP4Metadata::GetTrackIndice(mozilla::TrackID aTrackID)
 {
   FallibleTArray<Index::Indice> indiceSF;
+#ifdef MOZ_RUST_MP4PARSE
   if (!mPreferRust
 #ifndef RELEASE_OR_BETA
       || mRustTestMode
 #endif
      ) {
+#endif // MOZ_RUST_MP4PARSE
     MediaResult rv = mStagefright->ReadTrackIndex(indiceSF, aTrackID);
     if (NS_FAILED(rv)) {
       return {Move(rv), nullptr};
     }
+#ifdef MOZ_RUST_MP4PARSE
   }
+#endif // MOZ_RUST_MP4PARSE
 
+#ifdef MOZ_RUST_MP4PARSE
   mp4parse_byte_data indiceRust = {};
   if (mPreferRust
 #ifndef RELEASE_OR_BETA
@@ -592,13 +617,18 @@ MP4Metadata::GetTrackIndice(mozilla::TrackID aTrackID)
     }
   }
 #endif
+#endif // MOZ_RUST_MP4PARSE
 
   UniquePtr<IndiceWrapper> indice;
+#ifdef MOZ_RUST_MP4PARSE
   if (mPreferRust) {
     indice = mozilla::MakeUnique<IndiceWrapperRust>(indiceRust);
   } else {
+#endif // MOZ_RUST_MP4PARSE
     indice = mozilla::MakeUnique<IndiceWrapperStagefright>(indiceSF);
+#ifdef MOZ_RUST_MP4PARSE
   }
+#endif // MOZ_RUST_MP4PARSE
 
   return {NS_OK, Move(indice)};
 }
@@ -856,6 +886,7 @@ MP4MetadataStagefright::Metadata(Stream* aSource)
   return {NS_OK, Move(buffer)};
 }
 
+#ifdef MOZ_RUST_MP4PARSE
 bool
 RustStreamAdaptor::Read(uint8_t* buffer, uintptr_t size, size_t* bytes_read)
 {
@@ -1152,5 +1183,6 @@ MP4MetadataRust::Metadata(Stream* aSource)
   MOZ_ASSERT(false, "Not yet implemented");
   return {NS_ERROR_NOT_IMPLEMENTED, nullptr};
 }
+#endif // MOZ_RUST_MP4PARSE
 
 } // namespace mp4_demuxer
diff --git media/libstagefright/binding/include/mp4_demuxer/DecoderData.h media/libstagefright/binding/include/mp4_demuxer/DecoderData.h
index 3cd4b7c142f4..dc25ddf03b10 100644
--- media/libstagefright/binding/include/mp4_demuxer/DecoderData.h
+++ media/libstagefright/binding/include/mp4_demuxer/DecoderData.h
@@ -19,11 +19,13 @@ namespace stagefright
 class MetaData;
 }
 
+#ifdef MOZ_RUST_MP4PARSE
 extern "C" {
 typedef struct mp4parse_track_info mp4parse_track_info;
 typedef struct mp4parse_track_audio_info mp4parse_track_audio_info;
 typedef struct mp4parse_track_video_info mp4parse_track_video_info;
 }
+#endif // MOZ_RUST_MP4PARSE
 
 namespace mp4_demuxer
 {
@@ -71,8 +73,10 @@ public:
   void Update(const stagefright::MetaData* aMetaData,
               const char* aMimeType);
 
+#ifdef MOZ_RUST_MP4PARSE
   void Update(const mp4parse_track_info* track,
               const mp4parse_track_audio_info* audio);
+#endif // MOZ_RUST_MP4PARSE
 
   virtual bool IsValid() const override;
 };
@@ -85,8 +89,10 @@ public:
   void Update(const stagefright::MetaData* aMetaData,
               const char* aMimeType);
 
+#ifdef MOZ_RUST_MP4PARSE
   void Update(const mp4parse_track_info* track,
               const mp4parse_track_video_info* video);
+#endif // MOZ_RUST_MP4PARSE
 
   virtual bool IsValid() const override;
 };
diff --git media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h
index 492c9c1c1bc3..e16dbbd1155e 100644
--- media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h
+++ media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h
@@ -13,7 +13,9 @@
 #include "MediaInfo.h"
 #include "MediaResult.h"
 #include "Stream.h"
+#ifdef MOZ_RUST_MP4PARSE
 #include "mp4parse.h"
+#endif // MOZ_RUST_MP4PARSE
 
 namespace mp4_demuxer {
 
@@ -82,6 +84,7 @@ public:
 
 private:
   UniquePtr<MP4MetadataStagefright> mStagefright;
+#ifdef MOZ_RUST_MP4PARSE
   UniquePtr<MP4MetadataRust> mRust;
   mutable bool mPreferRust;
   mutable bool mReportedAudioTrackTelemetry;
@@ -90,6 +93,7 @@ private:
   mutable bool mRustTestMode;
 #endif
   bool ShouldPreferRust() const;
+#endif // MOZ_RUST_MP4PARSE
 };
 
 } // namespace mp4_demuxer
diff --git media/libstagefright/gtest/moz.build media/libstagefright/gtest/moz.build
index be4d56fc93f7..66fdd365f8f3 100644
--- media/libstagefright/gtest/moz.build
+++ media/libstagefright/gtest/moz.build
@@ -38,12 +38,13 @@ TEST_HARNESS_FILES.gtest += [
     'test_case_1351094.mp4',
 ]
 
-UNIFIED_SOURCES += ['TestMP4Rust.cpp',]
-TEST_HARNESS_FILES.gtest += [
-    '../../../dom/media/test/street.mp4',
-]
-LOCAL_INCLUDES += [
-    '../binding/include',
-]
+if CONFIG['MOZ_RUST']:
+    UNIFIED_SOURCES += ['TestMP4Rust.cpp',]
+    TEST_HARNESS_FILES.gtest += [
+        '../../../dom/media/test/street.mp4',
+    ]
+    LOCAL_INCLUDES += [
+        '../binding/include',
+    ]
 
 FINAL_LIBRARY = 'xul-gtest'
diff --git media/libstagefright/moz.build media/libstagefright/moz.build
index af5d1194d621..6725a0179989 100644
--- media/libstagefright/moz.build
+++ media/libstagefright/moz.build
@@ -83,9 +83,10 @@ SOURCES += [
     'system/core/libutils/VectorImpl.cpp',
 ]
 
-EXPORTS += [
-    'binding/include/mp4parse.h',
-]
+if CONFIG['MOZ_RUST']:
+    EXPORTS += [
+        'binding/include/mp4parse.h',
+    ]
 
 UNIFIED_SOURCES += [
     'binding/Adts.cpp',
diff --git mobile/android/confvars.sh mobile/android/confvars.sh
index e79b6f5c0707..eb62763acaf7 100644
--- mobile/android/confvars.sh
+++ mobile/android/confvars.sh
@@ -30,6 +30,8 @@ MOZ_XULRUNNER=
 MOZ_CAPTURE=1
 MOZ_RAW=1
 
+MOZ_RUST_MP4PARSE=1
+
 # use custom widget for html:select
 MOZ_USE_NATIVE_POPUP_WINDOWS=1
 
diff --git netwerk/base/moz.build netwerk/base/moz.build
index 61d022a9660e..e5ca1d77d859 100644
--- netwerk/base/moz.build
+++ netwerk/base/moz.build
@@ -256,7 +256,7 @@ UNIFIED_SOURCES += [
     'TLSServerSocket.cpp',
 ]
 
-if CONFIG['MOZ_RUST_URLPARSE']:
+if CONFIG['MOZ_RUST'] and CONFIG['MOZ_RUST_URLPARSE']:
     EXPORTS.mozilla.net += [ 'RustURL.h' ]
     UNIFIED_SOURCES += [ 'RustURL.cpp' ]
 
diff --git netwerk/base/nsStandardURL.cpp netwerk/base/nsStandardURL.cpp
index 608b918a4ecf..20bcdeb34ab8 100644
--- netwerk/base/nsStandardURL.cpp
+++ netwerk/base/nsStandardURL.cpp
@@ -858,6 +858,7 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
         if (!SegmentIs(spec, mScheme, "resource") &&
             !SegmentIs(spec, mScheme, "chrome")) {
             nsAutoCString ipString;
+#ifdef MOZ_RUST
             if (encHost.Length() > 0 &&
                 encHost.First() == '[' && encHost.Last() == ']' &&
                 ValidIPv6orHostname(encHost.get(), encHost.Length())) {
@@ -866,7 +867,9 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
                     return rv;
                 }
                 encHost = ipString;
-            } else if (NS_SUCCEEDED(NormalizeIPv4(encHost, ipString))) {
+            } else
+#endif
+            if (NS_SUCCEEDED(NormalizeIPv4(encHost, ipString))) {
                 encHost = ipString;
             }
         }
@@ -2112,6 +2115,7 @@ nsStandardURL::SetHost(const nsACString &input)
 
     if (!SegmentIs(mScheme, "resource") && !SegmentIs(mScheme, "chrome")) {
         nsAutoCString ipString;
+#ifdef MOZ_RUST
         if (hostBuf.Length() > 0 &&
             hostBuf.First() == '[' && hostBuf.Last() == ']' &&
             ValidIPv6orHostname(hostBuf.get(), hostBuf.Length())) {
@@ -2120,7 +2124,9 @@ nsStandardURL::SetHost(const nsACString &input)
                 return rv;
             }
             hostBuf = ipString;
-        } else if (NS_SUCCEEDED(NormalizeIPv4(hostBuf, ipString))) {
+        } else
+#endif
+        if (NS_SUCCEEDED(NormalizeIPv4(hostBuf, ipString))) {
           hostBuf = ipString;
         }
     }
diff --git old-configure.in old-configure.in
index 717a94fcc692..54b29d737cc1 100644
--- old-configure.in
+++ old-configure.in
@@ -2330,9 +2330,14 @@ if test -n "$MOZ_MULET"; then
 fi
 
 # Propagate feature switches for code written in rust from confvars.sh
-if test -n "$MOZ_RUST_URLPARSE"; then
-    AC_DEFINE(MOZ_RUST_URLPARSE)
-    AC_SUBST(MOZ_RUST_URLPARSE)
+if test -n "$MOZ_RUST"; then
+    if test -n "$MOZ_RUST_MP4PARSE"; then
+        AC_DEFINE(MOZ_RUST_MP4PARSE)
+    fi
+    if test -n "$MOZ_RUST_URLPARSE"; then
+        AC_DEFINE(MOZ_RUST_URLPARSE)
+        AC_SUBST(MOZ_RUST_URLPARSE)
+    fi
 fi
 
 AC_SUBST(MOZ_PHOENIX)
diff --git toolkit/components/telemetry/Histograms.json toolkit/components/telemetry/Histograms.json
index 061c55f6a5b6..e49dfd176952 100644
--- toolkit/components/telemetry/Histograms.json
+++ toolkit/components/telemetry/Histograms.json
@@ -8320,7 +8320,8 @@
     "expires_in_version": "60",
     "kind": "boolean",
     "bug_numbers": [1220885],
-    "description": "Whether the rust mp4 demuxer successfully parsed a stream segment."
+    "description": "Whether the rust mp4 demuxer successfully parsed a stream segment.",
+    "cpp_guard": "MOZ_RUST_MP4PARSE"
   },
   "MEDIA_RUST_MP4PARSE_ERROR_CODE": {
     "record_in_processes": ["main", "content"],
@@ -8329,7 +8330,8 @@
     "kind": "enumerated",
     "n_values": 32,
     "bug_numbers": [1238420],
-    "description": "The error code reported when an MP4 parse attempt has failed.0 = OK, 1 = bad argument, 2 = invalid data, 3 = unsupported, 4 = unexpected end of file, 5 = read error."
+    "description": "The error code reported when an MP4 parse attempt has failed.0 = OK, 1 = bad argument, 2 = invalid data, 3 = unsupported, 4 = unexpected end of file, 5 = read error.",
+    "cpp_guard": "MOZ_RUST_MP4PARSE"
   },
   "MEDIA_RUST_MP4PARSE_TRACK_MATCH_AUDIO": {
     "record_in_processes": ["main", "content"],
@@ -8337,7 +8339,8 @@
     "expires_in_version": "60",
     "kind": "boolean",
     "bug_numbers": [1231169],
-    "description": "Whether rust and stagefight mp4 parser audio track results match."
+    "description": "Whether rust and stagefight mp4 parser audio track results match.",
+    "cpp_guard": "MOZ_RUST_MP4PARSE"
   },
   "MEDIA_RUST_MP4PARSE_TRACK_MATCH_VIDEO": {
     "record_in_processes": ["main", "content"],
@@ -8345,7 +8348,8 @@
     "expires_in_version": "60",
     "kind": "boolean",
     "bug_numbers": [1231169],
-    "description": "Whether rust and stagefight mp4 parser video track results match."
+    "description": "Whether rust and stagefight mp4 parser video track results match.",
+    "cpp_guard": "MOZ_RUST_MP4PARSE"
   },
   "MEDIA_WMF_DECODE_ERROR": {
     "record_in_processes": ["main", "content", "gpu"],
diff --git toolkit/library/gtest/moz.build toolkit/library/gtest/moz.build
index 69a8fb1f4893..c684f48e456e 100644
--- toolkit/library/gtest/moz.build
+++ toolkit/library/gtest/moz.build
@@ -7,7 +7,6 @@
 FINAL_TARGET = 'dist/bin/gtest'
 
 USE_LIBS += [
-    'gkrust-gtest',
     'static:xul',
     # xul-gtest is an intermediate static library. It is used as FINAL_TARGET
     # for gtest code.
@@ -21,6 +20,11 @@ USE_LIBS += [
 # before StaticXULComponentStart.
 Libxul('xul-gtest-real')
 
+if CONFIG['MOZ_RUST']:
+    USE_LIBS += [
+        'gkrust-gtest',
+    ]
+
 DIRS += [
     'static',
 ]
diff --git toolkit/library/moz.build toolkit/library/moz.build
index 650f6eaba980..191e90ceb09a 100644
--- toolkit/library/moz.build
+++ toolkit/library/moz.build
@@ -63,7 +63,7 @@ def Libxul(name):
 
     # This option should go away in bug 1290972, but we need to wait until
     # Rust 1.12 has been released.
-    if CONFIG['OS_ARCH'] == 'Darwin':
+    if CONFIG['MOZ_RUST'] and CONFIG['OS_ARCH'] == 'Darwin':
         LDFLAGS += ['-Wl,-no_compact_unwind']
 
 Libxul('xul')
@@ -343,4 +343,5 @@ USE_LIBS += ['StaticXULComponentsEnd']
 # The above library needs to be last for C++ purposes.  This library,
 # however, is entirely composed of Rust code, and needs to come after
 # all the C++ code so any possible C++ -> Rust calls can be resolved.
-USE_LIBS += ['gkrust']
+if CONFIG['MOZ_RUST']:
+    USE_LIBS += ['gkrust']
diff --git toolkit/moz.configure toolkit/moz.configure
index ac9d123224ce..e90da70f0fa5 100644
--- toolkit/moz.configure
+++ toolkit/moz.configure
@@ -88,8 +88,7 @@ include('../js/moz.configure')
 
 # Rust
 # ==============================================================
-include('../build/moz.configure/rust.configure',
-        when='--enable-compile-environment')
+include('../build/moz.configure/rust.configure')
 
 
 # L10N
@@ -623,13 +622,13 @@ id_and_secret_keyfile('Leanplum SDK')
 option('--enable-stylo', nargs='?', choices=('build',),
        help='Include Stylo in the build and/or enable it at runtime')
 
-@depends('--enable-stylo')
-def stylo_config(value):
+@depends('--enable-stylo', '--enable-rust')
+def stylo_config(value, rust_enabled):
     build_stylo = None
     enable_stylo = None
 
     # The default is to not build Stylo at all.
-    if value.origin == 'default':
+    if not rust_enabled or value.origin == 'default':
         pass
     elif value == 'build':
         build_stylo = True
@@ -769,12 +768,14 @@ set_config('SERVO_TARGET_DIR', servo_target_dir)
 option('--enable-webrender', nargs='?', choices=('build',),
        help='Include WebRender in the build and/or enable it at runtime')
 
-@depends('--enable-webrender', milestone)
-def webrender(value, milestone):
+@depends('--enable-webrender', '--enable-rust', milestone)
+def webrender(value, rust_enabled, milestone):
     build_webrender = None
     enable_webrender = None
 
-    if value.origin == 'default':
+    if not rust_enabled:
+        pass
+    elif value.origin == 'default':
         # if nothing is specified, default to just building on Nightly
         build_webrender = milestone.is_nightly
     elif value == 'build':
diff --git toolkit/toolkit.mozbuild toolkit/toolkit.mozbuild
index b845aab48023..9215afc6dd2d 100644
--- toolkit/toolkit.mozbuild
+++ toolkit/toolkit.mozbuild
@@ -133,16 +133,23 @@ if CONFIG['MOZ_PREF_EXTENSIONS']:
 
 DIRS += [
     '/devtools',
-    '/toolkit/library',
-    '/toolkit/library/gtest/rust',
-    '/toolkit/library/rust',
-    '/toolkit/library/StaticXULComponentsEnd',
     '/services',
     '/startupcache',
     '/js/ductwork/debugger',
     '/other-licenses/snappy',
 ]
 
+if CONFIG['MOZ_RUST']:
+    DIRS += [
+        '/toolkit/library/gtest/rust',
+        '/toolkit/library/rust',
+    ]
+
+DIRS += [
+    '/toolkit/library/StaticXULComponentsEnd',
+    '/toolkit/library',
+]
+
 if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
     DIRS += ['/toolkit/system/gnome']
 
diff --git toolkit/xre/nsAppRunner.cpp toolkit/xre/nsAppRunner.cpp
index 667c2eb1b365..6fb6cf102baa 100644
--- toolkit/xre/nsAppRunner.cpp
+++ toolkit/xre/nsAppRunner.cpp
@@ -227,11 +227,13 @@
 extern uint32_t gRestartMode;
 extern void InstallSignalHandlers(const char *ProgramName);
 
+#ifdef MOZ_RUST
 // This workaround is fixed in Rust 1.19. For details, see bug 1358151.
 // Implementation in toolkit/library/rust/shared/lib.rs
 extern "C" {
   void rust_init_please_remove_this_after_updating_rust_1_19();
 }
+#endif
 
 #define FILE_COMPATIBILITY_INFO NS_LITERAL_CSTRING("compatibility.ini")
 #define FILE_INVALIDATE_CACHES NS_LITERAL_CSTRING(".purgecaches")
@@ -3122,8 +3124,10 @@ XREMain::XRE_mainInit(bool* aExitFlag)
     return 1;
   *aExitFlag = false;
 
+#ifdef MOZ_RUST
   // This workaround is fixed in Rust 1.19. For details, see bug 1358151.
   rust_init_please_remove_this_after_updating_rust_1_19();
+#endif
 
   atexit(UnexpectedExit);
   auto expectedShutdown = mozilla::MakeScopeExit([&] {
diff --git xpcom/base/nsDebugImpl.cpp xpcom/base/nsDebugImpl.cpp
index e6bb623c258b..c49d61dce605 100644
--- xpcom/base/nsDebugImpl.cpp
+++ xpcom/base/nsDebugImpl.cpp
@@ -148,14 +148,20 @@ nsDebugImpl::Abort(const char* aFile, int32_t aLine)
   return NS_OK;
 }
 
+#ifdef MOZ_RUST
 // From toolkit/library/rust/lib.rs
 extern "C" void intentional_panic(const char* message);
+#endif
 
 NS_IMETHODIMP
 nsDebugImpl::RustPanic(const char* aMessage)
 {
+#ifdef MOZ_RUST
   intentional_panic(aMessage);
   return NS_OK;
+#else
+  return NS_ERROR_NOT_IMPLEMENTED;
+#endif
 }
 
 NS_IMETHODIMP
diff --git xpcom/rust/nsstring/gtest/moz.build xpcom/rust/nsstring/gtest/moz.build
index 197411678815..5bed9e57e57d 100644
--- xpcom/rust/nsstring/gtest/moz.build
+++ xpcom/rust/nsstring/gtest/moz.build
@@ -4,8 +4,9 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-UNIFIED_SOURCES += [
-    'Test.cpp'
-]
+if CONFIG['MOZ_RUST']:
+    UNIFIED_SOURCES += [
+        'Test.cpp'
+    ]
 
 FINAL_LIBRARY = 'xul-gtest'
OpenPOWER on IntegriCloud