summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurilo <murilo@disroot.org>2026-01-23 10:52:50 -0300
committerGabriel Wicki <gabriel@erlikon.ch>2026-04-23 14:33:58 +0200
commite9e6165d07dfef44b0b12ef027198219f074ae12 (patch)
tree08f0dbc43d631644554c9e9931167933273d149d
parent4dcde1182537a568855a8f9a7d068ac88557aa4d (diff)
doc: Add new workflow for resolving merge conflicts on rust apps PRs.
* doc/guix-cookbook.texi (Packaging Workflows)[Packaging Rust Crates] {Common Workflow for Updating Existing Rust Packages}: Add new workflow. Change-Id: I191d35790754b2fab4c27b794829959f1bf58d06 Signed-off-by: Gabriel Wicki <gabriel@erlikon.ch>
-rw-r--r--doc/guix-cookbook.texi217
1 files changed, 217 insertions, 0 deletions
diff --git a/doc/guix-cookbook.texi b/doc/guix-cookbook.texi
index 7a28b640fdb..09a49a1c9a8 100644
--- a/doc/guix-cookbook.texi
+++ b/doc/guix-cookbook.texi
@@ -146,6 +146,7 @@ Packaging Rust Crates
146* Common Workflow for Rust Packaging:: 146* Common Workflow for Rust Packaging::
147* Cargo Workspaces and Development Snapshots:: 147* Cargo Workspaces and Development Snapshots::
148* Using Rust Libraries in Other Build Systems:: 148* Using Rust Libraries in Other Build Systems::
149* Common Workflow for Updating Existing Rust Packages::
149* Common Workflow for Resolving Merge Conflicts on Existing Pull Requests:: 150* Common Workflow for Resolving Merge Conflicts on Existing Pull Requests::
150 151
151System Configuration 152System Configuration
@@ -1648,6 +1649,7 @@ $ guix shell rust rust:cargo cargo-audit cargo-license
1648* Common Workflow for Rust Packaging:: 1649* Common Workflow for Rust Packaging::
1649* Cargo Workspaces and Development Snapshots:: 1650* Cargo Workspaces and Development Snapshots::
1650* Using Rust Libraries in Other Build Systems:: 1651* Using Rust Libraries in Other Build Systems::
1652* Common Workflow for Updating Existing Rust Packages::
1651* Common Workflow for Resolving Merge Conflicts on Existing Pull Requests:: 1653* Common Workflow for Resolving Merge Conflicts on Existing Pull Requests::
1652@end menu 1654@end menu
1653 1655
@@ -1989,6 +1991,221 @@ method, one of the most popular choices for Traditional Chinese users.")
1989 (license license:lgpl2.1+))) 1991 (license license:lgpl2.1+)))
1990@end lisp 1992@end lisp
1991 1993
1994@node Common Workflow for Updating Existing Rust Packages
1995@subsubsection Common Workflow for Updating Existing Rust Packages
1996
1997For this example, we'll update @code{niri}. The package definition looks like
1998this initially:
1999
2000@lisp
2001(define-public niri
2002 (package
2003 (name "niri")
2004 (version "25.08")
2005 (source (origin
2006 (method git-fetch)
2007 (uri (git-reference
2008 (url "https://github.com/YaLTeR/niri")
2009 (commit (string-append "v" version))))
2010 (file-name (git-file-name name version))
2011 (sha256
2012 (base32
2013 "09nsxd211mly8r1ys2lq6ia4jxgb980h1axrbgw748r0knfbbj7n"))))
2014 (build-system cargo-build-system)
2015...
2016@end lisp
2017
2018We start by running the usual @command{guix refresh -u niri}.
2019
2020The @command{-u} flag will update in place the version and hash for the
2021@code{niri} package.
2022
2023The package definition will then look like this:
2024
2025@lisp
2026(define-public niri
2027 (package
2028 (name "niri")
2029 (version "25.11")
2030 (source (origin
2031 (method git-fetch)
2032 (uri (git-reference
2033 (url "https://github.com/YaLTeR/niri")
2034 (commit (string-append "v" version))))
2035 (file-name (git-file-name name version))
2036 (sha256
2037 (base32
2038 "0752qm245wc2gak0jhp0fnr0rdj3z54m2h97k3cxbjym9pcn658n"))))
2039 (build-system cargo-build-system)
2040...
2041@end lisp
2042
2043This means the source field was updated successfully, thus we can now proceed to
2044get the updated source with @command{guix build --source niri} as follows:
2045
2046@example shell
2047$ cp -r $(./pre-inst-env guix build --source niri) /tmp
2048$ cd /tmp/<hash>-niri-25.11-checkout/
2049@end example
2050
2051@quotation Note
2052In this specific example, the source is a git checkout, thus a directory. If the
2053package source is a compressed archive, you would at this point extract it to a
2054directory to proceed.
2055@end quotation
2056
2057Now, given that we have access to the @code{Cargo.toml} file, we can now run
2058the following inside the checkout:
2059
2060@example shell
2061$ guix shell rust rust:cargo -- cargo generate-lockfile
2062$ guix shell rust rust:cargo -- cargo audit
2063$ guix shell rust rust:cargo -- cargo license
2064@end example
2065
2066@quotation Note
2067Sometimes the package will require a more up-to-date version of rust, that is
2068not yet the default rust on guix. For these cases you can use:
2069@example shell
2070$ guix shell -e "(@ (gnu packages rust) rust-1.90)" \
2071 -e '`(,(@ (gnu packages rust) rust-1.90) "cargo")'
2072@end example
2073@end quotation
2074
2075The first command will ensure that all cargo dependencies are up to date
2076and semver compatible, while also providing some other benefits, as further
2077explained in @ref{Common Workflow for Rust Packaging}.
2078
2079The following command will warn if there are any known vulnerabilities in the
2080crates being imported. The last one will output the license information of all
2081the dependent crates.
2082
2083If everything looks good, we can now replace the contents of the @code{niri}
2084indentifier, located inside the @code{lookup-cargo-inputs} variable on the
2085bottom of the @file{gnu/packages/rust-crates.scm} module, with the newer updated
2086crates by running the importer on the lockfile as follows:
2087
2088@example shell
2089$ guix import -i /path/to/gnu/packages/rust-crates.scm \
2090 crate -f Cargo.lock niri
2091@end example
2092
2093@quotation Note
2094For the purpose of contributing a package to Guix (@pxref{Contributing,,,
2095guix, GNU Guix Reference Manual}), there is no need to cleanup the leftover
2096crates as a result of the package update. This is tasked to the rust-team
2097(@pxref{Teams,,, guix, GNU Guix Reference Manual}) to periodically run a
2098convenient script in @code{etc/teams/rust} to cleanup unused crates from
2099@file{gnu/packages/rust-crates.scm}.
2100@end quotation
2101
2102We then need to check whether the importer has placed some TODOs for us,
2103inside @file{gnu/packages/rust-crates.scm} (you can use @command{git diff --
2104gnu/packages/rust-crates.scm} for this purpose).
2105
2106There are a few types of TODO messages that you might encounter during this
2107step, each type requiring you to perform a different action.
2108
2109The first one we encounter in our example is:
2110
2111@lisp
2112(define rust-libdisplay-info-sys-0.3.0
2113 ;; TODO REVIEW: Check bundled sources.
2114 (crate-source "libdisplay-info-sys" "0.3.0"
2115 "07xmkc2aqcdn6d58321y87rd3gzdr4nx3ncm1mmrr7w1p1ahsn96"))
2116@end lisp
2117
2118This specific TODO message tells us that there is a high probability of
2119encountering bundled sources within a crate definition generated by the
2120importer.
2121
2122We then check if there are any bundled sources within the
2123@code{rust-libdisplay-info-sys-0.3.0} crate. Since there are none (in our
2124example), we can simply remove the TODO line, and continue to the next TODO.
2125
2126If there were any bundled sources inside the crate, we would have to patch
2127it with a snippet, in order to unbundle it. You can see some examples on
2128how to unbundle inside @file{gnu/packages/rust-crates.scm} (search for the
2129@code{#:snippet} keyword).
2130
2131@quotation Note
2132If the unbundle is considered too difficult to be executed (e.g. the effort
2133needed to unbundle is unreasonable), the @code{TODO REVIEW} line should be
2134converted to a regular TODO comment explicitly stating the unbundle was not done
2135(e.g. @code{TODO: Unbundle rust-libdisplay-info-sys.}).
2136@end quotation
2137
2138Continuing, another TODO message we encounter in this example is the following:
2139
2140@lisp
2141(define rust-smithay-0.7.0.d743e1a
2142 ;; TODO REVIEW: Define standalone package if this is a workspace.
2143 (origin
2144 (method git-fetch)
2145 (uri (git-reference (url "https://github.com/Smithay/smithay.git")
2146 (commit "d743e1a317fa0f01d1c4cadd96d277a1ec7b59d9")))
2147 (file-name (git-file-name "rust-smithay" "0.7.0.d743e1a"))
2148 (sha256 (base32 "11327mhxxf844bs0v5bw1g9bzjssnzhidsissywy6kwng16x727v"))))
2149@end lisp
2150
2151This specific TODO message tells us that there is a high probability of the
2152@code{rust-smithay-0.7.0.d743e1a} crate being a workspace.
2153
2154After verifying that it is indeed a workspace, we now need to make it an
2155actual package in @file{gnu/packages/rust-sources.scm}, referencing it in the
2156crate-source definition (see @ref{Common Workflow for Rust Packaging} for more
2157details).
2158
2159@quotation Note
2160You can verify if a crate is a workspace by cloning the crate repository (in
2161this case @code{https://github.com/Smithay/smithay.git}), checking out the
2162specific revision (in this case @command{git checkout d743e1a}), and looking
2163for @code{[workspace]} in its main @file{Cargo.toml} file. If it does not have a
2164TOML @code{[workspace]} section, then it is not a workspace.
2165@end quotation
2166
2167After defining the separate source package for the workspace in
2168@file{gnu/packages/rust-sources.scm} (see @ref{Common Workflow for Rust
2169Packaging} for more details on how to do this), the crate definition for
2170@code{rust-smithay-0.7.0.d743e1a} would then become the following (notice we
2171also remove the TODO line):
2172
2173@lisp
2174(define rust-smithay-0.7.0.d743e1a package:rust-smithay-0.7.0.d743e1a)
2175@end lisp
2176
2177If @code{rust-smithay-0.7.0.d743e1a} was not a workspace, we would simply remove
2178the TODO line and move on.
2179
2180We then try to build the package with @command{guix build niri}, and make sure
2181whether it builds successfully, which it does.
2182
2183As a good practice, we can further check the output of the
2184@code{check-for-pregenerated-files} phase to ensure there are no extraneous
2185pregenerated files inside the crates. If there are any, it is important to
2186snippet them out, like these:
2187
2188@lisp
2189(define rust-winapi-x86-64-pc-windows-gnu-0.4.0
2190 (crate-source "winapi-x86_64-pc-windows-gnu" "0.4.0"
2191 "0gqq64czqb64kskjryj8isp62m2sgvx25yyj3kpc2myh85w24bki"
2192 #:snippet '(delete-file-recursively "lib")))
2193
2194(define rust-flate2-1.1.4
2195 (crate-source "flate2" "1.1.4"
2196 "1a8a3pk2r2dxays4ikc47ygydhpd1dcxlgqdi3r9kiiq9rb4wnnw"
2197 #:snippet '(for-each delete-file-recursively '("examples" "tests"))))
2198
2199(define rust-flo-curves-0.3.1
2200 (crate-source "flo_curves" "0.3.1"
2201 "16x293dp8825jh465kgms4yyvl4960j26gh37h3skflq9zxpy8hw"
2202 #:snippet '(for-each delete-file '("logo-small.png" "logo.png"))))
2203
2204(define rust-interception-sys-0.1.3
2205 (crate-source "interception-sys" "0.1.3"
2206 "1lgwbml7gzq5a5rriy708w68gx6yiw9cdg7xy2c5vsrrck7pbs5b"
2207 #:snippet '(for-each delete-file (find-files "." "\\.(dll|lib)$"))))
2208@end lisp
1992 2209
1993@node Common Workflow for Resolving Merge Conflicts on Existing Pull Requests 2210@node Common Workflow for Resolving Merge Conflicts on Existing Pull Requests
1994@subsubsection Common Workflow for Resolving Merge Conflicts on Existing Pull Requests 2211@subsubsection Common Workflow for Resolving Merge Conflicts on Existing Pull Requests