diff options
author | Vika <vika@fireburn.ru> | 2024-09-01 18:10:26 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2024-09-04 19:51:50 +0300 |
commit | f8d61d957d4a2d086f4b97f2e3d7d19d0bb35f13 (patch) | |
tree | 740988c295d5e3c53b93bd09bad0ce73211b2f40 /default.nix | |
parent | 7718901fb8346a75bd203f04e4303d0df007dcd1 (diff) | |
download | bowl-f8d61d957d4a2d086f4b97f2e3d7d19d0bb35f13.tar.zst |
Mesonify build
This took a while and had me scratching my head often. But I managed to combine the best parts of Crane and Meson together, allowing me to have blazing fast Nix builds. This also adds initial scaffolding for gettext and other cool things.
Diffstat (limited to 'default.nix')
-rw-r--r-- | default.nix | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/default.nix b/default.nix index e4d4f7e..c79ba7c 100644 --- a/default.nix +++ b/default.nix @@ -1,11 +1,12 @@ -{ craneLib, lib -, pkg-config, wrapGAppsHook -, gtk4, libadwaita, libpanel, libsoup_3, libsecret, librsvg, gettext +{ craneLib, lib, rustc +, pkg-config, wrapGAppsHook, meson, ninja, gettext +, desktop-file-utils +, gtk4, libadwaita, libpanel, libsoup_3, libsecret, librsvg }: let src = let - suffixes = []; + suffixes = [ "meson.options" "meson.build" ".sh" ".po" ".pot" ".in" ]; suffixFilter = name: type: let base = baseNameOf (toString name); in type == "directory" || lib.any (ext: lib.hasSuffix ext base) suffixes; @@ -30,7 +31,7 @@ let # cargoExtraArgs can be used to inject features buildInputs = [ gtk4 libadwaita libpanel libsoup_3 libsecret librsvg gettext ]; - nativeBuildInputs = [ pkg-config wrapGAppsHook gettext ]; + nativeBuildInputs = [ pkg-config wrapGAppsHook gettext meson ninja ]; meta = with lib.meta; { maintainers = with lib.maintainers; [ vikanezrimaya ]; @@ -42,7 +43,35 @@ let cargoArtifacts = craneLib.buildDepsOnly args; args' = args // { inherit cargoArtifacts; }; -in craneLib.buildPackage (args' // { +in craneLib.mkCargoDerivation (args' // { + # This is the magic sauce to integrate Crane and Meson builds + # (see `src/meson.build` for details on how we call Cargo) + + # Use source replacement so we can use the crane vendor tarball + postConfigure = '' + mkdir -p cargo-home + cp $CARGO_HOME/config.toml cargo-home/config.toml + ''; + # Move intermediate artefacts from Cargo to the Meson build folder + preBuild = '' + mv ../target/release src/release + ''; + # Use standard Meson and Ninja build phases + configurePhase = "mesonConfigurePhase"; + buildPhase = "ninjaBuildPhase"; + buildPhaseCargoCommand = "# unused"; + checkPhase = "mesonCheckPhase"; + installPhase = "mesonInstallPhase"; + + nativeBuildInputs = args'.nativeBuildInputs ++ [ + rustc # Only needed for Meson to successfully detect the Rust toolchain + + # Auxiliary packages + desktop-file-utils + ]; + + doInstallCargoArtifacts = false; + passthru = { inherit src cargoArtifacts; clippy = craneLib.cargoClippy args'; |