1
1
import { CommandWithResult } from "./command.mjs" ;
2
- import { commands , workspace } from "vscode" ;
2
+ import { commands , type Uri , window , workspace } from "vscode" ;
3
3
import {
4
4
getPythonPath ,
5
5
getPath ,
6
6
cmakeGetSelectedToolchainAndSDKVersions ,
7
7
cmakeGetPicoVar ,
8
8
} from "../utils/cmakeUtil.mjs" ;
9
9
import { join } from "path" ;
10
+ import { join as joinPosix } from "path/posix" ;
10
11
import {
11
12
buildOpenOCDPath ,
12
13
buildPicotoolPath ,
14
+ buildSDKPath ,
13
15
buildToolchainPath ,
14
16
downloadAndInstallOpenOCD ,
15
17
downloadAndInstallPicotool ,
@@ -19,6 +21,11 @@ import which from "which";
19
21
import { execSync } from "child_process" ;
20
22
import { getPicotoolReleases } from "../utils/githubREST.mjs" ;
21
23
import { openOCDVersion } from "../webview/newProjectPanel.mjs" ;
24
+ import State from "../state.mjs" ;
25
+ import VersionBundlesLoader from "../utils/versionBundles.mjs" ;
26
+ import { getSupportedToolchains } from "../utils/toolchainUtil.mjs" ;
27
+ import Logger from "../logger.mjs" ;
28
+ import { rustProjectGetSelectedChip } from "../utils/rustUtil.mjs" ;
22
29
23
30
export class GetPythonPathCommand extends CommandWithResult < string > {
24
31
constructor ( ) {
@@ -59,7 +66,7 @@ export class GetEnvPathCommand extends CommandWithResult<string> {
59
66
}
60
67
61
68
export class GetGDBPathCommand extends CommandWithResult < string > {
62
- constructor ( ) {
69
+ constructor ( private readonly _extensionUri : Uri ) {
63
70
super ( "getGDBPath" ) ;
64
71
}
65
72
@@ -72,13 +79,48 @@ export class GetGDBPathCommand extends CommandWithResult<string> {
72
79
}
73
80
74
81
const workspaceFolder = workspace . workspaceFolders ?. [ 0 ] ;
82
+ const isRustProject = State . getInstance ( ) . isRustProject ;
83
+ let toolchainVersion = "" ;
75
84
76
- const selectedToolchainAndSDKVersions =
77
- await cmakeGetSelectedToolchainAndSDKVersions ( workspaceFolder . uri ) ;
78
- if ( selectedToolchainAndSDKVersions === null ) {
79
- return "" ;
85
+ if ( isRustProject ) {
86
+ // check if latest toolchain is installed
87
+ const vbl = new VersionBundlesLoader ( this . _extensionUri ) ;
88
+ const latestVb = await vbl . getLatest ( ) ;
89
+
90
+ if ( ! latestVb ) {
91
+ void window . showErrorMessage ( "No version bundles found." ) ;
92
+
93
+ return "" ;
94
+ }
95
+
96
+ const supportedToolchains = await getSupportedToolchains ( ) ;
97
+ const latestSupportedToolchain = supportedToolchains . find (
98
+ t => t . version === latestVb . toolchain
99
+ ) ;
100
+ if ( ! latestSupportedToolchain ) {
101
+ void window . showErrorMessage (
102
+ "No supported toolchain found for the latest version."
103
+ ) ;
104
+
105
+ return "" ;
106
+ }
107
+
108
+ const useRISCV = rustProjectGetSelectedChip (
109
+ workspaceFolder . uri . fsPath
110
+ ) ?. includes ( "riscv" ) ;
111
+
112
+ toolchainVersion = useRISCV
113
+ ? latestVb . riscvToolchain
114
+ : latestVb . toolchain ;
115
+ } else {
116
+ const selectedToolchainAndSDKVersions =
117
+ await cmakeGetSelectedToolchainAndSDKVersions ( workspaceFolder . uri ) ;
118
+ if ( selectedToolchainAndSDKVersions === null ) {
119
+ return "" ;
120
+ }
121
+
122
+ toolchainVersion = selectedToolchainAndSDKVersions [ 1 ] ;
80
123
}
81
- const toolchainVersion = selectedToolchainAndSDKVersions [ 1 ] ;
82
124
83
125
let triple = "arm-none-eabi" ;
84
126
if ( toolchainVersion . includes ( "RISCV" ) ) {
@@ -154,6 +196,8 @@ export class GetCompilerPathCommand extends CommandWithResult<string> {
154
196
}
155
197
156
198
export class GetChipCommand extends CommandWithResult < string > {
199
+ private readonly _logger = new Logger ( "GetChipCommand" ) ;
200
+
157
201
constructor ( ) {
158
202
super ( "getChip" ) ;
159
203
}
@@ -167,6 +211,19 @@ export class GetChipCommand extends CommandWithResult<string> {
167
211
}
168
212
169
213
const workspaceFolder = workspace . workspaceFolders ?. [ 0 ] ;
214
+ const isRustProject = State . getInstance ( ) . isRustProject ;
215
+
216
+ if ( isRustProject ) {
217
+ // read .pico-rs
218
+ const chip = rustProjectGetSelectedChip ( workspaceFolder . uri . fsPath ) ;
219
+ if ( chip === null ) {
220
+ this . _logger . error ( "Failed to read .pico-rs" ) ;
221
+
222
+ return "" ;
223
+ }
224
+
225
+ return chip ;
226
+ }
170
227
171
228
const settings = Settings . getInstance ( ) ;
172
229
let buildDir = join ( workspaceFolder . uri . fsPath , "build" ) ;
@@ -227,6 +284,13 @@ export class GetTargetCommand extends CommandWithResult<string> {
227
284
}
228
285
229
286
const workspaceFolder = workspace . workspaceFolders ?. [ 0 ] ;
287
+ const isRustProject = State . getInstance ( ) . isRustProject ;
288
+
289
+ if ( isRustProject ) {
290
+ const chip = rustProjectGetSelectedChip ( workspaceFolder . uri . fsPath ) ;
291
+
292
+ return chip === null ? "rp2040" : chip . toLowerCase ( ) ;
293
+ }
230
294
231
295
const settings = Settings . getInstance ( ) ;
232
296
let buildDir = join ( workspaceFolder . uri . fsPath , "build" ) ;
@@ -343,3 +407,50 @@ export class GetOpenOCDRootCommand extends CommandWithResult<
343
407
return buildOpenOCDPath ( openOCDVersion ) ;
344
408
}
345
409
}
410
+
411
+ /**
412
+ * Currently rust only!
413
+ */
414
+ export class GetSVDPathCommand extends CommandWithResult < string | undefined > {
415
+ public static readonly id = "getSVDPath" ;
416
+
417
+ constructor ( private readonly _extensionUri : Uri ) {
418
+ super ( GetSVDPathCommand . id ) ;
419
+ }
420
+
421
+ async execute ( ) : Promise < string | undefined > {
422
+ if (
423
+ workspace . workspaceFolders === undefined ||
424
+ workspace . workspaceFolders . length === 0
425
+ ) {
426
+ return "" ;
427
+ }
428
+
429
+ const isRustProject = State . getInstance ( ) . isRustProject ;
430
+ if ( ! isRustProject ) {
431
+ return ;
432
+ }
433
+
434
+ const vs = new VersionBundlesLoader ( this . _extensionUri ) ;
435
+ const latestSDK = await vs . getLatestSDK ( ) ;
436
+ if ( ! latestSDK ) {
437
+ return ;
438
+ }
439
+
440
+ const chip = rustProjectGetSelectedChip (
441
+ workspace . workspaceFolders [ 0 ] . uri . fsPath
442
+ ) ;
443
+
444
+ if ( ! chip ) {
445
+ return ;
446
+ }
447
+
448
+ return joinPosix (
449
+ buildSDKPath ( latestSDK ) ,
450
+ "src" ,
451
+ chip ,
452
+ "hardware_regs" ,
453
+ `${ chip . toUpperCase ( ) } .svd`
454
+ ) ;
455
+ }
456
+ }
0 commit comments