Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
27 changes: 25 additions & 2 deletions crates/build/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 <https://github.com/rust-lang/rust/pull/144443> 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.
Expand All @@ -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
}
Expand Down
Loading