@@ -26,6 +26,10 @@ use std::{
2626use anyhow:: Result ;
2727use clap:: Args ;
2828use polkavm_linker:: TARGET_JSON_64_BIT as POLKAVM_TARGET_JSON_64_BIT ;
29+ use rustversion:: {
30+ before,
31+ since,
32+ } ;
2933
3034use crate :: CrateMetadata ;
3135
@@ -147,6 +151,26 @@ pub struct Target;
147151impl 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