mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
build(nixos): lay vendored Servo crates out in their repository tree
Servo's crates read files elsewhere in their repository by relative path (the WebIDL parser under third_party/, pages under resources/), which the per-crate vendoring breaks. Before building, move each vendored Servo crate to its place in a copy of the pinned tree and link it back, so cargo sees the same crates and those paths resolve. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QS8QcxvhVJwU3X2qhPamUW
This commit is contained in:
parent
19798976c6
commit
5ea2cfae57
2 changed files with 76 additions and 1 deletions
58
infra/nixos/servo-tree.py
Normal file
58
infra/nixos/servo-tree.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
"""Lay the vendored Servo crates out in their repository tree.
|
||||
|
||||
Nix vendors each git crate into a directory of its own, but Servo's crates
|
||||
read files elsewhere in their repository by relative path: the WebIDL parser
|
||||
under `third_party/`, the pages and lists under `resources/`. This copies
|
||||
those parts of the pinned Servo tree to TREE, moves each vendored Servo
|
||||
crate (with the manifest and checksum file the vendoring wrote) to its place
|
||||
in that tree, and leaves a symlink in the vendor directory, so cargo sees
|
||||
the same crates and their relative paths resolve.
|
||||
|
||||
Usage: servo-tree.py SERVO_SOURCE CARGO_LOCK VENDOR_DIR TREE
|
||||
"""
|
||||
|
||||
import shutil
|
||||
import sys
|
||||
import tomllib
|
||||
from pathlib import Path
|
||||
|
||||
SERVO_GIT = "git+https://github.com/marcoallegretti/servo"
|
||||
# The parts of the tree the crates read; `tests/` alone is most of its size.
|
||||
PARTS = ("components", "resources", "third_party", "Cargo.toml")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
source, lock, vendor, tree = (Path(a) for a in sys.argv[1:])
|
||||
crates = {
|
||||
p["name"]: p["version"]
|
||||
for p in tomllib.loads(lock.read_text())["package"]
|
||||
if p.get("source", "").startswith(SERVO_GIT)
|
||||
}
|
||||
for part in PARTS:
|
||||
src = source / part
|
||||
if src.is_dir():
|
||||
shutil.copytree(src, tree / part, symlinks=True)
|
||||
else:
|
||||
shutil.copy(src, tree / part)
|
||||
tree.chmod(0o755)
|
||||
for path in tree.rglob("*"):
|
||||
if not path.is_symlink():
|
||||
path.chmod(0o755 if path.is_dir() else 0o644)
|
||||
|
||||
homes = {}
|
||||
for manifest in (tree / "components").rglob("Cargo.toml"):
|
||||
name = tomllib.loads(manifest.read_text()).get("package", {}).get("name")
|
||||
if name in crates:
|
||||
homes[name] = manifest.parent
|
||||
missing = crates.keys() - homes.keys()
|
||||
if missing:
|
||||
sys.exit(f"Servo crates not found in {source}: {sorted(missing)}")
|
||||
|
||||
for name, version in crates.items():
|
||||
vendored = vendor / f"{name}-{version}"
|
||||
shutil.copytree(vendored, homes[name], dirs_exist_ok=True)
|
||||
shutil.rmtree(vendored)
|
||||
vendored.symlink_to(homes[name])
|
||||
|
||||
|
||||
main()
|
||||
|
|
@ -15,13 +15,22 @@ let
|
|||
in !(lib.hasPrefix "target" rel || lib.hasSuffix "-result" rel);
|
||||
};
|
||||
|
||||
servoHash = "sha256-L5XlHf5GOoPtyitRsbb+keXSkTMSJWmYCrWCHzGFI5M=";
|
||||
|
||||
# The pinned Servo revision as a whole tree; see servo-tree.py.
|
||||
servoSrc = pkgs.fetchgit {
|
||||
url = "https://github.com/marcoallegretti/servo";
|
||||
rev = "e5d9a518ebddb5ebd6af404d1fd4e00ea0f77163";
|
||||
hash = servoHash;
|
||||
};
|
||||
|
||||
cargoLock = {
|
||||
lockFile = ../../Cargo.lock;
|
||||
# One hash per git source in Cargo.lock: the Servo fork and the Stylo fork
|
||||
# (keyed by its `selectors` crate). Recompute them whenever a revision
|
||||
# changes; a build with a stale hash reports the right one.
|
||||
outputHashes = {
|
||||
"servo-0.0.1" = "sha256-L5XlHf5GOoPtyitRsbb+keXSkTMSJWmYCrWCHzGFI5M=";
|
||||
"servo-0.0.1" = servoHash;
|
||||
"selectors-0.36.0" = "13y6pa19j4w2zsxfhv6mrl03wsa0frazlsssbqkzpwci8k9gzl4i";
|
||||
};
|
||||
};
|
||||
|
|
@ -90,6 +99,14 @@ let
|
|||
WEFT_VERITYSETUP = "${pkgs.cryptsetup}/bin/veritysetup";
|
||||
};
|
||||
|
||||
# Servo's code generator finds its WebIDL parser from its own path
|
||||
# without resolving links, so the tree's third_party/ is also linked
|
||||
# where that path leads from the vendor directory.
|
||||
preBuild = ''
|
||||
python3 ${./servo-tree.py} ${servoSrc} Cargo.lock "$NIX_BUILD_TOP/cargo-vendor-dir" "$NIX_BUILD_TOP/servo"
|
||||
ln -s "$NIX_BUILD_TOP/servo/third_party" "$NIX_BUILD_TOP/third_party"
|
||||
'';
|
||||
|
||||
# The system UI page and the UI kit both shells inject, at the paths the
|
||||
# session's units name.
|
||||
postInstall = ''
|
||||
|
|
|
|||
Loading…
Reference in a new issue