@@ -26,6 +26,10 @@ use std::{
26
26
use anyhow:: Result ;
27
27
use clap:: Args ;
28
28
use polkavm_linker:: TARGET_JSON_64_BIT as POLKAVM_TARGET_JSON_64_BIT ;
29
+ use rustversion:: {
30
+ before,
31
+ since,
32
+ } ;
29
33
30
34
use crate :: CrateMetadata ;
31
35
@@ -147,6 +151,26 @@ pub struct Target;
147
151
impl Target {
148
152
/// The target string to be passed to rustc in order to build for this target.
149
153
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
+
150
174
// Instead of a target literal we use a JSON file with a more complex
151
175
// target configuration here. The path to the file is passed for the
152
176
// `rustc --target` argument. We write this file to the `target/` folder.
@@ -157,8 +181,7 @@ impl Target {
157
181
panic ! ( "unable to create target dir {target_dir:?}: {e:?}" )
158
182
} ) ;
159
183
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 ( ) ;
162
185
}
163
186
path
164
187
}
0 commit comments