diff options
| author | Murilo <murilo@disroot.org> | 2026-01-23 10:52:50 -0300 |
|---|---|---|
| committer | Gabriel Wicki <gabriel@erlikon.ch> | 2026-04-23 14:33:58 +0200 |
| commit | e9e6165d07dfef44b0b12ef027198219f074ae12 (patch) | |
| tree | 08f0dbc43d631644554c9e9931167933273d149d /doc | |
| parent | 4dcde1182537a568855a8f9a7d068ac88557aa4d (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>
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/guix-cookbook.texi | 217 |
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 | ||
| 151 | System Configuration | 152 | System 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 | |||
| 1997 | For this example, we'll update @code{niri}. The package definition looks like | ||
| 1998 | this 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 | |||
| 2018 | We start by running the usual @command{guix refresh -u niri}. | ||
| 2019 | |||
| 2020 | The @command{-u} flag will update in place the version and hash for the | ||
| 2021 | @code{niri} package. | ||
| 2022 | |||
| 2023 | The 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 | |||
| 2043 | This means the source field was updated successfully, thus we can now proceed to | ||
| 2044 | get 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 | ||
| 2052 | In this specific example, the source is a git checkout, thus a directory. If the | ||
| 2053 | package source is a compressed archive, you would at this point extract it to a | ||
| 2054 | directory to proceed. | ||
| 2055 | @end quotation | ||
| 2056 | |||
| 2057 | Now, given that we have access to the @code{Cargo.toml} file, we can now run | ||
| 2058 | the 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 | ||
| 2067 | Sometimes the package will require a more up-to-date version of rust, that is | ||
| 2068 | not 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 | |||
| 2075 | The first command will ensure that all cargo dependencies are up to date | ||
| 2076 | and semver compatible, while also providing some other benefits, as further | ||
| 2077 | explained in @ref{Common Workflow for Rust Packaging}. | ||
| 2078 | |||
| 2079 | The following command will warn if there are any known vulnerabilities in the | ||
| 2080 | crates being imported. The last one will output the license information of all | ||
| 2081 | the dependent crates. | ||
| 2082 | |||
| 2083 | If everything looks good, we can now replace the contents of the @code{niri} | ||
| 2084 | indentifier, located inside the @code{lookup-cargo-inputs} variable on the | ||
| 2085 | bottom of the @file{gnu/packages/rust-crates.scm} module, with the newer updated | ||
| 2086 | crates 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 | ||
| 2094 | For the purpose of contributing a package to Guix (@pxref{Contributing,,, | ||
| 2095 | guix, GNU Guix Reference Manual}), there is no need to cleanup the leftover | ||
| 2096 | crates 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 | ||
| 2098 | convenient script in @code{etc/teams/rust} to cleanup unused crates from | ||
| 2099 | @file{gnu/packages/rust-crates.scm}. | ||
| 2100 | @end quotation | ||
| 2101 | |||
| 2102 | We then need to check whether the importer has placed some TODOs for us, | ||
| 2103 | inside @file{gnu/packages/rust-crates.scm} (you can use @command{git diff -- | ||
| 2104 | gnu/packages/rust-crates.scm} for this purpose). | ||
| 2105 | |||
| 2106 | There are a few types of TODO messages that you might encounter during this | ||
| 2107 | step, each type requiring you to perform a different action. | ||
| 2108 | |||
| 2109 | The 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 | |||
| 2118 | This specific TODO message tells us that there is a high probability of | ||
| 2119 | encountering bundled sources within a crate definition generated by the | ||
| 2120 | importer. | ||
| 2121 | |||
| 2122 | We 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 | ||
| 2124 | example), we can simply remove the TODO line, and continue to the next TODO. | ||
| 2125 | |||
| 2126 | If there were any bundled sources inside the crate, we would have to patch | ||
| 2127 | it with a snippet, in order to unbundle it. You can see some examples on | ||
| 2128 | how to unbundle inside @file{gnu/packages/rust-crates.scm} (search for the | ||
| 2129 | @code{#:snippet} keyword). | ||
| 2130 | |||
| 2131 | @quotation Note | ||
| 2132 | If the unbundle is considered too difficult to be executed (e.g. the effort | ||
| 2133 | needed to unbundle is unreasonable), the @code{TODO REVIEW} line should be | ||
| 2134 | converted 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 | |||
| 2138 | Continuing, 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 | |||
| 2151 | This 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 | |||
| 2154 | After verifying that it is indeed a workspace, we now need to make it an | ||
| 2155 | actual package in @file{gnu/packages/rust-sources.scm}, referencing it in the | ||
| 2156 | crate-source definition (see @ref{Common Workflow for Rust Packaging} for more | ||
| 2157 | details). | ||
| 2158 | |||
| 2159 | @quotation Note | ||
| 2160 | You can verify if a crate is a workspace by cloning the crate repository (in | ||
| 2161 | this case @code{https://github.com/Smithay/smithay.git}), checking out the | ||
| 2162 | specific revision (in this case @command{git checkout d743e1a}), and looking | ||
| 2163 | for @code{[workspace]} in its main @file{Cargo.toml} file. If it does not have a | ||
| 2164 | TOML @code{[workspace]} section, then it is not a workspace. | ||
| 2165 | @end quotation | ||
| 2166 | |||
| 2167 | After defining the separate source package for the workspace in | ||
| 2168 | @file{gnu/packages/rust-sources.scm} (see @ref{Common Workflow for Rust | ||
| 2169 | Packaging} 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 | ||
| 2171 | also 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 | |||
| 2177 | If @code{rust-smithay-0.7.0.d743e1a} was not a workspace, we would simply remove | ||
| 2178 | the TODO line and move on. | ||
| 2179 | |||
| 2180 | We then try to build the package with @command{guix build niri}, and make sure | ||
| 2181 | whether it builds successfully, which it does. | ||
| 2182 | |||
| 2183 | As a good practice, we can further check the output of the | ||
| 2184 | @code{check-for-pregenerated-files} phase to ensure there are no extraneous | ||
| 2185 | pregenerated files inside the crates. If there are any, it is important to | ||
| 2186 | snippet 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 |
