Confirmed users
523
edits
Nnethercote (talk | contribs) |
No edit summary |
||
(34 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
'''Oxidation''' is a project to integrate [https://www.rust-lang.org/ Rust] code in and around Firefox. | '''Oxidation''' is a project to integrate [https://www.rust-lang.org/ Rust] code in and around Firefox. | ||
Rust support has been required on all platforms since Firefox 54, and the first major Rust components were shipped in Firefox 56 (encoding_rs) and 57 (Stylo). Moving forward, the goal of Oxidation is to make it easier and more | Rust support has been required on all platforms since Firefox 54, and the first major Rust components were shipped in Firefox 56 (encoding_rs) and 57 (Stylo). Moving forward, the goal of Oxidation is to make it easier and more productive to use Rust in Firefox, and correspondingly to increase the amount of Rust code in Firefox. | ||
This page is intended to serve as the starting point for all matters relating to Rust code in Firefox: the what, the why, and the how. | This page is intended to serve as the starting point for all matters relating to Rust code in Firefox: the what, the why, and the how. | ||
Line 18: | Line 18: | ||
Rust has the following strengths. | Rust has the following strengths. | ||
* Memory-safety and thread-safety. | * Memory-safety and thread-safety. Crashes and security vulnerabilities are much less likely. (Roughly 70% of critical security vulnerabilities are due to memory safety bugs.) | ||
* High performance. In particular, the safety enables code that is designed more actively for performance, especially parallel performance. | |||
* | * Nimbleness. The safety enables significant changes to existing code to be made quickly and with confidence. | ||
* | * Expressiveness. It is powerful and pleasant to use, particularly once a moderate level of experience has been reached. | ||
* | * Excellent package management and an extensive ecosystem. | ||
* Excellent compiler error messages. | * Excellent compiler error messages. | ||
* Excellent documentation. | * Excellent documentation. | ||
Line 74: | Line 74: | ||
== Rust in Firefox == | == Rust in Firefox == | ||
Policy | |||
* [[Rust_Update_Policy_for_Firefox|Rust Update Policy for Firefox]] | * [[Rust_Update_Policy_for_Firefox|Rust Update Policy for Firefox]] | ||
* [https://docs. | |||
* [https:// | Rust in Firefox docs | ||
* The Rust Matrix | * [https://firefox-source-docs.mozilla.org/build/buildsystem/rust.html Adding Rust code] | ||
* [https://firefox-source-docs.mozilla.org/writing-rust-code/index.html Writing Rust code] | |||
* [https://firefox-source-docs.mozilla.org/testing-rust-code/index.html Testing & debugging Rust code] | |||
Getting extra help | |||
* The Rust channel on [https://wiki.mozilla.org/Matrix Mozilla's Matrix network] contains lots of people who know about both Rust and Gecko. | |||
* Are you new to Rust and not sure if your Rust code could be improved? The following people can review Rust patches for Firefox from an "is this good Rust code?" point of view. | * Are you new to Rust and not sure if your Rust code could be improved? The following people can review Rust patches for Firefox from an "is this good Rust code?" point of view. | ||
** Alexis Beingessner (:Gankra) | ** Alexis Beingessner (:Gankra) | ||
Line 88: | Line 92: | ||
** Cameron McCormack (:heycam) | ** Cameron McCormack (:heycam) | ||
= | = Rust Components = | ||
== Within Firefox == | |||
= | === Statistics === | ||
= | * [https://docs.google.com/spreadsheets/d/1flUGg6Ut4bjtyWdyH_9emD9EAN01ljTAVft2S4Dq620/edit#gid=885787479 Lines of compiled Rust code shipped in Firefox (over time)] | ||
* [https://4e6.github.io/firefox-lang-stats/ Lines of Rust code in mozilla-central (current)] | |||
=== Shipped === | === Shipped === | ||
Line 116: | Line 109: | ||
** '''Why Rust?''' Code taken from Servo, uses parallel algorithms. | ** '''Why Rust?''' Code taken from Servo, uses parallel algorithms. | ||
* U2F HID backend: {{bug|1388843}} (shipped in Firefox 57) | * U2F HID backend: {{bug|1388843}} (shipped in Firefox 57) | ||
* libcubeb Audio backend for Linux (PulseAudio): {{bug|1346665}} (shipped in Firefox 59) | |||
* libcubeb Audio backend for macOS (CoreAudio): {{bug|1530713}} (shipped in Firefox 74) | |||
** '''Why Rust?''' Safer implementation avoids data racing by leveraging lifetime, variable mutability check and better mutex pattern. | |||
* XPIDL binding generator ({{bug|1293362}}) (shipped in Firefox 60) | * XPIDL binding generator ({{bug|1293362}}) (shipped in Firefox 60) | ||
* New prefs parser: {{bug|1423840}} (shipped in Firefox 60) | * New prefs parser: {{bug|1423840}} (shipped in Firefox 60) | ||
Line 121: | Line 117: | ||
* Audio remoting for Linux: {{bug|1434156}} (shipped in Firefox 60) | * Audio remoting for Linux: {{bug|1434156}} (shipped in Firefox 60) | ||
* WebRender: {{bug|webrender}} (shipped in Firefox 67, enabled for users with appropriate hardware) | * WebRender: {{bug|webrender}} (shipped in Firefox 67, enabled for users with appropriate hardware) | ||
** '''Why Rust?''' Code taken from Servo, has high performance; Rust's memory and thread safety | ** '''Why Rust?''' Code taken from Servo, has high performance; Rust's memory and thread safety assist productivity, and allow more aggressive optimizations. | ||
* kvstore (key-value storage backed by LMDB): {{bug|1490496}} (shipped in Firefox 67) | * kvstore (key-value storage backed by LMDB): {{bug|1490496}} (shipped in Firefox 67) | ||
** '''Why Rust?''' The rkv crate provides a safe, ergonomic wrapper around LMDB, our choice for simple key-value storage in Firefox. kvstore wraps rkv in an asynchronous XPCOM API for JS and C++ callers. | ** '''Why Rust?''' The rkv crate provides a safe, ergonomic wrapper around LMDB, our choice for simple key-value storage in Firefox. kvstore wraps rkv in an asynchronous XPCOM API for JS and C++ callers. | ||
* Profiler symbolication: {{bug|1509549}} (shipped in Firefox 67) | |||
** '''Why Rust?''' Makes use of existing crates that handle object file parsing and symbol iteration. Easy to compile to WebAssembly. | |||
* XUL store, backed by rkv: {{bug|1460811}} (landed in Firefox 68, used in Nightly only) | * XUL store, backed by rkv: {{bug|1460811}} (landed in Firefox 68, used in Nightly only) | ||
* TLS certificate store, backed by rkv: {{bug|1429796}} (shipped in Firefox 68) | * TLS certificate store, backed by rkv: {{bug|1429796}} (shipped in Firefox 68) | ||
Line 131: | Line 129: | ||
* Japanese encoding detector: {{bug|1543077}} (shipped in Firefox 69) | * Japanese encoding detector: {{bug|1543077}} (shipped in Firefox 69) | ||
** '''Why Rust?''' Builds upon encoding_rs, has tiny FFI surface, subject matter prone to accesses past the bounds of a buffer. | ** '''Why Rust?''' Builds upon encoding_rs, has tiny FFI surface, subject matter prone to accesses past the bounds of a buffer. | ||
* [https://github.com/padenot/audio_thread_priority audio_thread_priority] {{bug|1429847}} (shipped in Firefox 69), allow promoting threads to a real-time scheduling class, on Windows/Linux/macOS. | |||
** '''Why Rust?''' This crate is being used by C++ code and by Rust code (audioipc), Rust is nicer to write than C++ (especially for what is essentially just a series of system calls, the error checking style is nice), and cbindgen made it trivial to expose a C ABI. | |||
* [https://github.com/mozilla/dogear/ Dogear] a bookmark merger for Sync. Shipped pref'd-off in {{bug|1482608}} (Firefox 68), enabled by default in {{bug|1588005}} (shipped in Firefox 72) | |||
** '''Why Rust?''' A single performant and safe implementation shared between desktop and the bookmarks engine in [https://github.com/mozilla/application-services/tree/master/components/places application-services] | |||
* Unicode Language Identifier: {{bug|1571915}} (shipped in Firefox 72) | * Unicode Language Identifier: {{bug|1571915}} (shipped in Firefox 72) | ||
** '''Why Rust?''' Much faster, parser-heavy, easier to handle low-memory footprint thanks to `tinystr`. | ** '''Why Rust?''' Much faster, parser-heavy, easier to handle low-memory footprint thanks to `tinystr`. | ||
* Language Negotiation: {{bug|1581960}} (shipped in Firefox 72) | * Language Negotiation: {{bug|1581960}} (shipped in Firefox 72) | ||
** '''Why Rust?''' Ties into `unic-langid`, easier to handle list filtering and ordering. | ** '''Why Rust?''' Ties into `unic-langid`, easier to handle list filtering and ordering. | ||
* Replace libhyphen with mapped_hyph, {{bug|1590167}} (shipped in Firefox 72). | |||
* Encoding detector: {{bug|1551276}} (shipped in Firefox 73) | * Encoding detector: {{bug|1551276}} (shipped in Firefox 73) | ||
** '''Why Rust?''' Builds upon encoding_rs, has tiny FFI surface, subject matter prone to accesses past the bounds of a buffer, potentially parallelizable with Rayon. | ** '''Why Rust?''' Builds upon encoding_rs, has tiny FFI surface, subject matter prone to accesses past the bounds of a buffer, potentially parallelizable with Rayon. | ||
* [https://github.com/ | * Integrate [https://github.com/projectfluent/fluent-rs fluent-rs], a localization system: {{bug|1560038}} (shipped in Firefox 76) | ||
** '''Why Rust?''' | ** '''Why Rust?''' Performance and memory wins are substantial over previous JS implementation. It brings zero-copy parsing, and memory savvy resolving of localization strings. It also paves the way for migrating the rest of the Fluent APIs away from JS which is required for Fission. | ||
* qcms [https://searchfox.org/mozilla-central/source/gfx/qcms] ported from C to Rust | |||
** '''Why Rust?''' Memory safety | |||
** '''Why Rust?''' | |||
=== In progress === | === In progress === | ||
* | * Port [https://github.com/projectfluent/fluent-rs Localization API] to Rust: {{bug|1613705}} | ||
* [https://github.com/mozilla/neqo neqo] A QUIC implentation. | * [https://github.com/mozilla/neqo neqo] A QUIC implentation. | ||
* [https://github.com/CraneStation/cranelift/ cranelift, a low-level retargetable code generator]: {{bug|1469027}} | * [https://github.com/CraneStation/cranelift/ cranelift, a low-level retargetable code generator]: {{bug|1469027}} | ||
** '''Why Rust?''' It's a new, well-separated component with a clear interface. Also, Rust is a great language for writing compilers, due to algebraic data types and pattern matching. | ** '''Why Rust?''' It's a new, well-separated component with a clear interface. Also, Rust is a great language for writing compilers, due to algebraic data types and pattern matching. | ||
* [https://github.com/mozilla-spidermonkey/rust-frontend | * [https://github.com/mozilla-spidermonkey/rust-frontend SmooshMonkey] A Rust front-end for SpiderMonkey (featuring [https://github.com/mozilla-spidermonkey/jsparagus jsparagus]). | ||
** '''Why Rust?''' Parses untrusted input. Also, Rust is a great language for writing compilers, due to algebraic data types and pattern matching. | ** '''Why Rust?''' Parses untrusted input. Also, Rust is a great language for writing compilers, due to algebraic data types and pattern matching. | ||
* Audio remoting for Windows: {{bug|1432303}} | * Audio remoting for Windows: {{bug|1432303}} | ||
* Audio remoting for Mac OS: {{bug|1425788}} | * Audio remoting for Mac OS: {{bug|1425788}} | ||
* SDP parsing in WebRTC: {{bug|1365792}} | * SDP parsing in WebRTC: {{bug|1365792}} | ||
** '''Why Rust?''' SDP is a complex text protocol and the existing parser in C has a history of security issues. | ** '''Why Rust?''' SDP is a complex text protocol and the existing parser in C has a history of security issues. This also allows us to tailor the SDP parser specifically for the subset used in WebRTC, further reducing its surface area. It is currently run in parallel with the C parser in Nightly. | ||
* Linebreaking with xi-unicode: {{bug|1290022}} (last update late 2016) | * Linebreaking with xi-unicode: {{bug|1290022}} (last update late 2016) | ||
* Background Update Agent for Windows: {{bug|1343669}} | * Background Update Agent for Windows: {{bug|1343669}} | ||
* [https://github.com/gfx-rs/wgpu wgpu], a [https://gpuweb.github.io/gpuweb/ WebGPU] API implementation: {{bug|webgpu-mvp}} (in Nightly since 72) | * [https://github.com/gfx-rs/wgpu wgpu], a [https://gpuweb.github.io/gpuweb/ WebGPU] API implementation: {{bug|webgpu-mvp}} (in Nightly since 72) | ||
** '''Why Rust?''' Complex tracking logic, wide attack area. Also, leverages Rust ecosystem for building libraries on top of our native implementation and the API that will target the Web. | ** '''Why Rust?''' Complex tracking logic, wide attack area. Also, leverages Rust ecosystem for building libraries on top of our native implementation and the API that will target the Web. | ||
* Integrate the [https://github.com/mozilla/glean/ Glean SDK], a data collection library. | |||
=== Proposed === | === Proposed === | ||
Line 182: | Line 181: | ||
** '''Why Rust?''' Single safe and performant implementation which is shared across all our products. | ** '''Why Rust?''' Single safe and performant implementation which is shared across all our products. | ||
* libcubeb Audio backend for Windows (WASAPI) | * libcubeb Audio backend for Windows (WASAPI) | ||
* Replace the XML parser, possibly via c2rust: {{bug|1611289}} | |||
** '''Why Rust?''' Parses untrusted input, replaces expat, a 3rd-party library with a history of frequent security vulnerabilities. | |||
* Rewrite the ICE stack used by WebRTC; {{bug|1616966}} | |||
** '''Why Rust?''' Works with network data. | |||
== Outside Firefox == | == Outside Firefox == | ||
Line 204: | Line 207: | ||
* Application Services, client-side | * Application Services, client-side | ||
** [https://github.com/mozilla/application-services/tree/master/components various sync-related components used on iOS and Fenix], includes a cross-compiled FxA Rust client, and storage/syncing of bookmarks, history, logins, tabs and webextensions data. | ** [https://github.com/mozilla/application-services/tree/master/components various sync-related components used on iOS and Fenix], includes a cross-compiled FxA Rust client, and storage/syncing of bookmarks, history, logins, tabs and webextensions data. | ||
* [https://github.com/mozilla/fix-stacks/ fix-stacks], a stack frame symbolizer: {{bug|1596292}} | |||
** '''Why Rust?''' High performance needed, a single implementation can replace multiple platform-specific scripts, and we can use the [https://github.com/getsentry/symbolic/ symbolic] crate to do all the hard parts. | |||
=== In Progress === | === In Progress === | ||
Line 214: | Line 219: | ||
This section lists areas where Rust integration could be improved. | This section lists areas where Rust integration could be improved. | ||
* Tracking bug: Make the developer experience for Firefox + Rust great: {{Bug|rust-great}} | * Tracking bug: Make the developer experience for Firefox + Rust great: {{Bug|rust-great}} | ||
* | * [https://docs.google.com/document/d/16FgQPRxNb-Z6sfJy_P7edXzMVWE86jJEZVbmV0oC-m0/ 2020 Questionnaire results] | ||
* [https://docs.google.com/document/d/1puZvhWaURtViz8OC0HkB0h2dqJThVyAgLGFbIQpd4fo/ Oxidation 2020 Plan] | |||
= Meetings = | = Meetings = | ||
* Berlin, January 2020 (minutes lost due to technical issues, unfortunately) | |||
* [https://github.com/servo/servo/wiki/Whistler-Oxidation-2019 Whistler, Jun 2019] | * [https://github.com/servo/servo/wiki/Whistler-Oxidation-2019 Whistler, Jun 2019] | ||
* [https://github.com/servo/servo/wiki/Orlando-Oxidation-2018 Orlando, Dec 2018] | * [https://github.com/servo/servo/wiki/Orlando-Oxidation-2018 Orlando, Dec 2018] |