| 1 | Stylo |
| 2 | ===== |
| 3 | |
| 4 | **High-Performance CSS Style Engine** |
| 5 | |
| 6 | [](https://github.com/servo/stylo/actions) |
| 7 | [](https://crates.io/crates/stylo) |
| 8 | [](https://docs.rs/stylo) |
| 9 |  |
| 10 | |
| 11 | Stylo is a high-performance, browser-grade CSS style engine written in Rust that powers [Servo](https://servo.org) and [Firefox](https://firefox.com). This repo contains Servo’s downstream version of Stylo. The upstream version lives in mozilla-central with the rest of the Gecko/Firefox codebase. |
| 12 | |
| 13 | Coordination of Stylo development happens: |
| 14 | |
| 15 | - Here in Github Issues |
| 16 | - In the [#stylo](https://servo.zulipchat.com/#narrow/channel/417109-stylo) channel of the [Servo Zulip](https://servo.zulipchat.com/) |
| 17 | - In the [#layout](https://chat.mozilla.org/#/room/#layout:mozilla.org) room of the Mozilla Matrix instance (matrix.mozilla.org) |
| 18 | |
| 19 | ## High-Level Documentation |
| 20 | |
| 21 | - This [Mozilla Hacks article](https://hacks.mozilla.org/2017/08/inside-a-super-fast-css-engine-quantum-css-aka-stylo) contains a high-level overview of the Stylo architecture. |
| 22 | - There is a [chapter](https://book.servo.org/architecture/style.html) in the Servo Book (although it is a little out of date). |
| 23 | |
| 24 | ## Branches |
| 25 | |
| 26 | The branches are as follows: |
| 27 | |
| 28 | - [**upstream**](https://github.com/servo/style/tree/upstream) has upstream [mozilla-central](https://searchfox.org/mozilla-central/source/servo) filtered to the paths we care about ([style.paths](style.paths)), but is otherwise unmodified. |
| 29 | - [**main**](https://github.com/servo/style/tree/ci) adds our downstream patches, plus the scripts and workflows for syncing with mozilla-central on top of **upstream**. |
| 30 | |
| 31 | > [!WARNING] |
| 32 | > This repo syncs from upstream by creating a new branch and then rebasing our changes on top of it. This means that `git pull` will not work across syncs (you will need to use `git fetch`, `git reset` and `git rebase`). |
| 33 | |
| 34 | More information on the syncing process is available in [SYNCING.md](SYNCING.md) |
| 35 | |
| 36 | ## Crates |
| 37 | |
| 38 | A guide to the crates contained within this repo |
| 39 | |
| 40 | ### Stylo Crates |
| 41 | |
| 42 | These crates are largely implementation details of Stylo, although you may need to use some of them directly if you use Stylo. |
| 43 | |
| 44 | | Directory | Crate | Notes | |
| 45 | | --- | --- | --- | |
| 46 | | style | [](https://crates.io/crates/stylo) | The main Stylo crate containing the entire CSS engine | |
| 47 | | style_traits | [](https://crates.io/crates/stylo_traits) | Types and traits which allow other code to interoperate with Stylo without depending on the main crate directly. | |
| 48 | | stylo_dom | [](https://crates.io/crates/stylo_dom) | Similar to stylo_traits (but much smaller) | |
| 49 | | stylo_atoms | [](https://crates.io/crates/stylo_atoms) | [Atoms](https://docs.rs/string_cache/latest/string_cache/struct.Atom.html) for CSS and HTML event related strings | |
| 50 | | stylo_config | [](https://crates.io/crates/stylo_config) | Configuration for Stylo. Can be used to set runtime preferences (enabling/disabling properties, etc) | |
| 51 | | stylo_static_prefs | [](https://crates.io/crates/stylo_static_prefs) | Static configuration for Stylo. Config be overridden by patching in a replacement crate. | |
| 52 | | style_derive | [](https://crates.io/crates/stylo_derive) | Internal derive macro for stylo crate | |
| 53 | |
| 54 | ### Standalone Crates |
| 55 | |
| 56 | These crates form part of Stylo but are also be useful standalone. |
| 57 | |
| 58 | | Directory | Crate | Notes | |
| 59 | | --- | --- | --- | |
| 60 | | selectors | [](https://crates.io/crates/selectors) | CSS Selector matching | |
| 61 | | servo_arc | [](https://crates.io/crates/servo_arc) | A variant on `std::Arc` | |
| 62 | |
| 63 | You may also be interested in the `cssparser` crate which lives in the [servo/rust-cssparser](https://github.com/servo/rust-cssparser) repo. |
| 64 | |
| 65 | ### Support Crates |
| 66 | |
| 67 | Low-level crates which could technically be used standalone but are unlikely to be generally useful in practice. |
| 68 | |
| 69 | | Directory | Crate | Notes | |
| 70 | | --- | --- | --- | |
| 71 | | malloc_size_of | [](https://crates.io/crates/stylo_malloc_size_of) | Heap size measurement for Stylo values | |
| 72 | | to_shmem | [](https://crates.io/crates/to_shmem) | Internal utility crate for sharing memory across processes. | |
| 73 | | to_shmem_derive | [](https://crates.io/crates/to_shmem_derive) | Internal derive macro for to_shmem crate | |
| 74 | |
| 75 | ## Building Servo Against a Local Copy of Stylo |
| 76 | |
| 77 | Assuming your local `servo` and `stylo` directories are siblings, you can build `servo` against `stylo` by adding the following to `servo/Cargo.toml`: |
| 78 | |
| 79 | ```toml |
| 80 | [patch."https://github.com/servo/stylo"] |
| 81 | selectors = { path = "../stylo/selectors" } |
| 82 | servo_arc = { path = "../stylo/servo_arc" } |
| 83 | stylo_atoms = { path = "../stylo/stylo_atoms" } |
| 84 | stylo = { path = "../stylo/style" } |
| 85 | stylo_config = { path = "../stylo/stylo_config" } |
| 86 | stylo_dom = { path = "../stylo/stylo_dom" } |
| 87 | stylo_malloc_size_of = { path = "../stylo/malloc_size_of" } |
| 88 | stylo_traits = { path = "../stylo/style_traits" } |
| 89 | ``` |
| 90 | |
| 91 | ## Releases |
| 92 | |
| 93 | Releases are made every time this repository rebases its changes on top of the latest version of upstream Stylo. There are a lot of crates here. In order to publish them, they must be done in order. One order that works is: |
| 94 | |
| 95 | - selectors |
| 96 | - stylo_static_prefs |
| 97 | - stylo_config |
| 98 | - stylo_atoms |
| 99 | - stylo_malloc_size_of |
| 100 | - stylo_dom |
| 101 | - stylo_derive |
| 102 | - stylo_traits |
| 103 | - stylo |
| 104 | |
| 105 | ## License |
| 106 | |
| 107 | Stylo is licensed under MPL 2.0 |