File tree Expand file tree Collapse file tree 6 files changed +25
-7
lines changed Expand file tree Collapse file tree 6 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,9 @@ pub struct CargoConfig {
56
56
57
57
/// Runs cargo check on launch to figure out the correct values of OUT_DIR
58
58
pub load_out_dirs_from_check : bool ,
59
+
60
+ /// rustc target
61
+ pub target : Option < String > ,
59
62
}
60
63
61
64
impl Default for CargoConfig {
@@ -65,6 +68,7 @@ impl Default for CargoConfig {
65
68
all_features : true ,
66
69
features : Vec :: new ( ) ,
67
70
load_out_dirs_from_check : false ,
71
+ target : None ,
68
72
}
69
73
}
70
74
}
@@ -160,6 +164,9 @@ impl CargoWorkspace {
160
164
if let Some ( parent) = cargo_toml. parent ( ) {
161
165
meta. current_dir ( parent) ;
162
166
}
167
+ if let Some ( target) = cargo_features. target . as_ref ( ) {
168
+ meta. other_options ( & [ String :: from ( "--filter-platform" ) , target. clone ( ) ] ) ;
169
+ }
163
170
let meta = meta. exec ( ) . with_context ( || {
164
171
format ! ( "Failed to run `cargo metadata --manifest-path {}`" , cargo_toml. display( ) )
165
172
} ) ?;
Original file line number Diff line number Diff line change @@ -543,7 +543,7 @@ impl ProjectWorkspace {
543
543
}
544
544
}
545
545
546
- pub fn get_rustc_cfg_options ( ) -> CfgOptions {
546
+ pub fn get_rustc_cfg_options ( target : Option < & String > ) -> CfgOptions {
547
547
let mut cfg_options = CfgOptions :: default ( ) ;
548
548
549
549
// Some nightly-only cfgs, which are required for stdlib
@@ -558,10 +558,12 @@ pub fn get_rustc_cfg_options() -> CfgOptions {
558
558
559
559
match ( || -> Result < String > {
560
560
// `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here.
561
- let output = Command :: new ( "rustc" )
562
- . args ( & [ "--print" , "cfg" , "-O" ] )
563
- . output ( )
564
- . context ( "Failed to get output from rustc --print cfg -O" ) ?;
561
+ let mut cmd = Command :: new ( "rustc" ) ;
562
+ cmd. args ( & [ "--print" , "cfg" , "-O" ] ) ;
563
+ if let Some ( target) = target {
564
+ cmd. args ( & [ "--target" , target. as_str ( ) ] ) ;
565
+ }
566
+ let output = cmd. output ( ) . context ( "Failed to get output from rustc --print cfg -O" ) ?;
565
567
if !output. status . success ( ) {
566
568
bail ! (
567
569
"rustc --print cfg -O exited with exit code ({})" ,
Original file line number Diff line number Diff line change @@ -149,7 +149,7 @@ pub(crate) fn load(
149
149
150
150
// FIXME: cfg options?
151
151
let default_cfg_options = {
152
- let mut opts = get_rustc_cfg_options ( ) ;
152
+ let mut opts = get_rustc_cfg_options ( None ) ;
153
153
opts. insert_atom ( "test" . into ( ) ) ;
154
154
opts. insert_atom ( "debug_assertion" . into ( ) ) ;
155
155
opts
Original file line number Diff line number Diff line change @@ -131,6 +131,7 @@ impl Config {
131
131
set ( value, "/cargo/allFeatures" , & mut self . cargo . all_features ) ;
132
132
set ( value, "/cargo/features" , & mut self . cargo . features ) ;
133
133
set ( value, "/cargo/loadOutDirsFromCheck" , & mut self . cargo . load_out_dirs_from_check ) ;
134
+ set ( value, "/cargo/target" , & mut self . cargo . target ) ;
134
135
135
136
match get ( value, "/procMacro/enable" ) {
136
137
Some ( true ) => {
Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ impl WorldState {
131
131
132
132
// FIXME: Read default cfgs from config
133
133
let default_cfg_options = {
134
- let mut opts = get_rustc_cfg_options ( ) ;
134
+ let mut opts = get_rustc_cfg_options ( config . cargo . target . as_ref ( ) ) ;
135
135
opts. insert_atom ( "test" . into ( ) ) ;
136
136
opts. insert_atom ( "debug_assertion" . into ( ) ) ;
137
137
opts
Original file line number Diff line number Diff line change 233
233
"default" : false ,
234
234
"markdownDescription" : " Run `cargo check` on startup to get the correct value for package OUT_DIRs"
235
235
},
236
+ "rust-analyzer.cargo.target" : {
237
+ "type" : [
238
+ " null" ,
239
+ " string"
240
+ ],
241
+ "default" : null ,
242
+ "description" : " Specify the compilation target"
243
+ },
236
244
"rust-analyzer.rustfmt.extraArgs" : {
237
245
"type" : " array" ,
238
246
"items" : {
You can’t perform that action at this time.
0 commit comments