From 5616042a51ddfa5ab5ac248f94938a46a273d2a4 Mon Sep 17 00:00:00 2001 From: Aleksana Date: Tue, 26 Mar 2024 04:45:19 +0800 Subject: [PATCH] doc: add build rust package with meson example (#298881) --- doc/languages-frameworks/rust.section.md | 60 ++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 75e57a8bb574..274ee9ce9cc4 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -651,6 +651,66 @@ buildPythonPackage rec { } ``` +#### Rust package built with `meson` {#rust-package-built-with-meson} + +Some projects, especially GNOME applications, are built with the Meson Build System instead of calling Cargo directly. Using `rustPlatform.buildRustPackage` may successfully build the main program, but related files will be missing. Instead, you need to set up Cargo dependencies with `fetchCargoTarball` and `cargoSetupHook` and leave the rest to Meson. `rust` and `cargo` are still needed in `nativeBuildInputs` for Meson to use. + +```nix +{ lib +, stdenv +, fetchFromGitLab +, meson +, ninja +, pkg-config +, rustPlatform +, rustc +, cargo +, wrapGAppsHook4 +, blueprint-compiler +, libadwaita +, libsecret +, tracker +}: + +stdenv.mkDerivation rec { + pname = "health"; + version = "0.95.0"; + + src = fetchFromGitLab { + domain = "gitlab.gnome.org"; + owner = "World"; + repo = "health"; + rev = version; + hash = "sha256-PrNPprSS98yN8b8yw2G6hzTSaoE65VbsM3q7FVB4mds="; + }; + + cargoDeps = rustPlatform.fetchCargoTarball { + inherit src; + name = "${pname}-${version}"; + hash = "sha256-8fa3fa+sFi5H+49B5sr2vYPkp9C9s6CcE0zv4xB8gww="; + }; + + nativeBuildInputs = [ + meson + ninja + pkg-config + rustPlatform.cargoSetupHook + rustc + cargo + wrapGAppsHook4 + blueprint-compiler + ]; + + buildInputs = [ + libadwaita + libsecret + tracker + ]; + + # ... +} +``` + ## `buildRustCrate`: Compiling Rust crates using Nix instead of Cargo {#compiling-rust-crates-using-nix-instead-of-cargo} ### Simple operation {#simple-operation}