From 760ebff16408c803ed4848c3355e78d20f9e092b Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 11 Sep 2025 21:25:32 +0200 Subject: [PATCH 1/2] Handle Rust >= 1.91 change to `target-pointer-width` JSON type https://github.com/rust-lang/rust/pull/144443 --- Cargo.lock | 1 + crates/build/Cargo.toml | 1 + crates/build/src/args.rs | 27 +++++++++++++++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 11749731a..c30cf2617 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1869,6 +1869,7 @@ dependencies = [ "pretty_assertions", "regex", "rustc_version 0.4.1", + "rustversion", "semver 1.0.26", "serde", "serde_json", diff --git a/crates/build/Cargo.toml b/crates/build/Cargo.toml index 05dddcaed..13db0a023 100644 --- a/crates/build/Cargo.toml +++ b/crates/build/Cargo.toml @@ -46,6 +46,7 @@ itertools = "0.14.0" alloy-json-abi = "1.3.1" polkavm-linker = { git = "https://github.com/paritytech/polkavm.git" } +rustversion = "1" contract-metadata = { version = "6.0.0-alpha.3", path = "../metadata" } ink_metadata = { workspace = true } diff --git a/crates/build/src/args.rs b/crates/build/src/args.rs index 13fa38f7e..97a784579 100644 --- a/crates/build/src/args.rs +++ b/crates/build/src/args.rs @@ -26,6 +26,10 @@ use std::{ use anyhow::Result; use clap::Args; use polkavm_linker::TARGET_JSON_64_BIT as POLKAVM_TARGET_JSON_64_BIT; +use rustversion::{ + before, + since, +}; use crate::CrateMetadata; @@ -147,6 +151,26 @@ pub struct Target; impl Target { /// The target string to be passed to rustc in order to build for this target. pub fn llvm_target(crate_metadata: &CrateMetadata) -> String { + // With Rust 1.91, the `target-pointer-width` field became an Integer + // instead of a String. Depending on the toolchain this crate is compiled + // with, we transform the value in the PolkaVM JSON into the correct format. + // + // See for more details. + #[since(1.91)] + fn target_spec() -> String { + POLKAVM_TARGET_JSON_64_BIT.to_string().replace( + r#"target-pointer-width": "64""#, + r#"target-pointer-width": 64"#, + ) + } + #[before(1.91)] + fn target_spec() -> String { + POLKAVM_TARGET_JSON_64_BIT.to_string().replace( + r#"target-pointer-width": 64"#, + r#"target-pointer-width": "64""#, + ) + } + // Instead of a target literal we use a JSON file with a more complex // target configuration here. The path to the file is passed for the // `rustc --target` argument. We write this file to the `target/` folder. @@ -157,8 +181,7 @@ impl Target { panic!("unable to create target dir {target_dir:?}: {e:?}") }); let mut file = File::create(&path).unwrap(); - file.write_all(POLKAVM_TARGET_JSON_64_BIT.as_bytes()) - .unwrap(); + file.write_all(target_spec().as_bytes()).unwrap(); } path } From 56e3a826370dde0eda62d5bfbdbead754dd23a35 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 11 Sep 2025 21:32:08 +0200 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b45729df..51d72f038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [Unreleased] +### Changed +- Handle Rust >= 1.91 change of `target-pointer-width` JSON type ‒ [2131](https://github.com/use-ink/cargo-contract/pull/2131) + ## [6.0.0-alpha.3] Compatibility of this release: