diff options
author | Qyriad <qyriad@qyriad.me> | 2024-08-10 10:59:58 -0600 |
---|---|---|
committer | Qyriad <qyriad@qyriad.me> | 2024-08-20 17:21:13 +0000 |
commit | 95863b258bde3ec11d9688e35454e523571ac17d (patch) | |
tree | 1a2c1a973988a371c20bc315e01709fbac96d8d3 /meson/cargo-lock-to-wraps.py | |
parent | f1533160aaa0b2ecd0bb26d6445808593ecb0726 (diff) |
build: build lix-doc with Meson! 🎉
lix-doc is now built with Meson, with lix-doc's dependencies built as
Meson subprojects, either fetched on demand with .wrap files, or fetched
in advance by Nix with importCargoLock. It even builds statically.
Fixes #256.
Co-authored-by: Lunaphied <lunaphied@lunaphied.me>
Co-authored-by: Jade Lovelace <lix@jade.fyi>
Change-Id: I3a4731ff13278e7117e0316bc0d7169e85f5eb0c
Diffstat (limited to 'meson/cargo-lock-to-wraps.py')
-rwxr-xr-x | meson/cargo-lock-to-wraps.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/meson/cargo-lock-to-wraps.py b/meson/cargo-lock-to-wraps.py new file mode 100755 index 000000000..811d7a219 --- /dev/null +++ b/meson/cargo-lock-to-wraps.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +import argparse +import tomllib +import sys + +DOWNLOAD_URI_FORMAT = 'https://crates.io/api/v1/crates/{crate}/{version}/download' + +WRAP_TEMPLATE = """ +[wrap-file] +method = cargo +directory = {crate}-{version} +source_url = {url} +source_filename = {crate}-{version}.tar.gz +source_hash = {hash} +""".lstrip() + +parser = argparse.ArgumentParser() +parser.add_argument('lockfile', help='path to the Cargo lockfile to generate wraps from') +parser.add_argument('outdir', help="the 'subprojects' directory to write .wrap files to") + +args = parser.parse_args() + +with open(args.lockfile, 'rb') as f: + lock_toml = tomllib.load(f) + +for dependency in lock_toml['package']: + try: + hash = dependency['checksum'] + except KeyError: + # The base package, e.g. lix-doc, won't have a checksum, and conveniently + # the base package is also not something we want a wrap file for. + # Doesn't that work out nicely? + continue + + crate = dependency['name'] + version = dependency['version'] + + url = DOWNLOAD_URI_FORMAT.format(crate=crate, version=version) + + wrap_text = WRAP_TEMPLATE.format(crate=crate, version=version, url=url, hash=hash) + with open(f'{args.outdir}/{crate}-rs.wrap', 'w') as f: + f.write(wrap_text) |