From d6c6d3840630f7fe3a99060e250509004a85870b Mon Sep 17 00:00:00 2001 From: Csoregi Natalia Date: Wed, 21 Mar 2018 19:01:07 +0200 Subject: [PATCH] Backed out 4 changesets (bug 1447611) for mass failures due to --enable-stylo removal. CLOSED TREE Backed out changeset c6193142bbcf (bug 1447611) Backed out changeset 01ada1c5a95f (bug 1447611) Backed out changeset 86c9fed44da2 (bug 1447611) Backed out changeset bb84ac6e1468 (bug 1447611) --- dom/base/nsDocument.cpp | 23 +- dom/base/nsIDocument.h | 25 +- dom/xul/nsXULElement.cpp | 16 +- layout/base/nsLayoutUtils.cpp | 17 + layout/base/nsLayoutUtils.h | 36 +++ layout/base/nsStyleSheetService.cpp | 30 +- layout/style/PreloadedStyleSheet.cpp | 18 +- layout/style/ServoBindings.toml | 2 +- layout/tools/reftest/manifest.jsm | 17 +- layout/xul/crashtests/crashtests.list | 10 +- modules/libpref/init/all.js | 15 + python/mozbuild/mozbuild/mozinfo.py | 3 +- testing/awsy/mach_commands.py | 6 + .../mozharness/scripts/desktop_unittest.py | 6 + .../mozharness/scripts/web_platform_tests.py | 21 ++ .../telemetry/TelemetryEnvironment.jsm | 1 + toolkit/library/rust/gkrust-features.mozbuild | 11 +- toolkit/modules/AppConstants.jsm | 8 + toolkit/modules/Troubleshoot.jsm | 31 ++ .../tests/browser/browser_Troubleshoot.js | 15 + toolkit/moz.configure | 297 ++++++++++-------- toolkit/mozapps/installer/packager.mk | 2 + toolkit/mozapps/installer/upload-files.mk | 4 +- 23 files changed, 458 insertions(+), 156 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 5eedf9c5b157..de4f05f64450 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -1500,6 +1500,7 @@ nsIDocument::nsIDocument() mAsyncOnloadBlockCount(0), mCompatMode(eCompatibility_FullStandards), mReadyState(ReadyState::READYSTATE_UNINITIALIZED), + mStyleBackendType(StyleBackendType::None), #ifdef MOZILLA_INTERNAL_API mVisibilityState(dom::VisibilityState::Hidden), #else @@ -2155,9 +2156,13 @@ nsDocument::Init() NS_ASSERTION(OwnerDoc() == this, "Our nodeinfo is busted!"); + UpdateStyleBackendType(); + // Set this when document is initialized and value stays the same for the // lifetime of the document. - mIsShadowDOMEnabled = nsContentUtils::IsShadowDOMEnabled(); + mIsShadowDOMEnabled = + mStyleBackendType == StyleBackendType::Servo && + nsContentUtils::IsShadowDOMEnabled(); // If after creation the owner js global is not set for a document // we use the default compartment for this document, instead of creating @@ -8899,6 +8904,7 @@ nsDocument::CloneDocHelper(nsDocument* clone, bool aPreallocateChildren) const clone->mContentLanguage = mContentLanguage; clone->SetContentTypeInternal(GetContentTypeInternal()); clone->mSecurityInfo = mSecurityInfo; + clone->mStyleBackendType = mStyleBackendType; // State from nsDocument clone->mType = mType; @@ -12602,6 +12608,21 @@ nsIDocument::ReportHasScrollLinkedEffect() "ScrollLinkedEffectFound2"); } +void +nsIDocument::UpdateStyleBackendType() +{ + MOZ_ASSERT(mStyleBackendType == StyleBackendType::None, + "no need to call UpdateStyleBackendType now"); + + // Assume Gecko by default. + mStyleBackendType = StyleBackendType::Gecko; + + if (nsLayoutUtils::StyloEnabled() && + nsLayoutUtils::ShouldUseStylo(NodePrincipal())) { + mStyleBackendType = StyleBackendType::Servo; + } +} + void nsIDocument::SetUserHasInteracted(bool aUserHasInteracted) { diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 972c18beedc2..de44542598a2 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -1737,13 +1737,24 @@ public: return mCSSLoader; } - mozilla::StyleBackendType GetStyleBackendType() const - { - return mozilla::StyleBackendType::Servo; + mozilla::StyleBackendType GetStyleBackendType() const { + MOZ_ASSERT(mStyleBackendType != mozilla::StyleBackendType::None, + "Not initialized yet"); + return mStyleBackendType; } - bool IsStyledByServo() const - { + /** + * Documents generally decide their style backend type themselves, and + * this is only used for XBL documents to set their style backend type to + * their bounding document's. + */ + + /** + * Decide this document's own style backend type. + */ + void UpdateStyleBackendType(); + + bool IsStyledByServo() const { return GetStyleBackendType() == mozilla::StyleBackendType::Servo; } @@ -4214,6 +4225,10 @@ protected: // Our readyState ReadyState mReadyState; + // Whether this document has (or will have, once we have a pres shell) a + // Gecko- or Servo-backed style system. + mozilla::StyleBackendType mStyleBackendType; + #ifdef MOZILLA_INTERNAL_API // Our visibility state mozilla::dom::VisibilityState mVisibilityState; diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp index b4e4ac1dcb7b..2aac8f326673 100644 --- a/dom/xul/nsXULElement.cpp +++ b/dom/xul/nsXULElement.cpp @@ -2368,11 +2368,17 @@ nsXULPrototypeElement::SetAttrAt(uint32_t aPos, const nsAString& aValue, // TODO: If we implement Content Security Policy for chrome documents // as has been discussed, the CSP should be checked here to see if // inline styles are allowed to be applied. - RefPtr data = - new URLExtraData(aDocumentURI, aDocumentURI, principal); - RefPtr declaration = - ServoDeclarationBlock::FromCssText( - aValue, data, eCompatibility_FullStandards, nullptr); + + RefPtr declaration; + if (nsLayoutUtils::StyloEnabled() && + nsLayoutUtils::ShouldUseStylo(principal)) { + RefPtr data = + new URLExtraData(aDocumentURI, aDocumentURI, principal); + declaration = ServoDeclarationBlock::FromCssText( + aValue, data, eCompatibility_FullStandards, nullptr); + } else { + MOZ_CRASH("old style system disabled"); + } if (declaration) { mAttributes[aPos].mValue.SetTo(declaration.forget(), &aValue); diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 9f449a283d37..c6c7afde2bcc 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -196,6 +196,7 @@ typedef nsStyleTransformMatrix::TransformReferenceBox TransformReferenceBox; /* static */ bool nsLayoutUtils::sInterruptibleReflowEnabled; /* static */ bool nsLayoutUtils::sSVGTransformBoxEnabled; /* static */ bool nsLayoutUtils::sTextCombineUprightDigitsEnabled; +/* static */ bool nsLayoutUtils::sStyloEnabled; /* static */ uint32_t nsLayoutUtils::sIdlePeriodDeadlineLimit; /* static */ uint32_t nsLayoutUtils::sQuiescentFramesBeforeIdlePeriod; @@ -8279,6 +8280,8 @@ nsLayoutUtils::Initialize() "svg.transform-box.enabled"); Preferences::AddBoolVarCache(&sTextCombineUprightDigitsEnabled, "layout.css.text-combine-upright-digits.enabled"); + sStyloEnabled = true; + Preferences::AddUintVarCache(&sIdlePeriodDeadlineLimit, "layout.idle_period.time_limit", DEFAULT_IDLE_PERIOD_TIME_LIMIT); @@ -8310,6 +8313,20 @@ nsLayoutUtils::Shutdown() nsStyleList::Shutdown(); } +/* static */ +bool +nsLayoutUtils::ShouldUseStylo(nsIPrincipal* aPrincipal) +{ + return true; +} + +/* static */ +bool +nsLayoutUtils::StyloChromeEnabled() +{ + return true; +} + /* static */ void nsLayoutUtils::RegisterImageRequest(nsPresContext* aPresContext, diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index 83c4b9328dc8..56cf1ff329e2 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -2521,6 +2521,36 @@ public: return sTextCombineUprightDigitsEnabled; } + // Stylo (the Servo backend for Gecko's style system) is generally enabled + // or disabled at compile-time. However, we provide the additional capability + // to disable it dynamically in stylo-enabled builds via a pref. + static bool StyloEnabled() { + return true; + } + + // Whether Stylo should be allowed to be enabled in this process. + static bool StyloSupportedInCurrentProcess() { + if (XRE_IsContentProcess()) { + return true; + } + if (XRE_IsParentProcess()) { + // If Stylo is enabled for chrome document, we use it in all + // parent processes, regardless of whether it's e10s parent. + if (StyloChromeEnabled()) { + return true; + } + // Otherwise we only use stylo on non-e10s parent. + return !XRE_IsE10sParentProcess(); + } + // Stylo is not enabled for any other process. + MOZ_DIAGNOSTIC_ASSERT(false, "We should not be creating any document " + "in processes other than content and parent"); + return false; + } + + // Whether Stylo should be used on chrome documents. + static bool StyloChromeEnabled(); + static uint32_t IdlePeriodDeadlineLimit() { return sIdlePeriodDeadlineLimit; } @@ -2549,6 +2579,11 @@ public: static void Initialize(); static void Shutdown(); + /** + * Return whether stylo should be used for a given document principal. + */ + static bool ShouldUseStylo(nsIPrincipal* aPrincipal); + /** * Register an imgIRequest object with a refresh driver. * @@ -3066,6 +3101,7 @@ private: static bool sInterruptibleReflowEnabled; static bool sSVGTransformBoxEnabled; static bool sTextCombineUprightDigitsEnabled; + static bool sStyloEnabled; static uint32_t sIdlePeriodDeadlineLimit; static uint32_t sQuiescentFramesBeforeIdlePeriod; diff --git a/layout/base/nsStyleSheetService.cpp b/layout/base/nsStyleSheetService.cpp index 95c3a384f836..826a797753ef 100644 --- a/layout/base/nsStyleSheetService.cpp +++ b/layout/base/nsStyleSheetService.cpp @@ -170,11 +170,24 @@ nsStyleSheetService::LoadAndRegisterSheet(nsIURI *aSheetURI, rv = LoadAndRegisterSheetInternal(aSheetURI, aSheetType); if (NS_SUCCEEDED(rv)) { + // Success means that at least the Gecko sheet was loaded. It's possible + // that a Servo sheet was also loaded. In both cases, the new sheets are + // the last sheets in m{Gecko,Servo}Sheets[aSheetType] + bool servoSheetWasAdded = false; + servoSheetWasAdded = nsLayoutUtils::StyloSupportedInCurrentProcess(); + // Hold on to a copy of the registered PresShells. nsTArray> toNotify(mPresShells); for (nsIPresShell* presShell : toNotify) { - StyleSheet* sheet = Sheets(StyleBackendType::Servo)[aSheetType].LastElement(); - presShell->NotifyStyleSheetServiceSheetAdded(sheet, aSheetType); + if (presShell->StyleSet()) { + StyleBackendType backendType = presShell->StyleSet()->BackendType(); + if (backendType == StyleBackendType::Gecko || servoSheetWasAdded) { + StyleSheet* sheet = Sheets(backendType)[aSheetType].LastElement(); + presShell->NotifyStyleSheetServiceSheetAdded(sheet, aSheetType); + } else { + MOZ_ASSERT_UNREACHABLE("Servo pres shell, but stylo unsupported?"); + } + } } if (XRE_IsParentProcess()) { @@ -232,11 +245,14 @@ nsStyleSheetService::LoadAndRegisterSheetInternal(nsIURI *aSheetURI, } - RefPtr servoSheet; - nsresult rv = LoadSheet(aSheetURI, parsingMode, StyleBackendType::Servo, &servoSheet); - NS_ENSURE_SUCCESS(rv, rv); - MOZ_ASSERT(servoSheet); - mServoSheets[aSheetType].AppendElement(servoSheet); + + if (nsLayoutUtils::StyloSupportedInCurrentProcess()) { + RefPtr servoSheet; + nsresult rv = LoadSheet(aSheetURI, parsingMode, StyleBackendType::Servo, &servoSheet); + NS_ENSURE_SUCCESS(rv, rv); + MOZ_ASSERT(servoSheet); + mServoSheets[aSheetType].AppendElement(servoSheet); + } return NS_OK; } diff --git a/layout/style/PreloadedStyleSheet.cpp b/layout/style/PreloadedStyleSheet.cpp index 8a753a5e2ac0..73f089ddc991 100644 --- a/layout/style/PreloadedStyleSheet.cpp +++ b/layout/style/PreloadedStyleSheet.cpp @@ -85,10 +85,13 @@ PreloadedStyleSheet::Preload() // fetching the URL again, but for the usage patterns of this API this is // unlikely, and it doesn't seem worth trying to store the contents of the URL // and duplicating a bunch of css::Loader's logic. + auto type = nsLayoutUtils::StyloEnabled() ? StyleBackendType::Servo + : StyleBackendType::Gecko; + mLoaded = true; StyleSheet* sheet; - return GetSheet(StyleBackendType::Servo, &sheet); + return GetSheet(type, &sheet); } NS_IMPL_ISUPPORTS(PreloadedStyleSheet::StylesheetPreloadObserver, @@ -117,10 +120,17 @@ PreloadedStyleSheet::PreloadAsync(NotNull aPromise) { MOZ_DIAGNOSTIC_ASSERT(!mLoaded); - RefPtr& sheet = mServo; + // As with the Preload() method, we can't be sure that the sheet will only be + // used with the backend that we're preloading it for now. If it's used with + // a different backend later, it will be synchronously loaded for that + // backend the first time it's used. + auto type = nsLayoutUtils::StyloEnabled() ? StyleBackendType::Servo + : StyleBackendType::Gecko; - RefPtr loader = - new css::Loader(StyleBackendType::Servo, nullptr); + RefPtr& sheet = + type == StyleBackendType::Gecko ? mGecko : mServo; + + RefPtr loader = new css::Loader(type, nullptr); RefPtr obs = new StylesheetPreloadObserver(aPromise, this); diff --git a/layout/style/ServoBindings.toml b/layout/style/ServoBindings.toml index 08bf696b5af7..f5a427135783 100644 --- a/layout/style/ServoBindings.toml +++ b/layout/style/ServoBindings.toml @@ -2,7 +2,7 @@ args = [ "-x", "c++", "-std=c++14", "-fno-sized-deallocation", "-DTRACING=1", "-DIMPL_LIBXUL", "-DMOZ_STYLO_BINDINGS=1", - "-DMOZILLA_INTERNAL_API", "-DRUST_BINDGEN" + "-DMOZILLA_INTERNAL_API", "-DRUST_BINDGEN", "-DMOZ_STYLO" ] "family=unix" = ["-DOS_POSIX=1"] "os=solaris" = ["-DOS_SOLARIS=1"] diff --git a/layout/tools/reftest/manifest.jsm b/layout/tools/reftest/manifest.jsm index a755a39641f3..6a87156ef5ab 100644 --- a/layout/tools/reftest/manifest.jsm +++ b/layout/tools/reftest/manifest.jsm @@ -482,8 +482,21 @@ let retainedDisplayListsEnabled = prefs.getBoolPref("layout.display-list.retain" sandbox.retainedDisplayLists = retainedDisplayListsEnabled && !g.compareRetainedDisplayLists; sandbox.compareRetainedDisplayLists = g.compareRetainedDisplayLists; -// TODO(emilio): Remove the remaining reftest expectations that mention stylo. -sandbox.stylo = true; +#ifdef MOZ_STYLO + let styloEnabled = false; + // Perhaps a bit redundant in places, but this is easier to compare with the + // the real check in `nsLayoutUtils.cpp` to ensure they test the same way. + if (env.get("STYLO_FORCE_ENABLED")) { + styloEnabled = true; + } else if (env.get("STYLO_FORCE_DISABLED")) { + styloEnabled = false; + } else { + styloEnabled = prefs.getBoolPref("layout.css.servo.enabled", false); + } + sandbox.stylo = styloEnabled; +#else + sandbox.stylo = false; +#endif sandbox.skiaPdf = false; diff --git a/layout/xul/crashtests/crashtests.list b/layout/xul/crashtests/crashtests.list index 5f501ea70ffc..2eb7d5c6986c 100644 --- a/layout/xul/crashtests/crashtests.list +++ b/layout/xul/crashtests/crashtests.list @@ -97,5 +97,11 @@ load 583957-1.html load 617089.html load menulist-focused.xhtml load 716503.html -load 1379332-1.xul -load 1379332-2.xul + +# Bug 1379332's tests need stylo to be disabled in order for the +# 'visiblity:collapse' to take effect (which is needed to trigger the assertion +# that these tests are screening for, in unpatched builds). (Also, we skip +# these tests on Android, because otherwise we trigger bug 1350948 when trying +# to force the servo pref to false on that platform.) +skip-if(Android) pref(layout.css.servo.enabled,false) load 1379332-1.xul +skip-if(Android) pref(layout.css.servo.enabled,false) load 1379332-2.xul diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 1f6d537c9ad1..4d62152900a6 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -5918,6 +5918,21 @@ pref("dom.webkitBlink.filesystem.enabled", true); pref("media.block-autoplay-until-in-foreground", true); +// Is Stylo CSS support built and enabled? +// Only define these prefs if Stylo support is actually built in. +#ifdef MOZ_STYLO +#ifdef MOZ_STYLO_ENABLE +pref("layout.css.servo.enabled", true); +#else +pref("layout.css.servo.enabled", false); +#endif +// Whether Stylo is enabled for chrome document? +// If Stylo is not enabled, this pref doesn't take any effect. +// Note that this pref is only read once when requested. Changing it +// at runtime may have no effect. +pref("layout.css.servo.chrome.enabled", true); +#endif + // TODO: Bug 1324406: Treat 'data:' documents as unique, opaque origins // If true, data: URIs will be treated as unique opaque origins, hence will use // a NullPrincipal as the security context. diff --git a/python/mozbuild/mozbuild/mozinfo.py b/python/mozbuild/mozbuild/mozinfo.py index daa729baaffa..7e7ad1b2a8f2 100755 --- a/python/mozbuild/mozbuild/mozinfo.py +++ b/python/mozbuild/mozbuild/mozinfo.py @@ -83,8 +83,7 @@ def build_dict(config, env=os.environ): d['datareporting'] = bool(substs.get('MOZ_DATA_REPORTING')) d['healthreport'] = substs.get('MOZ_SERVICES_HEALTHREPORT') == '1' d['sync'] = substs.get('MOZ_SERVICES_SYNC') == '1' - # FIXME(emilio): We need to update a lot of WPT expectations before removing this. - d['stylo'] = True + d['stylo'] = substs.get('MOZ_STYLO_ENABLE') == '1' d['asan'] = substs.get('MOZ_ASAN') == '1' d['tsan'] = substs.get('MOZ_TSAN') == '1' d['ubsan'] = substs.get('MOZ_UBSAN') == '1' diff --git a/testing/awsy/mach_commands.py b/testing/awsy/mach_commands.py index 3fab62425d59..6be50735e5bb 100644 --- a/testing/awsy/mach_commands.py +++ b/testing/awsy/mach_commands.py @@ -69,6 +69,9 @@ class MachCommands(MachCommandBase): else: os.environ['STYLO_THREADS'] = '4' + if 'enable_stylo' in kwargs and kwargs['enable_stylo']: + os.environ['STYLO_FORCE_ENABLED'] = '1' + if 'enable_webrender' in kwargs and kwargs['enable_webrender']: os.environ['MOZ_WEBRENDER'] = '1' os.environ['MOZ_ACCELERATED'] = '1' @@ -202,6 +205,9 @@ class MachCommands(MachCommandBase): dest='settleWaitTime', help='Seconds to wait for things to settled down. ' 'Defaults to %s.' % SETTLE_WAIT_TIME) + @CommandArgument('--enable-stylo', group='AWSY', action='store_true', + dest='enable_stylo', default=False, + help='Enable Stylo.') @CommandArgument('--single-stylo-traversal', group='AWSY', action='store_true', dest='single_stylo_traversal', default=False, help='Set STYLO_THREADS=1.') diff --git a/testing/mozharness/scripts/desktop_unittest.py b/testing/mozharness/scripts/desktop_unittest.py index 53201eaa72e2..160de6f705e6 100755 --- a/testing/mozharness/scripts/desktop_unittest.py +++ b/testing/mozharness/scripts/desktop_unittest.py @@ -163,6 +163,12 @@ class DesktopUnittest(TestingMixin, MercurialScript, BlobUploadMixin, MozbaseMix "default": False, "help": "Forcibly enable single thread traversal in Stylo with STYLO_THREADS=1"} ], + [["--enable-stylo"], { + "action": "store_true", + "dest": "enable_stylo", + "default": False, + "help": "Run tests with Stylo enabled"} + ], [["--enable-webrender"], { "action": "store_true", "dest": "enable_webrender", diff --git a/testing/mozharness/scripts/web_platform_tests.py b/testing/mozharness/scripts/web_platform_tests.py index 53668cbce3ea..3e5ac54edbab 100755 --- a/testing/mozharness/scripts/web_platform_tests.py +++ b/testing/mozharness/scripts/web_platform_tests.py @@ -88,6 +88,18 @@ class WebPlatformTest(TestingMixin, MercurialScript, BlobUploadMixin, CodeCovera "default": False, "help": "Forcibly enable single thread traversal in Stylo with STYLO_THREADS=1"} ], + [["--enable-stylo"], { + "action": "store_true", + "dest": "enable_stylo", + "default": False, + "help": "Run tests with Stylo enabled"} + ], + [["--disable-stylo"], { + "action": "store_true", + "dest": "disable_stylo", + "default": False, + "help": "Run tests with Stylo disabled"} + ], ] + copy.deepcopy(testing_config_options) + \ copy.deepcopy(blobupload_config_options) + \ copy.deepcopy(code_coverage_config_options) @@ -310,11 +322,20 @@ class WebPlatformTest(TestingMixin, MercurialScript, BlobUploadMixin, CodeCovera env['MOZ_HEADLESS_WIDTH'] = self.config['headless_width'] env['MOZ_HEADLESS_HEIGHT'] = self.config['headless_height'] + if self.config['disable_stylo']: + if self.config['single_stylo_traversal']: + self.fatal("--disable-stylo conflicts with --single-stylo-traversal") + if self.config['enable_stylo']: + self.fatal("--disable-stylo conflicts with --enable-stylo") + if self.config['single_stylo_traversal']: env['STYLO_THREADS'] = '1' else: env['STYLO_THREADS'] = '4' + if self.config['enable_stylo']: + env['STYLO_FORCE_ENABLED'] = '1' + env = self.query_env(partial_env=env, log_level=INFO) start_time = datetime.now() diff --git a/toolkit/components/telemetry/TelemetryEnvironment.jsm b/toolkit/components/telemetry/TelemetryEnvironment.jsm index fd493042f6e0..0ec5d97e88c8 100644 --- a/toolkit/components/telemetry/TelemetryEnvironment.jsm +++ b/toolkit/components/telemetry/TelemetryEnvironment.jsm @@ -245,6 +245,7 @@ const DEFAULT_ENVIRONMENT_PREFS = new Map([ ["layers.prefer-d3d9", {what: RECORD_PREF_VALUE}], ["layers.prefer-opengl", {what: RECORD_PREF_VALUE}], ["layout.css.devPixelsPerPx", {what: RECORD_PREF_VALUE}], + ["layout.css.servo.enabled", {what: RECORD_PREF_VALUE}], ["marionette.enabled", {what: RECORD_PREF_VALUE}], ["network.proxy.autoconfig_url", {what: RECORD_PREF_STATE}], ["network.proxy.http", {what: RECORD_PREF_STATE}], diff --git a/toolkit/library/rust/gkrust-features.mozbuild b/toolkit/library/rust/gkrust-features.mozbuild index ce57d8645a10..9c931b876437 100644 --- a/toolkit/library/rust/gkrust-features.mozbuild +++ b/toolkit/library/rust/gkrust-features.mozbuild @@ -4,10 +4,15 @@ # 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/. -gkrust_features = ['servo', 'bindgen'] +gkrust_features = [] +if CONFIG['MOZ_STYLO']: + gkrust_features += ['servo'] -if CONFIG['MOZ_DEBUG']: - gkrust_features += ['gecko_debug'] + if CONFIG['MOZ_STYLO_BINDGEN']: + gkrust_features += ['bindgen'] + + if CONFIG['MOZ_DEBUG']: + gkrust_features += ['gecko_debug'] if CONFIG['MOZ_BUILD_WEBRENDER']: gkrust_features += ['quantum_render'] diff --git a/toolkit/modules/AppConstants.jsm b/toolkit/modules/AppConstants.jsm index a77c572d1c7c..e1b27e0159ab 100644 --- a/toolkit/modules/AppConstants.jsm +++ b/toolkit/modules/AppConstants.jsm @@ -333,4 +333,12 @@ this.AppConstants = Object.freeze({ #else false, #endif + + MOZ_STYLO: +#ifdef MOZ_STYLO + true, +#else + false, +#endif + }); diff --git a/toolkit/modules/Troubleshoot.jsm b/toolkit/modules/Troubleshoot.jsm index 024c50aa29d7..3893565e39d6 100644 --- a/toolkit/modules/Troubleshoot.jsm +++ b/toolkit/modules/Troubleshoot.jsm @@ -16,6 +16,9 @@ try { } catch (e) { } +const env = Cc["@mozilla.org/process/environment;1"] + .getService(Ci.nsIEnvironment); + // We use a preferences whitelist to make sure we only show preferences that // are useful for support and won't compromise the user's privacy. Note that // entries are *prefixes*: for example, "accessibility." applies to all prefs @@ -64,6 +67,7 @@ const PREFS_WHITELIST = [ "keyword.", "layers.", "layout.css.dpi", + "layout.css.servo.", "layout.display-list.", "media.", "mousewheel.", @@ -220,6 +224,33 @@ var dataProviders = { data.autoStartStatus = -1; } + data.styloBuild = AppConstants.MOZ_STYLO; + data.styloDefault = Services.prefs.getDefaultBranch(null) + .getBoolPref("layout.css.servo.enabled", false); + data.styloResult = false; + // Perhaps a bit redundant in places, but this is easier to compare with the + // the real check in `nsLayoutUtils.cpp` to ensure they test the same way. + if (AppConstants.MOZ_STYLO) { + if (env.get("STYLO_FORCE_ENABLED")) { + data.styloResult = true; + } else if (env.get("STYLO_FORCE_DISABLED")) { + data.styloResult = false; + } else { + data.styloResult = + Services.prefs.getBoolPref("layout.css.servo.enabled", false); + } + } + data.styloChromeDefault = + Services.prefs.getDefaultBranch(null) + .getBoolPref("layout.css.servo.chrome.enabled", false); + data.styloChromeResult = false; + if (data.styloResult) { + let winUtils = Services.wm.getMostRecentWindow(""). + QueryInterface(Ci.nsIInterfaceRequestor). + getInterface(Ci.nsIDOMWindowUtils); + data.styloChromeResult = winUtils.isStyledByServo; + } + if (Services.policies) { data.policiesStatus = Services.policies.status; } diff --git a/toolkit/modules/tests/browser/browser_Troubleshoot.js b/toolkit/modules/tests/browser/browser_Troubleshoot.js index a23e1354cc07..68cc9471252d 100644 --- a/toolkit/modules/tests/browser/browser_Troubleshoot.js +++ b/toolkit/modules/tests/browser/browser_Troubleshoot.js @@ -144,6 +144,21 @@ const SNAPSHOT_SCHEMA = { maxContentProcesses: { type: "number", }, + styloBuild: { + type: "boolean", + }, + styloDefault: { + type: "boolean", + }, + styloResult: { + type: "boolean", + }, + styloChromeDefault: { + type: "boolean", + }, + styloChromeResult: { + type: "boolean", + }, policiesStatus: { type: "number", }, diff --git a/toolkit/moz.configure b/toolkit/moz.configure index 54a6066c60f9..d9f50d1d219e 100644 --- a/toolkit/moz.configure +++ b/toolkit/moz.configure @@ -550,6 +550,47 @@ id_and_secret_keyfile('Leanplum SDK') simple_keyfile('Pocket API') +# Servo integration +# ============================================================== +option('--enable-stylo', nargs='?', choices=('build',), + help='Include Stylo in the build. "build" means to disable Stylo at ' + + 'runtime.') + +@depends('--enable-stylo', '--help') +def stylo_config(value, _): + # If nothing is specified, default to building and enabling Stylo, + # and not building the old style system. + build_stylo = True + enable_stylo = True + old_style = None + + if len(value) and value[0] == 'build': + # Build but disable by request. + enable_stylo = None + old_style = True + elif value.origin != 'default' and not bool(value): + # Disable stylo entirely. + old_style = True + build_stylo = None + enable_stylo = None + + return namespace( + build = build_stylo, + enable = enable_stylo, + old_style = old_style, + ) + +option('--disable-stylo-build-bindgen', + help='Disable build-time bindgen for Stylo') + +@depends('--enable-stylo-build-bindgen', '--enable-compile-environment') +def building_stylo_bindgen(bindgen_enabled, compile_environment): + if not compile_environment: + return False + if not bindgen_enabled: + return False + return True + # We support setting up the appropriate options for Stylo's build-time # bindings generation via setting LLVM_CONFIG or by providing explicit # configure options. The Windows installer of LLVM/Clang doesn't provide @@ -599,151 +640,161 @@ def llvm_config_paths(host): return llvm_config_progs llvm_config = check_prog('LLVM_CONFIG', llvm_config_paths, + when=building_stylo_bindgen, what='llvm-config', allow_missing=True) -option('--with-libclang-path', nargs=1, - help='Absolute path to a directory containing Clang/LLVM libraries for Stylo (version 3.9.x or above)') -option('--with-clang-path', nargs=1, - help='Absolute path to a Clang binary for Stylo bindgen (version 3.9.x or above)') +with only_when(building_stylo_bindgen): + option('--with-libclang-path', nargs=1, + help='Absolute path to a directory containing Clang/LLVM libraries for Stylo (version 3.9.x or above)') + option('--with-clang-path', nargs=1, + help='Absolute path to a Clang binary for Stylo bindgen (version 3.9.x or above)') -def invoke_llvm_config(llvm_config, *options): - '''Invoke llvm_config with the given options and return the first line of - output.''' - lines = check_cmd_output(llvm_config, *options).splitlines() - return lines[0] + def invoke_llvm_config(llvm_config, *options): + '''Invoke llvm_config with the given options and return the first line of + output.''' + lines = check_cmd_output(llvm_config, *options).splitlines() + return lines[0] -@imports(_from='textwrap', _import='dedent') -def check_minimum_llvm_config_version(llvm_config): - version = Version(invoke_llvm_config(llvm_config, '--version')) - min_version = Version('3.9.0') - if version < min_version: - die(dedent('''\ - llvm installation {} is incompatible with Stylo bindgen. - - To compile Stylo, please install version {} or greater of - Clang + LLVM and ensure that the 'llvm-config' from that - installation is first on your path. - - You can verify this by typing 'llvm-config --version'. - '''.format(version, min_version))) - -@depends(llvm_config, '--with-libclang-path', '--with-clang-path', - host_library_name_info, host) -@imports('os.path') -@imports('glob') -@imports(_from='textwrap', _import='dedent') -def bindgen_config_paths(llvm_config, libclang_path, clang_path, - library_name_info, host): - def search_for_libclang(path): - # Try to ensure that the clang shared library that bindgen is going - # to look for is actually present. The files that we search for - # mirror the logic in clang-sys/build.rs. - libclang_choices = [] - if host.os == 'WINNT': - libclang_choices.append('libclang.dll') - libclang_choices.append('%sclang%s' % (library_name_info.dll.prefix, - library_name_info.dll.suffix)) - if host.kernel == 'Linux': - libclang_choices.append('libclang.so.1') - - if host.os == 'OpenBSD': - libclang_choices = glob.glob(path + '/libclang.so.*.*') - - # At least one of the choices must be found. - for choice in libclang_choices: - libclang = os.path.join(path, choice) - if os.path.exists(libclang): - return (True, None) - else: - return (False, list(set(libclang_choices))) - - if not libclang_path and not clang_path: - # We must have LLVM_CONFIG in this case. - if not llvm_config: + @imports(_from='textwrap', _import='dedent') + def check_minimum_llvm_config_version(llvm_config): + version = Version(invoke_llvm_config(llvm_config, '--version')) + min_version = Version('3.9.0') + if version < min_version: die(dedent('''\ - Could not find LLVM/Clang installation for compiling stylo build-time - bindgen. Please specify the 'LLVM_CONFIG' environment variable - (recommended), pass the '--with-libclang-path' and '--with-clang-path' - options to configure, or put 'llvm-config' in your PATH. Altering your - PATH may expose 'clang' as well, potentially altering your compiler, - which may not be what you intended.''')) + llvm installation {} is incompatible with Stylo bindgen. - check_minimum_llvm_config_version(llvm_config) - libclang_arg = '--bindir' if host.os == 'WINNT' else '--libdir' - libclang_path = invoke_llvm_config(llvm_config, libclang_arg) - clang_path = os.path.join(invoke_llvm_config(llvm_config, '--bindir'), - 'clang') - libclang_path = normsep(libclang_path) - clang_path = normsep(clang_path) + To compile Stylo, please install version {} or greater of + Clang + LLVM and ensure that the 'llvm-config' from that + installation is first on your path. - # Debian-based distros, at least, can have llvm-config installed - # but not have other packages installed. Since the user is trying - # to use their system packages, we can't be more specific about what - # they need. - clang_resolved = find_program(clang_path) - if not clang_resolved: + You can verify this by typing 'llvm-config --version'. + '''.format(version, min_version))) + + @depends(llvm_config, '--with-libclang-path', '--with-clang-path', + host_library_name_info, host) + @imports('os.path') + @imports('glob') + @imports(_from='textwrap', _import='dedent') + def bindgen_config_paths(llvm_config, libclang_path, clang_path, + library_name_info, host): + def search_for_libclang(path): + # Try to ensure that the clang shared library that bindgen is going + # to look for is actually present. The files that we search for + # mirror the logic in clang-sys/build.rs. + libclang_choices = [] + if host.os == 'WINNT': + libclang_choices.append('libclang.dll') + libclang_choices.append('%sclang%s' % (library_name_info.dll.prefix, + library_name_info.dll.suffix)) + if host.kernel == 'Linux': + libclang_choices.append('libclang.so.1') + + if host.os == 'OpenBSD': + libclang_choices = glob.glob(path + '/libclang.so.*.*') + + # At least one of the choices must be found. + for choice in libclang_choices: + libclang = os.path.join(path, choice) + if os.path.exists(libclang): + return (True, None) + else: + return (False, list(set(libclang_choices))) + + if not libclang_path and not clang_path: + # We must have LLVM_CONFIG in this case. + if not llvm_config: + die(dedent('''\ + Could not find LLVM/Clang installation for compiling stylo build-time + bindgen. Please specify the 'LLVM_CONFIG' environment variable + (recommended), pass the '--with-libclang-path' and '--with-clang-path' + options to configure, or put 'llvm-config' in your PATH. Altering your + PATH may expose 'clang' as well, potentially altering your compiler, + which may not be what you intended.''')) + + check_minimum_llvm_config_version(llvm_config) + libclang_arg = '--bindir' if host.os == 'WINNT' else '--libdir' + libclang_path = invoke_llvm_config(llvm_config, libclang_arg) + clang_path = os.path.join(invoke_llvm_config(llvm_config, '--bindir'), + 'clang') + libclang_path = normsep(libclang_path) + clang_path = normsep(clang_path) + + # Debian-based distros, at least, can have llvm-config installed + # but not have other packages installed. Since the user is trying + # to use their system packages, we can't be more specific about what + # they need. + clang_resolved = find_program(clang_path) + if not clang_resolved: + die(dedent('''\ + The file {} returned by `llvm-config {}` does not exist. + clang is required to build Stylo. Please install the necessary packages, + run `mach bootstrap`, or add --disable-stylo to your mozconfig. + '''.format(clang_path, '--bindir'))) + + if not os.path.exists(libclang_path): + die(dedent('''\ + The directory {} returned by `llvm-config {}` does not exist. + clang is required to build Stylo. Please install the necessary packages, + run `mach bootstrap`, or add --disable-stylo to your mozconfig. + '''.format(libclang_path, libclang_arg))) + + (found, searched) = search_for_libclang(libclang_path) + if not found: + die(dedent('''\ + Could not find the clang shared library in the path {} + returned by `llvm-config {}` (searched for files {}). + clang is required to build Stylo. Please install the necessary packages, + run `mach bootstrap`, or add --disable-stylo to your mozconfig. + '''.format(libclang_path, libclang_arg, searched))) + + return namespace( + libclang_path=libclang_path, + clang_path=clang_resolved, + ) + + if (not libclang_path and clang_path) or \ + (libclang_path and not clang_path): die(dedent('''\ - The file {} returned by `llvm-config {}` does not exist. - clang is required to build Firefox. Please install the necessary - packages, or run `mach bootstrap`. - '''.format(clang_path, '--bindir'))) + You must provide both of --with-libclang-path and --with-clang-path + or neither of them.''')) - if not os.path.exists(libclang_path): + libclang_path = libclang_path[0] + clang_path = clang_path[0] + + if not os.path.exists(libclang_path) or \ + not os.path.isdir(libclang_path): die(dedent('''\ - The directory {} returned by `llvm-config {}` does not exist. - clang is required to build Firefox. Please install the necessary - packages, or run `mach bootstrap`. - '''.format(libclang_path, libclang_arg))) + The argument to --with-libclang-path is not a directory: {} + '''.format(libclang_path))) (found, searched) = search_for_libclang(libclang_path) if not found: die(dedent('''\ Could not find the clang shared library in the path {} - returned by `llvm-config {}` (searched for files {}). - clang is required to build Firefox. Please install the necessary - packages, or run `mach bootstrap`. - '''.format(libclang_path, libclang_arg, searched))) + specified by --with-libclang-path (searched for files {}). + '''.format(libclang_path, searched))) + + clang_resolved = find_program(clang_path) + if not clang_resolved: + die(dedent('''\ + The argument to --with-clang-path is not a file: {} + '''.format(clang_path))) return namespace( libclang_path=libclang_path, clang_path=clang_resolved, ) - if (not libclang_path and clang_path) or \ - (libclang_path and not clang_path): - die(dedent('''\ - You must provide both of --with-libclang-path and --with-clang-path - or neither of them.''')) + set_config('MOZ_LIBCLANG_PATH', bindgen_config_paths.libclang_path) + set_config('MOZ_CLANG_PATH', bindgen_config_paths.clang_path) + set_config('MOZ_STYLO_BINDGEN', depends_if('--enable-stylo-build-bindgen')(lambda _: True)) - libclang_path = libclang_path[0] - clang_path = clang_path[0] - - if not os.path.exists(libclang_path) or \ - not os.path.isdir(libclang_path): - die(dedent('''\ - The argument to --with-libclang-path is not a directory: {} - '''.format(libclang_path))) - - (found, searched) = search_for_libclang(libclang_path) - if not found: - die(dedent('''\ - Could not find the clang shared library in the path {} - specified by --with-libclang-path (searched for files {}). - '''.format(libclang_path, searched))) - - clang_resolved = find_program(clang_path) - if not clang_resolved: - die(dedent('''\ - The argument to --with-clang-path is not a file: {} - '''.format(clang_path))) - - return namespace( - libclang_path=libclang_path, - clang_path=clang_resolved, - ) - -set_config('MOZ_LIBCLANG_PATH', bindgen_config_paths.libclang_path) -set_config('MOZ_CLANG_PATH', bindgen_config_paths.clang_path) +set_config('MOZ_STYLO', stylo_config.build) +set_define('MOZ_STYLO', stylo_config.build) +set_config('MOZ_STYLO_ENABLE', stylo_config.enable) +set_define('MOZ_STYLO_ENABLE', stylo_config.enable) +set_config('MOZ_OLD_STYLE', stylo_config.old_style) +set_define('MOZ_OLD_STYLE', stylo_config.old_style) option('--with-servo', env='SERVO_TARGET_DIR', nargs=1, help='Absolute path of the target directory where libgeckoservo can ' diff --git a/toolkit/mozapps/installer/packager.mk b/toolkit/mozapps/installer/packager.mk index ddceb15cbb35..49133c9c9beb 100644 --- a/toolkit/mozapps/installer/packager.mk +++ b/toolkit/mozapps/installer/packager.mk @@ -91,11 +91,13 @@ ifdef MOZ_ASAN $(PYTHON) $(MOZILLA_DIR)/build/unix/rewrite_asan_dylib.py $(DIST)/$(MOZ_PKG_DIR)$(_BINPATH) endif # MOZ_ASAN endif # Darwin +ifdef MOZ_STYLO ifndef MOZ_ARTIFACT_BUILDS @echo 'Packing stylo binding files...' cd '$(DIST)/rust_bindings/style' && \ zip -r5D '$(ABS_DIST)/$(PKG_PATH)$(STYLO_BINDINGS_PACKAGE)' . endif # MOZ_ARTIFACT_BUILDS +endif # MOZ_STYLO prepare-package: stage-package diff --git a/toolkit/mozapps/installer/upload-files.mk b/toolkit/mozapps/installer/upload-files.mk index 240f07accfce..8ace9703a160 100644 --- a/toolkit/mozapps/installer/upload-files.mk +++ b/toolkit/mozapps/installer/upload-files.mk @@ -407,7 +407,6 @@ UPLOAD_FILES= \ $(call QUOTED_WILDCARD,$(topobjdir)/$(MOZ_BUILD_APP)/installer/windows/instgen/setup.exe) \ $(call QUOTED_WILDCARD,$(topobjdir)/$(MOZ_BUILD_APP)/installer/windows/instgen/setup-stub.exe) \ $(call QUOTED_WILDCARD,$(topsrcdir)/toolchains.json) \ - $(call QUOTED_WILDCARD,$(DIST)/$(PKG_PATH)$(STYLO_BINDINGS_PACKAGE)) \ $(if $(UPLOAD_EXTRA_FILES), $(foreach f, $(UPLOAD_EXTRA_FILES), $(wildcard $(DIST)/$(f)))) ifneq ($(filter-out en-US x-test,$(AB_CD)),) @@ -424,6 +423,9 @@ ifdef MOZ_CODE_COVERAGE $(NULL) endif +ifdef MOZ_STYLO + UPLOAD_FILES += $(call QUOTED_WILDCARD,$(DIST)/$(PKG_PATH)$(STYLO_BINDINGS_PACKAGE)) +endif ifdef ENABLE_MOZSEARCH_PLUGIN UPLOAD_FILES += $(call QUOTED_WILDCARD,$(DIST)/$(PKG_PATH)$(MOZSEARCH_ARCHIVE_BASENAME).zip)