Skip to content

Commit 758953d

Browse files
authored
Handle Rust >= 1.91 change of target-pointer-width JSON type (#2131)
* Handle Rust >= 1.91 change to `target-pointer-width` JSON type rust-lang/rust#144443 * Update changelog
1 parent 226c0e6 commit 758953d

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
[Unreleased]
88

9+
### Changed
10+
- Handle Rust >= 1.91 change of `target-pointer-width` JSON type ‒ [2131](https://github.com/use-ink/cargo-contract/pull/2131)
11+
912
## [6.0.0-alpha.3]
1013

1114
Compatibility of this release:

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/build/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ itertools = "0.14.0"
4646
alloy-json-abi = "1.3.1"
4747

4848
polkavm-linker = { git = "https://github.com/paritytech/polkavm.git" }
49+
rustversion = "1"
4950

5051
contract-metadata = { version = "6.0.0-alpha.3", path = "../metadata" }
5152
ink_metadata = { workspace = true }

crates/build/src/args.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ use std::{
2626
use anyhow::Result;
2727
use clap::Args;
2828
use polkavm_linker::TARGET_JSON_64_BIT as POLKAVM_TARGET_JSON_64_BIT;
29+
use rustversion::{
30+
before,
31+
since,
32+
};
2933

3034
use crate::CrateMetadata;
3135

@@ -147,6 +151,26 @@ pub struct Target;
147151
impl Target {
148152
/// The target string to be passed to rustc in order to build for this target.
149153
pub fn llvm_target(crate_metadata: &CrateMetadata) -> String {
154+
// With Rust 1.91, the `target-pointer-width` field became an Integer
155+
// instead of a String. Depending on the toolchain this crate is compiled
156+
// with, we transform the value in the PolkaVM JSON into the correct format.
157+
//
158+
// See <https://github.com/rust-lang/rust/pull/144443> for more details.
159+
#[since(1.91)]
160+
fn target_spec() -> String {
161+
POLKAVM_TARGET_JSON_64_BIT.to_string().replace(
162+
r#"target-pointer-width": "64""#,
163+
r#"target-pointer-width": 64"#,
164+
)
165+
}
166+
#[before(1.91)]
167+
fn target_spec() -> String {
168+
POLKAVM_TARGET_JSON_64_BIT.to_string().replace(
169+
r#"target-pointer-width": 64"#,
170+
r#"target-pointer-width": "64""#,
171+
)
172+
}
173+
150174
// Instead of a target literal we use a JSON file with a more complex
151175
// target configuration here. The path to the file is passed for the
152176
// `rustc --target` argument. We write this file to the `target/` folder.
@@ -157,8 +181,7 @@ impl Target {
157181
panic!("unable to create target dir {target_dir:?}: {e:?}")
158182
});
159183
let mut file = File::create(&path).unwrap();
160-
file.write_all(POLKAVM_TARGET_JSON_64_BIT.as_bytes())
161-
.unwrap();
184+
file.write_all(target_spec().as_bytes()).unwrap();
162185
}
163186
path
164187
}

0 commit comments

Comments
 (0)