11import { CommandWithResult } from "./command.mjs" ;
2- import { commands , workspace } from "vscode" ;
2+ import { commands , type Uri , window , workspace } from "vscode" ;
33import {
44 getPythonPath ,
55 getPath ,
66 cmakeGetSelectedToolchainAndSDKVersions ,
77 cmakeGetPicoVar ,
88} from "../utils/cmakeUtil.mjs" ;
99import { join } from "path" ;
10+ import { join as joinPosix } from "path/posix" ;
1011import {
1112 buildOpenOCDPath ,
1213 buildPicotoolPath ,
14+ buildSDKPath ,
1315 buildToolchainPath ,
1416 downloadAndInstallOpenOCD ,
1517 downloadAndInstallPicotool ,
@@ -19,6 +21,11 @@ import which from "which";
1921import { execSync } from "child_process" ;
2022import { getPicotoolReleases } from "../utils/githubREST.mjs" ;
2123import { 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" ;
2229
2330export class GetPythonPathCommand extends CommandWithResult < string > {
2431 constructor ( ) {
@@ -59,7 +66,7 @@ export class GetEnvPathCommand extends CommandWithResult<string> {
5966}
6067
6168export class GetGDBPathCommand extends CommandWithResult < string > {
62- constructor ( ) {
69+ constructor ( private readonly _extensionUri : Uri ) {
6370 super ( "getGDBPath" ) ;
6471 }
6572
@@ -72,13 +79,48 @@ export class GetGDBPathCommand extends CommandWithResult<string> {
7279 }
7380
7481 const workspaceFolder = workspace . workspaceFolders ?. [ 0 ] ;
82+ const isRustProject = State . getInstance ( ) . isRustProject ;
83+ let toolchainVersion = "" ;
7584
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 ] ;
80123 }
81- const toolchainVersion = selectedToolchainAndSDKVersions [ 1 ] ;
82124
83125 let triple = "arm-none-eabi" ;
84126 if ( toolchainVersion . includes ( "RISCV" ) ) {
@@ -192,6 +234,8 @@ export class GetCxxCompilerPathCommand extends CommandWithResult<string> {
192234}
193235
194236export class GetChipCommand extends CommandWithResult < string > {
237+ private readonly _logger = new Logger ( "GetChipCommand" ) ;
238+
195239 constructor ( ) {
196240 super ( "getChip" ) ;
197241 }
@@ -205,6 +249,19 @@ export class GetChipCommand extends CommandWithResult<string> {
205249 }
206250
207251 const workspaceFolder = workspace . workspaceFolders ?. [ 0 ] ;
252+ const isRustProject = State . getInstance ( ) . isRustProject ;
253+
254+ if ( isRustProject ) {
255+ // read .pico-rs
256+ const chip = rustProjectGetSelectedChip ( workspaceFolder . uri . fsPath ) ;
257+ if ( chip === null ) {
258+ this . _logger . error ( "Failed to read .pico-rs" ) ;
259+
260+ return "" ;
261+ }
262+
263+ return chip ;
264+ }
208265
209266 const settings = Settings . getInstance ( ) ;
210267 let buildDir = join ( workspaceFolder . uri . fsPath , "build" ) ;
@@ -265,6 +322,13 @@ export class GetTargetCommand extends CommandWithResult<string> {
265322 }
266323
267324 const workspaceFolder = workspace . workspaceFolders ?. [ 0 ] ;
325+ const isRustProject = State . getInstance ( ) . isRustProject ;
326+
327+ if ( isRustProject ) {
328+ const chip = rustProjectGetSelectedChip ( workspaceFolder . uri . fsPath ) ;
329+
330+ return chip === null ? "rp2040" : chip . toLowerCase ( ) ;
331+ }
268332
269333 const settings = Settings . getInstance ( ) ;
270334 let buildDir = join ( workspaceFolder . uri . fsPath , "build" ) ;
@@ -381,3 +445,50 @@ export class GetOpenOCDRootCommand extends CommandWithResult<
381445 return buildOpenOCDPath ( openOCDVersion ) ;
382446 }
383447}
448+
449+ /**
450+ * Currently rust only!
451+ */
452+ export class GetSVDPathCommand extends CommandWithResult < string | undefined > {
453+ public static readonly id = "getSVDPath" ;
454+
455+ constructor ( private readonly _extensionUri : Uri ) {
456+ super ( GetSVDPathCommand . id ) ;
457+ }
458+
459+ async execute ( ) : Promise < string | undefined > {
460+ if (
461+ workspace . workspaceFolders === undefined ||
462+ workspace . workspaceFolders . length === 0
463+ ) {
464+ return "" ;
465+ }
466+
467+ const isRustProject = State . getInstance ( ) . isRustProject ;
468+ if ( ! isRustProject ) {
469+ return ;
470+ }
471+
472+ const vs = new VersionBundlesLoader ( this . _extensionUri ) ;
473+ const latestSDK = await vs . getLatestSDK ( ) ;
474+ if ( ! latestSDK ) {
475+ return ;
476+ }
477+
478+ const chip = rustProjectGetSelectedChip (
479+ workspace . workspaceFolders [ 0 ] . uri . fsPath
480+ ) ;
481+
482+ if ( ! chip ) {
483+ return ;
484+ }
485+
486+ return joinPosix (
487+ buildSDKPath ( latestSDK ) ,
488+ "src" ,
489+ chip ,
490+ "hardware_regs" ,
491+ `${ chip . toUpperCase ( ) } .svd`
492+ ) ;
493+ }
494+ }
0 commit comments