aboutsummaryrefslogtreecommitdiff
path: root/lix-doc
diff options
context:
space:
mode:
authorQyriad <qyriad@qyriad.me>2024-08-10 10:59:58 -0600
committerQyriad <qyriad@qyriad.me>2024-08-20 17:21:13 +0000
commit95863b258bde3ec11d9688e35454e523571ac17d (patch)
tree1a2c1a973988a371c20bc315e01709fbac96d8d3 /lix-doc
parentf1533160aaa0b2ecd0bb26d6445808593ecb0726 (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 'lix-doc')
-rw-r--r--lix-doc/meson.build52
-rw-r--r--lix-doc/package.nix8
2 files changed, 52 insertions, 8 deletions
diff --git a/lix-doc/meson.build b/lix-doc/meson.build
new file mode 100644
index 000000000..36a5d8ba4
--- /dev/null
+++ b/lix-doc/meson.build
@@ -0,0 +1,52 @@
+# Until Meson 1.5ยน, we can't just give Meson a Cargo.lock file and be done with it.
+# Meson will *detect* what dependencies are needed from Cargo files; it just won't
+# fetch them. The Meson 1.5 feature essentially internally translates Cargo.lock entries
+# to .wrap files, and that translation is incredibly straightforward, so let's just
+# use a simple Python script to generate the .wrap files ourselves while we wait for
+# Meson 1.5. Weirdly, it seems Meson will only detect dependencies from other
+# dependency() calls, so we have to specify lix-doc's two top-level dependencies,
+# rnix and rowan, manually, and then their dependencies will be recursively translated
+# into more dependency() calls.
+#
+# When Meson translates a Cargo dependency, the string passed to `dependency()` follows
+# a fixed format, which is important as the .wrap files' basenames must match the string
+# passed to `dependency()` exactly.
+# In Meson 1.4, this format is `$packageName-rs`. Meson 1.5 changes this to
+# `$packageName-$shortenedVersionString-rs`, because of course it does, but we'll cross
+# that bridge when we get there...
+#
+# [1]: https://github.com/mesonbuild/meson/commit/9b8378985dbdc0112d11893dd42b33b7bc8d1e62
+
+run_command(
+ python,
+ meson.project_source_root() / 'meson/cargo-lock-to-wraps.py',
+ meson.current_source_dir() / 'Cargo.lock',
+ meson.project_source_root() / 'subprojects',
+ check : true,
+)
+
+# The external crate rowan has an ambiguous pointer comparison warning, which
+# we don't want to fail our whole build if werror is on.
+subproject('rowan-rs', default_options : ['werror=false'])
+
+rnix = dependency('rnix-rs')
+rowan = dependency('rowan-rs')
+
+lix_doc = static_library(
+ 'lix_doc',
+ sources : files('src/lib.rs'),
+ rust_abi : 'c',
+ dependencies : [
+ rowan,
+ rnix,
+ ],
+ # If an installed static library depends on this target, then Meson will force
+ # that to link with `-Wl,--whole-archive`, unless we also install this target.
+ # `-Wl,--whole-archive` can cause some Problems when linking multiple nested
+ # static libraries, so let's just install the damn thing.
+ install : true,
+)
+
+liblix_doc = declare_dependency(
+ link_with : lix_doc,
+)
diff --git a/lix-doc/package.nix b/lix-doc/package.nix
deleted file mode 100644
index d3896e726..000000000
--- a/lix-doc/package.nix
+++ /dev/null
@@ -1,8 +0,0 @@
-{ rustPlatform, lib }:
-
-rustPlatform.buildRustPackage {
- name = "lix-doc";
-
- cargoLock.lockFile = ./Cargo.lock;
- src = lib.cleanSource ./.;
-}