Skip to content

Commit 9511816

Browse files
Feature/windows gnu toolchain (#123)
* add support for Windows GNU toolchain Co-authored-by: Sergio Gasquez Arcos <[email protected]>
1 parent 20d712f commit 9511816

File tree

8 files changed

+112
-24
lines changed

8 files changed

+112
-24
lines changed

Install-RustToolchain.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
param (
33
[Parameter()]
44
[String]
5+
[ValidateSet("x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu")]
6+
$DefaultHost = "x86_64-pc-windows-msvc",
7+
[String]
58
$ExportFile = '',
69
[String]
710
$ToolchainVersion = '1.62.1.0',
@@ -22,14 +25,15 @@ $ExportContent = ""
2225
$RustcMinimalMinorVersion="55"
2326

2427
"Processing configuration:"
28+
"-DefaultHost = ${DefaultHost}"
2529
"-InstalltationMode = ${InstallationMode}"
2630
"-LlvmVersion = ${LlvmVersion}"
2731
"-ToolchainVersion = ${ToolchainVersion}"
2832
"-ToolchainDestination = ${ToolchainDestination}"
2933

3034
function InstallRust() {
3135
Invoke-WebRequest https://win.rustup.rs/x86_64 -OutFile rustup-init.exe
32-
./rustup-init.exe --default-toolchain stable -y
36+
./rustup-init.exe --default-host ${DefaultHost} --default-toolchain stable -y
3337
$env:PATH+=";$env:USERPROFILE\.cargo\bin"
3438
$ExportContent+="`n" + '$env:PATH+=";$env:USERPROFILE\.cargo\bin"'
3539
}
@@ -83,7 +87,7 @@ $Arch="x86_64-pc-windows-msvc"
8387
$EspFlashUrl="https://github.com/esp-rs/espflash/releases/latest/download/cargo-espflash-${Arch}.zip"
8488
$CargoBin="${env:USERPROFILE}\.cargo\bin"
8589
$EspFlashBin="${CargoBin}\cargo-espflash.exe"
86-
$RustDist="rust-${ToolchainVersion}-${Arch}"
90+
$RustDist="rust-${ToolchainVersion}-${DefaultHost}"
8791
$RustDistZipUrl="https://github.com/esp-rs/rust-build/releases/download/v${ToolchainVersion}/${RustDist}.zip"
8892
$IdfToolsPath="${HOME}/.espressif"
8993
$IdfToolXtensaElfClang="${IdfToolsPath}/tools/xtensa-esp32-elf-clang/${LlvmVersion}-${Arch}"

README.md

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ This repository contains:
1717
- [Linux and macOS](#linux-and-macos)
1818
- [Prerequisites](#prerequisites)
1919
- [Installation commands](#installation-commands)
20-
- [Windows x64](#windows-x64)
21-
- [Prerequisites](#prerequisites-1)
20+
- [Windows x64 GNU](#windows-x86_64-gnu)
21+
- [Prerequisites](#prerequisites-x86_64-gnu)
2222
- [Installation commands for PowerShell](#installation-commands-for-powershell)
23+
- [Windows x64 MSVC](#windows-x86_64-msvc)
24+
- [Prerequisites](#prerequisites-x86_64-msvc)
25+
- [Installation commands for PowerShell](#installation-commands-for-powershell-1)
2326
- [RISC-V Installation](#riscv-installation)
2427
- [Building projects](#building-projects)
2528
- [Cargo first approach](#cargo-first-approach)
@@ -48,7 +51,7 @@ Invoke-WebRequest 'https://github.com/esp-rs/rust-build/releases/download/v1.62.
4851

4952
### Linux and macOS
5053

51-
Following instructions are specific for ESP32 and ESP32-S series based on Xtensa architecture.
54+
The following instructions are specific for the ESP32 and ESP32-S series based on Xtensa architecture.
5255

5356
Instructions for ESP-C series based on RISC-V architecture are described in [RISC-V section](#riscv-installation).
5457

@@ -61,7 +64,7 @@ Instructions for ESP-C series based on RISC-V architecture are described in [RIS
6164
python3 python3-pip python3-venv libusb-1.0-0 libssl-dev pkg-config libtinfo5 libpython2.7
6265
```
6366

64-
No prerequisites are needed for macOS
67+
No prerequisites are needed for macOS.
6568

6669
#### Installation commands
6770

@@ -75,9 +78,9 @@ Run `./install-rust-toolchain.sh --help` for more information about arguments.
7578

7679
Export variables are displayed at the end of the script.
7780
> **Note**
78-
> If the export variables are added into the shell startup script, the shell may need to be refreshed.
81+
> If the export variables are added to the shell startup script, the shell may need to be refreshed.
7982

80-
Installation of different version of toolchain:
83+
Installation of different version of the toolchain:
8184

8285
```
8386
./install-rust-toolchain.sh --toolchain-version 1.62.1.0 --export-file export-esp-rust.sh
@@ -99,13 +102,40 @@ source export-esp-rust.sh
99102
- `-t|--toolchain-version`: Xtensa Rust toolchain version
100103
- `-x|--clear-cache`: Removes cached distribution files. Possible values: [`YES, NO`]
101104
102-
### Windows x64
105+
### Windows x86_64 GNU
103106
104-
Following instructions are specific for ESP32 and ESP32-S series based on Xtensa architecture.
107+
The following instructions describe deployment with the GNU toolchain. If you're using Visual Studio with Windows 10 SDK, consider option [Windows x86_64 MSVC](#windows-x86_64-msvc).
108+
109+
#### Prerequisites x86_64 GNU
110+
111+
Install MinGW x86_64 e.g., from releases https://github.com/niXman/mingw-builds-binaries/releases and add bin to environment variable PATH
112+
113+
```powershell
114+
choco install 7zip
115+
Invoke-WebRequest https://github.com/niXman/mingw-builds-binaries/releases/download/12.1.0-rt_v10-rev3/x86_64-12.1.0-release-posix-seh-rt_v10-rev3.7z -OutFile x86_64-12.1.0-release-posix-seh-rt_v10-rev3.7z
116+
7z e x86_64-12.1.0-release-posix-seh-rt_v10-rev3.7z
117+
$env:PATH+=";.....\x86_64-12.1.0-release-posix-seh-rt_v10-rev3\mingw64\bin"
118+
```
119+
120+
Install ESP-IDF using Windows installer https://dl.espressif.com/dl/esp-idf/
121+
#### Installation commands for PowerShell
122+
123+
Activate ESP-IDF PowerShell and enter following command:
124+
125+
```powershell
126+
git clone https://github.com/esp-rs/rust-build.git
127+
cd rust-build
128+
./Install-RustToolchain.ps1 -DefaultHost x86_64-pc-windows-gnu -ExportFile Export-EspRust.ps1
129+
source Export-EspRust.ps1
130+
```
131+
132+
### Windows x86_64 MSVC
133+
134+
The following instructions are specific for the ESP32 and ESP32-S series based on Xtensa architecture. If you do not have Visual Studio and Windows 10 SDK installed, consider the alternative option [Windows x86_64 GNU](#windows-x86_64-gnu).
105135

106136
Instructions for ESP-C series based on RISC-V architecture are described in [RISC-V section](#riscv-installation).
107137

108-
#### Prerequisites
138+
#### Prerequisites x86_64 MSVC
109139

110140
- Visual Studio - installed with option Desktop development with C++ - components: MSVCv142 - VS2019 C++ x86/64 build tools, Windows 10 SDK
111141

@@ -128,16 +158,16 @@ cd rust-build
128158

129159
Export variables are displayed at the end of the output from the script.
130160

131-
Installation of different version of toolchain:
161+
Installation of different versions of toolchain:
132162

133163
```sh
134-
./Install-RustToolchain.ps1 --toolchain-version 1.62.1.0 --export-file Export-EspRust.ps1
164+
./Install-RustToolchain.ps1 -ToolchainVersion 1.62.1.0 -ExportFile Export-EspRust.ps1
135165
source ./Export-EspRust.ps1
136166
```
137167

138168
## RISC-V Installation
139169

140-
Following instructions are specific for ESP32-C based on RISC-V architecture.
170+
The following instructions are specific for ESP32-C based on RISC-V architecture.
141171

142172
Install the RISC-V target for Rust:
143173

@@ -213,11 +243,11 @@ When building for Xtensa targets, we need to [override the `esp` toolchain](http
213243

214244
## Containers with Rust ESP environment
215245

216-
Alternatively, some container images, with pre-installed Rust and ESP-IDF, are published to Dockerhub and can be used to build Rust projects for ESP boards:
246+
Alternatively, some container images with pre-installed Rust and ESP-IDF, are published to Dockerhub and can be used to build Rust projects for ESP boards:
217247

218248
- [idf-rust](https://hub.docker.com/r/espressif/idf-rust)
219-
- Some tags contains only the toolchain. The naming convention for those tags is: `<xtensa-version>`
220-
- Some tags contains full environment with esp-idf installed, [wokwi-server](https://github.com/MabezDev/wokwi-server)
249+
- Some tags contain only the toolchain. The naming convention for those tags is: `<xtensa-version>`
250+
- Some tags contain full environment with esp-idf installed, [wokwi-server](https://github.com/MabezDev/wokwi-server)
221251
and [web-flash](https://github.com/bjoernQ/esp-web-flash-server) to use them
222252
in Dev Containers. This tags are generated for `linux/arm64` and `linux/amd64`,
223253
and use the following naming convention: `<board>_<esp-idf>_<xtensa-version>`
@@ -229,7 +259,7 @@ Podman example with mapping multiple /dev/ttyUSB from host computer to the conta
229259
podman run --device /dev/ttyUSB0 --device /dev/ttyUSB1 -it docker.io/espressif/idf-rust-examples
230260
```
231261

232-
Docker (does not support flashing from container):
262+
Docker (does not support flashing from a container):
233263

234264
```sh
235265
docker run -it espressif/idf-rust-examples
@@ -239,7 +269,7 @@ If you are using the `idf-rust-examples` image, instructions will be displayed o
239269

240270
## Dev Containers
241271

242-
Dev Container support is offered for VS Code, Gitpod and GitHub Codespaces,
272+
Dev Container support is offered for VS Code, Gitpod, and GitHub Codespaces,
243273
resulting in a fully working environment to develop for ESP boards in Rust,
244274
flash and simulate projects with Wokwi from the container.
245275

Test-RustToolchain.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
param (
33
[Parameter()]
44
[String]
5+
[ValidateSet("x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu")]
6+
$DefaultHost = "x86_64-pc-windows-msvc",
7+
[String]
58
$ToolchainVersion = '1.62.1.0',
69
[String]
710
[ValidateSet("xtensa-esp32-espidf", "xtensa-esp32s2-espidf", "xtensa-esp32s3-espidf", "riscv32imc-esp-espidf")]
@@ -24,6 +27,7 @@ $ErrorActionPreference = "Stop"
2427
$RustStdDemo = "rust-esp32-std-demo"
2528

2629
"Processing configuration:"
30+
"-DefaultHost = ${DefaultHost}"
2731
"-Features = ${Features}"
2832
"-LlvmVersion = ${LlvmVersion}"
2933
"-Target = ${Target}"
@@ -37,6 +41,7 @@ $ExportFile="Export-Rust-${ToolchainName}.ps1"
3741

3842
if ("skip" -ne $InstallationMode) {
3943
./Install-RustToolchain.ps1 `
44+
-DefaultHost ${DefaultHost} `
4045
-ExportFile ${ExportFile} `
4146
-LlvmVersion ${LlvmVersion} `
4247
-InstallationMode ${InstallationMode} `

install-rust-toolchain.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,22 @@ function install_system_packages() {
427427
fi
428428
}
429429

430+
function install_system_packages() {
431+
if [ -z "${SYSTEM_PACKAGES}" ]; then
432+
return
433+
fi
434+
435+
echo "Installing system packages: ${SYSTEM_PACKAGES}"
436+
437+
if [[ ${ARCH} == "aarch64-apple-darwin" || ${ARCH} == "x86_64-apple-darwin" ]]; then
438+
command -v brew || {
439+
echo "Warning: Unable to find command brew. Skipping installation of system package."
440+
return
441+
}
442+
brew list "${SYSTEM_PACKAGES}" || brew install "${SYSTEM_PACKAGES}"
443+
fi
444+
}
445+
430446
# Check required tooling - rustc, rustfmt
431447
command -v rustup || install_rustup
432448

support/rust-build/Repackage-RustRelease.ps1

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
[CmdletBinding()]
2+
param (
3+
[Parameter()]
4+
[String]
5+
[ValidateSet("x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu")]
6+
$DefaultHost = "x86_64-pc-windows-msvc"
7+
)
18
# Helper script to perform repackaging of Windows release
29

310
# Stop on error
@@ -12,13 +19,13 @@ if (Test-Path -Path esp -PathType Container) {
1219
}
1320

1421
mkdir esp
15-
7z e rust-${RustVersion}-x86_64-pc-windows-msvc.tar.xz
16-
7z x rust-${RustVersion}-x86_64-pc-windows-msvc.tar
17-
pushd rust-${RustVersion}-x86_64-pc-windows-msvc
22+
7z e rust-${RustVersion}-${DefaultHost}.tar.xz
23+
7z x rust-${RustVersion}-${DefaultHost}.tar
24+
pushd rust-${RustVersion}-${DefaultHost}
1825
cp -Recurse .\rustc\bin ..\esp\
1926
cp -Recurse .\rustc\lib ..\esp\
2027
cp -Recurse .\rustc\share ..\esp\
21-
cp -ErrorAction SilentlyContinue -Recurse .\rust-std-x86_64-pc-windows-msvc\lib\* ..\esp\lib\
28+
cp -ErrorAction SilentlyContinue -Recurse .\rust-std-${DefaultHost}\lib\* ..\esp\lib\
2229
popd
2330
7z e rust-src-${RustVersion}.tar.xz
2431
7z x rust-src-${RustVersion}.tar
@@ -32,4 +39,4 @@ Get-ChildItem -Path .\ -Filter *.pdb -Recurse -File -Name| ForEach-Object {
3239
Remove-Item -Path $_
3340
}
3441

35-
7z a rust-${ReleaseVersion}-x86_64-pc-windows-msvc.zip esp/
42+
7z a rust-${ReleaseVersion}-${DefaultHost}.zip esp/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
2+
3+
choco install msys2 -y
4+
5+
msys2_shell.cmd -mingw64
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
cd c:
4+
git clone --recursive https://github.com/esp-rs/rust.git r
5+
cd r
6+
7+
python3 src/bootstrap/configure.py --experimental-targets=Xtensa --enable-extended --tools=clippy,cargo,rustfmt --dist-compression-formats='xz' --host 'x86_64-pc-windows-gnu'
8+
9+
python3 x.py dist --stage 2
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
pacman -Sy pacman-mirrors
4+
5+
pacman -S git \
6+
make \
7+
diffutils \
8+
tar \
9+
mingw-w64-x86_64-python \
10+
mingw-w64-x86_64-cmake \
11+
mingw-w64-x86_64-gcc \
12+
mingw-w64-x86_64-ninja

0 commit comments

Comments
 (0)