diff mbox series

[v2,01/14] rust: patch bilge-impl to allow compilation with 1.63.0

Message ID 20241022100956.196657-2-pbonzini@redhat.com (mailing list archive)
State New
Headers show
Series rust: allow older versions of rustc and bindgen | expand

Commit Message

Paolo Bonzini Oct. 22, 2024, 10:09 a.m. UTC
Apply a patch that removes "let ... else" constructs, replacing them with
"if let ... else" or "let ... = match ...".  "let ... else" was stabilized in
Rust 1.65.0.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 .gitattributes                                |  2 +
 subprojects/bilge-impl-0.2-rs.wrap            |  1 +
 subprojects/packagefiles/.gitattributes       |  1 +
 .../packagefiles/bilge-impl-1.63.0.patch      | 45 +++++++++++++++++++
 4 files changed, 49 insertions(+)
 create mode 100644 subprojects/packagefiles/.gitattributes
 create mode 100644 subprojects/packagefiles/bilge-impl-1.63.0.patch

Comments

Junjie Mao Oct. 24, 2024, 2:12 a.m. UTC | #1
Paolo Bonzini <pbonzini@redhat.com> writes:

> Apply a patch that removes "let ... else" constructs, replacing them with
> "if let ... else" or "let ... = match ...".  "let ... else" was stabilized in
> Rust 1.65.0.
>
> Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Junjie Mao <junjie.mao@hotmail.com>

One question and one note below.

> ---
>  .gitattributes                                |  2 +
>  subprojects/bilge-impl-0.2-rs.wrap            |  1 +
>  subprojects/packagefiles/.gitattributes       |  1 +
>  .../packagefiles/bilge-impl-1.63.0.patch      | 45 +++++++++++++++++++
>  4 files changed, 49 insertions(+)
>  create mode 100644 subprojects/packagefiles/.gitattributes
>  create mode 100644 subprojects/packagefiles/bilge-impl-1.63.0.patch
>
> diff --git a/.gitattributes b/.gitattributes
> index 6dc6383d3d1..9ce7a19581a 100644
> --- a/.gitattributes
> +++ b/.gitattributes
> @@ -5,3 +5,5 @@
>  *.rs            diff=rust
>  *.rs.inc        diff=rust
>  Cargo.lock      diff=toml merge=binary
> +
> +*.patch         -text -whitespace
<snip>
> diff --git a/subprojects/packagefiles/.gitattributes b/subprojects/packagefiles/.gitattributes
> new file mode 100644
> index 00000000000..bf5b766d75d
> --- /dev/null
> +++ b/subprojects/packagefiles/.gitattributes
> @@ -0,0 +1 @@
> +/*.patch     -text

Do we really need unsetting the attrs for *.patch in both .gitattributes
and subprojects/packagefiles/.gitattributes? Is that related to the
different setting of -whitespace?

> diff --git a/subprojects/packagefiles/bilge-impl-1.63.0.patch b/subprojects/packagefiles/bilge-impl-1.63.0.patch
> new file mode 100644
> index 00000000000..987428a6d65
> --- /dev/null
> +++ b/subprojects/packagefiles/bilge-impl-1.63.0.patch
> @@ -0,0 +1,45 @@
> +--- a/src/shared/discriminant_assigner.rs
> ++++ b/src/shared/discriminant_assigner.rs

Just a note: when fetching this series using b4 am, I still get this
patch with LF line ending. Later when merging one may need to fetch this
specific commit directly from the git repository.

--
Best Regards
Junjie Mao
Alex Bennée Oct. 24, 2024, 10:43 a.m. UTC | #2
Paolo Bonzini <pbonzini@redhat.com> writes:

> Apply a patch that removes "let ... else" constructs, replacing them with
> "if let ... else" or "let ... = match ...".  "let ... else" was stabilized in
> Rust 1.65.0.
>
> Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

My configure on a clean build dir blows up with:

  bilge-0.2-rs| Downloading bilge-impl-0.2-rs source from https://crates.io/api/v1/crates/bilge-impl/0.2.0/download
  Downloading: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 23.9k/23.9k 5.30MB/s eta 00:00
  bilge-0.2-rs| Applying diff file "bilge-impl-1.63.0.patch"
  bilge-0.2-rs| patching file src/shared/discriminant_assigner.rs
  bilge-0.2-rs| Hunk #1 FAILED at 26 (different line endings).
  bilge-0.2-rs| 1 out of 1 hunk FAILED -- saving rejects to file src/shared/discriminant_assigner.rs.rej
  bilge-0.2-rs| patching file src/shared/fallback.rs
  bilge-0.2-rs| Hunk #1 FAILED at 22 (different line endings).
  bilge-0.2-rs| 1 out of 1 hunk FAILED -- saving rejects to file src/shared/fallback.rs.rej

  ../../subprojects/bilge-0.2.0/meson.build:9:0: ERROR: Failed to apply diff file "bilge-impl-1.63.0.patch"

  A full log can be found at /home/alex/lsrc/qemu.git/builds/rust/meson-logs/meson-log.txt

  ERROR: meson setup failed

So do I have some hidden state somewhere?
diff mbox series

Patch

diff --git a/.gitattributes b/.gitattributes
index 6dc6383d3d1..9ce7a19581a 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -5,3 +5,5 @@ 
 *.rs            diff=rust
 *.rs.inc        diff=rust
 Cargo.lock      diff=toml merge=binary
+
+*.patch         -text -whitespace
diff --git a/subprojects/bilge-impl-0.2-rs.wrap b/subprojects/bilge-impl-0.2-rs.wrap
index eefb10c36c2..b24c34a9043 100644
--- a/subprojects/bilge-impl-0.2-rs.wrap
+++ b/subprojects/bilge-impl-0.2-rs.wrap
@@ -5,3 +5,4 @@  source_filename = bilge-impl-0.2.0.tar.gz
 source_hash = feb11e002038ad243af39c2068c8a72bcf147acf05025dcdb916fcc000adb2d8
 #method = cargo
 patch_directory = bilge-impl-0.2-rs
+diff_files = bilge-impl-1.63.0.patch
diff --git a/subprojects/packagefiles/.gitattributes b/subprojects/packagefiles/.gitattributes
new file mode 100644
index 00000000000..bf5b766d75d
--- /dev/null
+++ b/subprojects/packagefiles/.gitattributes
@@ -0,0 +1 @@ 
+/*.patch     -text
diff --git a/subprojects/packagefiles/bilge-impl-1.63.0.patch b/subprojects/packagefiles/bilge-impl-1.63.0.patch
new file mode 100644
index 00000000000..987428a6d65
--- /dev/null
+++ b/subprojects/packagefiles/bilge-impl-1.63.0.patch
@@ -0,0 +1,45 @@ 
+--- a/src/shared/discriminant_assigner.rs
++++ b/src/shared/discriminant_assigner.rs
+@@ -26,20 +26,20 @@
+         let discriminant_expr = &discriminant.1;
+         let variant_name = &variant.ident;
+ 
+-        let Expr::Lit(ExprLit { lit: Lit::Int(int), .. }) = discriminant_expr else {
++        if let Expr::Lit(ExprLit { lit: Lit::Int(int), .. }) = discriminant_expr {
++            let discriminant_value: u128 = int.base10_parse().unwrap_or_else(unreachable);
++            if discriminant_value > self.max_value() {
++                abort!(variant, "Value of variant exceeds the given number of bits")
++            }
++
++            Some(discriminant_value)
++        } else {
+             abort!(
+                 discriminant_expr,
+                 "variant `{}` is not a number", variant_name;
+                 help = "only literal integers currently supported"
+             )
+-        };
+-
+-        let discriminant_value: u128 = int.base10_parse().unwrap_or_else(unreachable);
+-        if discriminant_value > self.max_value() {
+-            abort!(variant, "Value of variant exceeds the given number of bits")
+         }
+-
+-        Some(discriminant_value)
+     }
+ 
+     fn assign(&mut self, variant: &Variant) -> u128 {
+--- a/src/shared/fallback.rs
++++ b/src/shared/fallback.rs
+@@ -22,8 +22,9 @@
+             }
+             Unnamed(fields) => {
+                 let variant_fields = fields.unnamed.iter();
+-                let Ok(fallback_value) = variant_fields.exactly_one() else {
+-                    abort!(variant, "fallback variant must have exactly one field"; help = "use only one field or change to a unit variant")
++                let fallback_value = match variant_fields.exactly_one() {
++                    Ok(ok) => ok,
++                    _ => abort!(variant, "fallback variant must have exactly one field"; help = "use only one field or change to a unit variant")
+                 };
+ 
+                 if !is_last_variant {