Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate predefined counter styles (allows atoms crate to be published) #99

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI

on:
push:
branches: ["main"]
pull_request:
workflow_dispatch:
merge_group:
types: [checks_requested]


jobs:
linux-debug:
name: Linux (Debug)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Run Tests
run: cargo build --features servo
env:
RUST_BACKTRACE: 1

linux-release:
name: Linux (Release)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Run Tests
run: cargo build --release --features servo
env:
RUST_BACKTRACE: 1

build-result:
name: Result
runs-on: ubuntu-latest
if: ${{ always() }}
needs:
- linux-debug
- linux-release
steps:
- name: Success
if: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
run: exit 0
- name: Failure
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: exit 1

26 changes: 26 additions & 0 deletions .github/workflows/mirror-to-release-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: 🪞 Mirror `main`
on:
push:
branches:
- main

jobs:
mirror:
name: Mirror
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get branch name
id: branch-name
run: |
first_commit=$(git log --pretty=\%H --grep='Servo initial downstream commit')
upstream_base="$first_commit~"
echo BRANCH_NAME=$(git log -n1 --pretty='%as' $upstream_base) >> $GITHUB_OUTPUT
- uses: google/[email protected]
name: Mirror to ${{ steps.branch-name.outputs.BRANCH_NAME }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
source: main
dest: ${{ steps.branch-name.outputs.BRANCH_NAME }}
23 changes: 23 additions & 0 deletions .github/workflows/sync-upstream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Sync upstream with mozilla-central

on:
schedule:
- cron: '0 13 * * *'
workflow_dispatch:

jobs:
sync:
name: Sync
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- uses: actions/cache@v3
with:
path: _cache/upstream
key: upstream
- run: |
./sync.sh _filtered
git fetch -f --progress ./_filtered master:upstream
git push -fu --progress origin upstream
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/_cache/
/_filtered/
/target/
/style/properties/__pycache__/
Cargo.lock
16 changes: 16 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[workspace]
resolver = "2"
members = [
"dom",
"malloc_size_of",
"rustfmt.toml",
"selectors",
"servo_arc",
"style",
"style_derive",
"style_static_prefs",
"style_traits",
"to_shmem",
"to_shmem_derive",
]
default-members = ["style"]
88 changes: 88 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Stylo
=====

This repo contains Servo’s downstream fork of [Stylo](https://searchfox.org/mozilla-central/source/servo).

The branches are as follows:

- [`upstream`](https://github.com/servo/style/tree/upstream) has upstream mozilla-central filtered to the paths we care about ([style.paths](style.paths)), but is otherwise unmodified
- [`main`](https://github.com/servo/style/tree/ci) has our downstream patches, plus the scripts and workflows for syncing with mozilla-central, to be rebased onto `upstream`

## Building Servo against your local Stylo

Assuming your local `servo` and `stylo` directories are siblings, you can build `servo` against `stylo` by adding the following to `servo/Cargo.toml`:

```toml
[patch."https://github.com/servo/stylo.git"]
derive_common = { path = "../stylo/derive_common" }
malloc_size_of = { path = "../stylo/malloc_size_of" }
selectors = { path = "../stylo/selectors" }
servo_arc = { path = "../stylo/servo_arc" }
servo_atoms = { path = "../stylo/atoms" }
size_of_test = { path = "../stylo/size_of_test" }
static_prefs = { path = "../stylo/style_static_prefs" }
style_config = { path = "../stylo/style_config" }
style_derive = { path = "../stylo/style_derive" }
style = { path = "../stylo/style" }
style_traits = { path = "../stylo/style_traits" }
```

## Syncing `upstream` with mozilla-central

Start by generating a filtered copy of mozilla-central. This will cache the raw mozilla-central in `_cache/upstream`, storing the result in `_filtered`:

```sh
$ ./sync.sh _filtered
```

If `_filtered` already exists, you will need to delete it and try again:

```sh
$ rm -Rf _filtered
```

Now overwrite our `upstream` with those commits and push:

```sh
$ git fetch -f --progress ./_filtered master:upstream
$ git push -fu --progress origin upstream
```

## Rebasing `main` onto `upstream`

Start by fetching `upstream` into your local repo:

```sh
$ git fetch -f origin upstream:upstream
```

In general, the filtering process is deterministic, yielding the same commit hashes each time, so we can rebase normally:

```sh
$ git rebase upstream
```

But if the filtering config changes or Mozilla moves to GitHub, the commit hashes on `upstream` may change. In this case, we need to tell git where the old upstream ends and our own commits start (notice the `~`):

```sh
$ git log --pretty=\%H --grep='Servo initial downstream commit'
e62d7f0090941496e392e1dc91df103a38e3f488

$ git rebase --onto upstream e62d7f0090941496e392e1dc91df103a38e3f488~
Successfully rebased and updated refs/heads/main.
```

`start-rebase.sh` takes care of this automatically, but you should still use `git rebase` for subsequent steps like `--continue` and `--abort`:

```sh
$ ./start-rebase.sh upstream
$ ./start-rebase.sh upstream -i # interactive
$ git rebase --continue # not ./start-rebase.sh --continue
$ git rebase --abort # not ./start-rebase.sh --abort
```

Or if we aren’t ready to rebase onto the tip of upstream:

```sh
$ ./start-rebase.sh upstream~10 -i
```
17 changes: 17 additions & 0 deletions atoms/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "servo_atoms"
version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
edition = "2018"
publish = false
build = "build.rs"

[lib]
path = "lib.rs"

[dependencies]
string_cache = "0.8"

[build-dependencies]
string_cache_codegen = "0.5"
31 changes: 31 additions & 0 deletions atoms/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* 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 std::env;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;

fn main() {
let static_atoms =
Path::new(&env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("static_atoms.txt");
let static_atoms = BufReader::new(File::open(&static_atoms).unwrap());
let mut atom_type = string_cache_codegen::AtomType::new("Atom", "atom!");

macro_rules! predefined {
($($name: expr,)+) => {
{
$(
atom_type.atom($name);
)+
}
}
}
include!("./predefined_counter_styles.rs");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better way to do this would probably be to have the import script duplicate this file into the atoms directory.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did think about that but this directory doesn't exist at import time either (at least not when calling git filter-repo) because it's not upstream. I suppose we could add a post rebase step to sync and squash this file? But that seems like it might be quite fragile?


atom_type
.atoms(static_atoms.lines().map(Result::unwrap))
.write_to_file(&Path::new(&env::var_os("OUT_DIR").unwrap()).join("atom.rs"))
.unwrap();
}
5 changes: 5 additions & 0 deletions atoms/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* 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/. */

include!(concat!(env!("OUT_DIR"), "/atom.rs"));
66 changes: 66 additions & 0 deletions atoms/predefined_counter_styles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* 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/. */

// THIS FILE IS DUPLICATED FROM style/counter_style/predefined.rs.
// TO UPDATE IT:
// - Run `python style/counter_style/updated_predefined.py`
// - Re-copy style/counter_style/predefined.rs to this location

predefined! {
"decimal",
"decimal-leading-zero",
"arabic-indic",
"armenian",
"upper-armenian",
"lower-armenian",
"bengali",
"cambodian",
"khmer",
"cjk-decimal",
"devanagari",
"georgian",
"gujarati",
"gurmukhi",
"hebrew",
"kannada",
"lao",
"malayalam",
"mongolian",
"myanmar",
"oriya",
"persian",
"lower-roman",
"upper-roman",
"tamil",
"telugu",
"thai",
"tibetan",
"lower-alpha",
"lower-latin",
"upper-alpha",
"upper-latin",
"cjk-earthly-branch",
"cjk-heavenly-stem",
"lower-greek",
"hiragana",
"hiragana-iroha",
"katakana",
"katakana-iroha",
"disc",
"circle",
"square",
"disclosure-open",
"disclosure-closed",
"japanese-informal",
"japanese-formal",
"korean-hangul-formal",
"korean-hanja-informal",
"korean-hanja-formal",
"simp-chinese-informal",
"simp-chinese-formal",
"trad-chinese-informal",
"trad-chinese-formal",
"cjk-ideographic",
"ethiopic-numeric",
}
Loading
Loading