From 642b8b041567016c0ad3f6f4342c68a2fcd35daa Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sat, 26 Oct 2019 12:53:34 +0200 Subject: [PATCH 1/3] Move items at the root of the script crate to a module --- components/script/init.rs | 69 +++++++++++++++++++++++++++++++++++++++ components/script/lib.rs | 69 ++------------------------------------- 2 files changed, 72 insertions(+), 66 deletions(-) create mode 100644 components/script/init.rs diff --git a/components/script/init.rs b/components/script/init.rs new file mode 100644 index 00000000000..15428f4f3fe --- /dev/null +++ b/components/script/init.rs @@ -0,0 +1,69 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +use crate::dom::bindings::codegen::RegisterBindings; +use crate::dom::bindings::proxyhandler; +use crate::serviceworker_manager::ServiceWorkerManager; +use script_traits::SWManagerSenders; + +#[cfg(target_os = "linux")] +#[allow(unsafe_code)] +fn perform_platform_specific_initialization() { + // 4096 is default max on many linux systems + const MAX_FILE_LIMIT: libc::rlim_t = 4096; + + // Bump up our number of file descriptors to save us from impending doom caused by an onslaught + // of iframes. + unsafe { + let mut rlim = libc::rlimit { + rlim_cur: 0, + rlim_max: 0, + }; + match libc::getrlimit(libc::RLIMIT_NOFILE, &mut rlim) { + 0 => { + if rlim.rlim_cur >= MAX_FILE_LIMIT { + // we have more than enough + return; + } + + rlim.rlim_cur = match rlim.rlim_max { + libc::RLIM_INFINITY => MAX_FILE_LIMIT, + _ => { + if rlim.rlim_max < MAX_FILE_LIMIT { + rlim.rlim_max + } else { + MAX_FILE_LIMIT + } + }, + }; + match libc::setrlimit(libc::RLIMIT_NOFILE, &rlim) { + 0 => (), + _ => warn!("Failed to set file count limit"), + }; + }, + _ => warn!("Failed to get file count limit"), + }; + } +} + +#[cfg(not(target_os = "linux"))] +fn perform_platform_specific_initialization() {} + +pub fn init_service_workers(sw_senders: SWManagerSenders) { + // Spawn the service worker manager passing the constellation sender + ServiceWorkerManager::spawn_manager(sw_senders); +} + +#[allow(unsafe_code)] +pub fn init() { + unsafe { + proxyhandler::init(); + + // Create the global vtables used by the (generated) DOM + // bindings to implement JS proxies. + RegisterBindings::RegisterProxyHandlers(); + } + + perform_platform_specific_initialization(); +} diff --git a/components/script/lib.rs b/components/script/lib.rs index c87e705d1e9..0d85e377cf4 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -59,6 +59,7 @@ mod canvas_state; mod compartments; pub mod fetch; mod image_listener; +mod init; mod layout_image; mod mem; mod microtask; @@ -79,6 +80,8 @@ mod timers; mod unpremultiplytable; mod webdriver_handlers; +pub use init::{init, init_service_workers}; + /// A module with everything layout can use from script. /// /// Try to keep this small! @@ -98,69 +101,3 @@ pub mod layout_exports { pub use crate::dom::shadowroot::{LayoutShadowRootHelpers, ShadowRoot}; pub use crate::dom::text::Text; } - -use crate::dom::bindings::codegen::RegisterBindings; -use crate::dom::bindings::proxyhandler; -use crate::serviceworker_manager::ServiceWorkerManager; -use script_traits::SWManagerSenders; - -#[cfg(target_os = "linux")] -#[allow(unsafe_code)] -fn perform_platform_specific_initialization() { - // 4096 is default max on many linux systems - const MAX_FILE_LIMIT: libc::rlim_t = 4096; - - // Bump up our number of file descriptors to save us from impending doom caused by an onslaught - // of iframes. - unsafe { - let mut rlim = libc::rlimit { - rlim_cur: 0, - rlim_max: 0, - }; - match libc::getrlimit(libc::RLIMIT_NOFILE, &mut rlim) { - 0 => { - if rlim.rlim_cur >= MAX_FILE_LIMIT { - // we have more than enough - return; - } - - rlim.rlim_cur = match rlim.rlim_max { - libc::RLIM_INFINITY => MAX_FILE_LIMIT, - _ => { - if rlim.rlim_max < MAX_FILE_LIMIT { - rlim.rlim_max - } else { - MAX_FILE_LIMIT - } - }, - }; - match libc::setrlimit(libc::RLIMIT_NOFILE, &rlim) { - 0 => (), - _ => warn!("Failed to set file count limit"), - }; - }, - _ => warn!("Failed to get file count limit"), - }; - } -} - -#[cfg(not(target_os = "linux"))] -fn perform_platform_specific_initialization() {} - -pub fn init_service_workers(sw_senders: SWManagerSenders) { - // Spawn the service worker manager passing the constellation sender - ServiceWorkerManager::spawn_manager(sw_senders); -} - -#[allow(unsafe_code)] -pub fn init() { - unsafe { - proxyhandler::init(); - - // Create the global vtables used by the (generated) DOM - // bindings to implement JS proxies. - RegisterBindings::RegisterProxyHandlers(); - } - - perform_platform_specific_initialization(); -} From d3439fb4d105c1b772b45969f25bff8071d46cad Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sat, 26 Oct 2019 12:57:14 +0200 Subject: [PATCH 2/3] Upgrade to rustc 1.40.0-nightly (246be7e1a 2019-10-25) --- components/script/lib.rs | 32 +++++++++++++++++++++++++++++++- components/script_plugins/lib.rs | 17 ++++++++++------- rust-toolchain | 2 +- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/components/script/lib.rs b/components/script/lib.rs index 0d85e377cf4..48f42cd7a38 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -11,8 +11,9 @@ #![deny(unsafe_code)] #![allow(non_snake_case)] #![doc = "The script crate contains all matters DOM."] -#![plugin(script_plugins)] #![cfg_attr(not(feature = "unrooted_must_root_lint"), allow(unknown_lints))] +#![allow(deprecated)] // FIXME: Can we make `allow` only apply to the `plugin` crate attribute? +#![plugin(script_plugins)] #[macro_use] extern crate bitflags; @@ -47,37 +48,66 @@ extern crate servo_atoms; #[macro_use] extern crate style; +#[warn(deprecated)] #[macro_use] mod task; +#[warn(deprecated)] mod body; +#[warn(deprecated)] pub mod clipboard_provider; +#[warn(deprecated)] mod devtools; +#[warn(deprecated)] pub mod document_loader; +#[warn(deprecated)] #[macro_use] mod dom; +#[warn(deprecated)] mod canvas_state; +#[warn(deprecated)] mod compartments; +#[warn(deprecated)] pub mod fetch; +#[warn(deprecated)] mod image_listener; +#[warn(deprecated)] mod init; +#[warn(deprecated)] mod layout_image; +#[warn(deprecated)] mod mem; +#[warn(deprecated)] mod microtask; +#[warn(deprecated)] mod network_listener; +#[warn(deprecated)] pub mod script_runtime; +#[warn(deprecated)] #[allow(unsafe_code)] pub mod script_thread; +#[warn(deprecated)] mod serviceworker_manager; +#[warn(deprecated)] mod serviceworkerjob; +#[warn(deprecated)] mod stylesheet_loader; +#[warn(deprecated)] mod stylesheet_set; +#[warn(deprecated)] mod task_manager; +#[warn(deprecated)] mod task_queue; +#[warn(deprecated)] mod task_source; +#[warn(deprecated)] pub mod test; +#[warn(deprecated)] pub mod textinput; +#[warn(deprecated)] mod timers; +#[warn(deprecated)] mod unpremultiplytable; +#[warn(deprecated)] mod webdriver_handlers; pub use init::{init, init_service_workers}; diff --git a/components/script_plugins/lib.rs b/components/script_plugins/lib.rs index ea00a58848d..740ae9f35ad 100644 --- a/components/script_plugins/lib.rs +++ b/components/script_plugins/lib.rs @@ -27,7 +27,7 @@ extern crate syntax; use rustc::hir::def_id::DefId; use rustc::hir::intravisit as visit; use rustc::hir::{self, ExprKind, HirId}; -use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass}; +use rustc::lint::{LateContext, LateLintPass, LintContext, LintPass}; use rustc::ty; use rustc_driver::plugin::Registry; use syntax::feature_gate::AttributeType::Whitelisted; @@ -36,13 +36,20 @@ use syntax::source_map::{ExpnKind, MacroKind, Span}; use syntax::symbol::sym; use syntax::symbol::Symbol; +#[allow(deprecated)] #[plugin_registrar] pub fn plugin_registrar(reg: &mut Registry) { + registrar(reg) +} + +fn registrar(reg: &mut Registry) { let symbols = Symbols::new(); reg.register_attribute(symbols.allow_unrooted_interior, Whitelisted); reg.register_attribute(symbols.allow_unrooted_in_rc, Whitelisted); reg.register_attribute(symbols.must_root, Whitelisted); - reg.register_late_lint_pass(Box::new(UnrootedPass::new(symbols))); + reg.lint_store.register_lints(&[&UNROOTED_MUST_ROOT]); + reg.lint_store + .register_late_pass(move || Box::new(UnrootedPass::new(symbols.clone()))); } declare_lint!( @@ -165,10 +172,6 @@ impl LintPass for UnrootedPass { fn name(&self) -> &'static str { "ServoUnrootedPass" } - - fn get_lints(&self) -> LintArray { - lint_array!(UNROOTED_MUST_ROOT) - } } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnrootedPass { @@ -360,7 +363,7 @@ fn match_def_path(cx: &LateContext, def_id: DefId, path: &[Symbol]) -> bool { other .into_iter() .zip(path) - .all(|(e, p)| e.data.as_interned_str().as_symbol() == *p) + .all(|(e, p)| e.data.as_symbol() == *p) } fn in_derive_expn(span: Span) -> bool { diff --git a/rust-toolchain b/rust-toolchain index 6c1c2de2e23..fc6d4ce593e 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2019-09-28 +nightly-2019-10-26 From 6ba0fabc739c4d2942aba85b14d4276b6a186f89 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sun, 27 Oct 2019 17:54:29 +0100 Subject: [PATCH 3/3] Taskcluster: install the `rustc-dev` rustup component, required for compiler plugins --- etc/taskcluster/decision_task.py | 14 ++++++++++++++ etc/taskcluster/decisionlib.py | 2 -- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/etc/taskcluster/decision_task.py b/etc/taskcluster/decision_task.py index 2fe8d273adb..0a2664f32eb 100644 --- a/etc/taskcluster/decision_task.py +++ b/etc/taskcluster/decision_task.py @@ -157,6 +157,9 @@ def linux_tidy_unit_untrusted(): .with_dockerfile(dockerfile_path("build")) .with_env(**build_env, **unix_build_env, **linux_build_env) .with_repo() + .with_script("rustup set profile minimal") + # required by components/script_plugins: + .with_script("rustup component add rustc-dev") .with_script(""" ./mach test-tidy --no-progress --all ./mach test-tidy --no-progress --self-test @@ -761,6 +764,9 @@ def linux_build_task(name, *, build_env=build_env): .with_dockerfile(dockerfile_path("build")) .with_env(**build_env, **unix_build_env, **linux_build_env) .with_repo() + .with_script("rustup set profile minimal") + # required by components/script_plugins: + .with_script("rustup component add rustc-dev") ) @@ -806,6 +812,9 @@ def windows_build_task(name, package=True, arch="x86_64"): path="python3", ) .with_rustup() + .with_script("rustup set profile minimal") + # required by components/script_plugins: + .with_script("rustup component add rustc-dev") ) if arch in hashes["non-devel"] and arch in hashes["devel"]: task = ( @@ -858,6 +867,11 @@ def macos_build_task(name): .with_repo() .with_python2() .with_rustup() + # Since macOS workers are long-lived and ~/.rustup kept across tasks: + .with_script("rustup self update") + .with_script("rustup set profile minimal") + # required by components/script_plugins: + .with_script("rustup component add rustc-dev") .with_index_and_artifacts_expire_in(build_artifacts_expire_in) # Debugging for surprising generic-worker behaviour .with_early_script("ls") diff --git a/etc/taskcluster/decisionlib.py b/etc/taskcluster/decisionlib.py index 6e9cbe91973..93a5f3a8706 100644 --- a/etc/taskcluster/decisionlib.py +++ b/etc/taskcluster/decisionlib.py @@ -657,8 +657,6 @@ class MacOsGenericWorkerTask(UnixTaskMixin, GenericWorkerTask): return self.with_early_script(""" export PATH="$HOME/.cargo/bin:$PATH" which rustup || curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain none -y - rustup self update - rustup set profile minimal """)