@@ -4,14 +4,17 @@ import { INSTALL_DIR, EXPORTS_FILE_PATH } from './constants'
44import upsert from '../patching/upsert'
55import { installDeps as installMacDeps } from './zephyr/mac'
66import { installDeps as installLinuxDeps } from './zephyr/linux'
7+ import { installDeps as installWinDeps } from './zephyr/windows'
78import { moddableExists } from './moddable'
89import { sourceEnvironment } from '../system/exec'
910import { failure , successVoid , isFailure } from '../system/errors'
1011import type { SetupResult } from '../../types'
1112import { detectPython } from '../system/python'
13+ import { ensureModdableCommandPrompt , setEnv } from './windows'
1214
1315export default async function ( ) : Promise < SetupResult > {
1416 const OS = platformType ( ) . toLowerCase ( )
17+ const isWindows = OS === 'windows_nt'
1518 const ZEPHYR_ROOT =
1619 process . env . ZEPHYR_ROOT ?? filesystem . resolve ( INSTALL_DIR , 'zephyrproject' )
1720 const ZEPHYR_BASE =
@@ -31,6 +34,11 @@ export default async function(): Promise<SetupResult> {
3134 )
3235 return failure ( 'Moddable platform tooling required. Run `xs-dev setup` before trying again.' )
3336 }
37+
38+ if ( isWindows ) {
39+ const result = await ensureModdableCommandPrompt ( spinner )
40+ if ( isFailure ( result ) ) return result
41+ }
3442 spinner . info ( 'Ensuring zephyr directory' )
3543 filesystem . dir ( ZEPHYR_ROOT )
3644
@@ -45,6 +53,11 @@ export default async function(): Promise<SetupResult> {
4553 const result = await installLinuxDeps ( spinner )
4654 if ( isFailure ( result ) ) return result
4755 }
56+ if ( isWindows ) {
57+ spinner . start ( 'Installing dependencies with winget' )
58+ const result = await installWinDeps ( spinner )
59+ if ( isFailure ( result ) ) return result
60+ }
4861 spinner . succeed ( )
4962
5063 // 2. Create zephyr virtual environment
@@ -60,7 +73,18 @@ export default async function(): Promise<SetupResult> {
6073 spinner . succeed ( )
6174 }
6275 // 3. Activate virtual environment
63- await upsert ( EXPORTS_FILE_PATH , `source ${ ZEPHYR_VENV_ACTIVATE } ` )
76+ if ( isWindows ) {
77+ await upsert (
78+ EXPORTS_FILE_PATH ,
79+ `call "${ ZEPHYR_ROOT } \\.venv\\Scripts\\activate.bat"` ,
80+ )
81+ await system . exec ( `${ ZEPHYR_ROOT } \\.venv\\Scripts\\activate.bat` , {
82+ stdout : process . stdout ,
83+ shell : true ,
84+ } )
85+ } else {
86+ await upsert ( EXPORTS_FILE_PATH , `source ${ ZEPHYR_VENV_ACTIVATE } ` )
87+ }
6488 await sourceEnvironment ( )
6589
6690 // 4. Install West with pip
@@ -86,11 +110,19 @@ export default async function(): Promise<SetupResult> {
86110
87111 // 6. Install west packages
88112 spinner . start ( `Installing west packages` )
89- await system . exec ( `west packages pip --install` , {
90- process,
91- shell : process . env . SHELL ,
92- stdout : process . stdout
93- } )
113+ if ( isWindows ) {
114+ await system . exec ( `cmd /c zephyr\\scripts\\utils\\west-packages-pip-install.cmd` , {
115+ cwd : ZEPHYR_ROOT ,
116+ process,
117+ shell : process . env . SHELL ,
118+ } )
119+ } else {
120+ await system . exec ( `west packages pip --install` , {
121+ process,
122+ shell : process . env . SHELL ,
123+ stdout : process . stdout
124+ } )
125+ }
94126 spinner . succeed ( )
95127
96128 // 7. Install Zephyr SDK
@@ -103,7 +135,11 @@ export default async function(): Promise<SetupResult> {
103135 spinner . succeed ( )
104136
105137 if ( process . env . ZEPHYR_BASE === undefined ) {
106- await upsert ( EXPORTS_FILE_PATH , `export ZEPHYR_BASE=${ ZEPHYR_BASE } ` )
138+ if ( isWindows ) {
139+ await setEnv ( 'ZEPHYR_BASE' , ZEPHYR_BASE )
140+ } else {
141+ await upsert ( EXPORTS_FILE_PATH , `export ZEPHYR_BASE=${ ZEPHYR_BASE } ` )
142+ }
107143 }
108144
109145 print . success ( `
0 commit comments