Skip to content

Commit 2289e94

Browse files
Update Windows-Development-Setup.rst with pixi build instructions (backport ros2#4989)
1 parent e8bda53 commit 2289e94

File tree

2 files changed

+119
-276
lines changed

2 files changed

+119
-276
lines changed

source/Installation/Alternatives/Windows-Development-Setup.rst

Lines changed: 119 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -9,59 +9,138 @@ Windows (source)
99
:depth: 2
1010
:local:
1111

12-
This guide is about how to setup a development environment for ROS 2 on Windows.
12+
This page explains how to setup a development environment for ROS 2 on Windows.
1313

1414
System requirements
1515
-------------------
1616

1717
Only Windows 10 is supported.
1818

19+
.. warning::
20+
21+
We recommend using a clean Windows environment for the build, such as a fresh install, Docker container, or Virtual Machine. This is because existing software, such as other Python versions, can pollute the build configuration and cause compilation errors.
22+
1923
Language support
2024
^^^^^^^^^^^^^^^^
2125

2226
Make sure you have a locale which supports ``UTF-8``.
2327
For example, for a Chinese-language Windows 10 installation, you may need to install an `English language pack <https://support.microsoft.com/en-us/windows/language-packs-for-windows-a5094319-a92d-18de-5b53-1cfc697cfca8>`_.
2428

25-
.. include:: ../_Windows-Install-Prerequisites.rst
29+
Create a location for the ROS 2 installation
30+
--------------------------------------------
31+
32+
This location will contain both the installed binary packages, plus the ROS 2 installation itself.
2633

27-
Install additional prerequisites from Chocolatey
28-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34+
Start a powershell session (usually by clicking on the start menu, then typing ``powershell``).
2935

30-
.. code-block:: bash
36+
Then create a directory to store the installation.
37+
Because of Windows path-length limitations, this should be as short as possible.
38+
We'll use ``C:\dev`` for the rest of these instructions.
3139

32-
choco install -y cppcheck curl git winflexbison3
40+
.. code-block:: console
3341
34-
You will need to append the Git cmd folder ``C:\Program Files\Git\cmd`` to the PATH (you can do this by clicking the Windows icon, typing "Environment Variables", then clicking on "Edit the system environment variables".
35-
In the resulting dialog, click "Environment Variables", the click "Path" on the bottom pane, then click "Edit" and add the path).
42+
$ md C:\dev
3643
37-
Install Python prerequisites
38-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
Increase the Windows maximum path length
45+
----------------------------------------
46+
47+
By default, Windows is restricted to a maximum path length (MAX_PATH) of 260 characters.
48+
The ROS 2 build will use significantly longer path lengths, so we will increase that.
49+
Using the powershell session you started above, run the following:
50+
51+
.. code-block:: console
52+
53+
$ New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
54+
55+
You can read more about this limitation in `Microsoft's documentation <https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry>`__.
56+
57+
58+
Install prerequisites
59+
---------------------
60+
61+
Install MSVC
62+
^^^^^^^^^^^^
63+
64+
In order to compile the ROS 2 code, the MSVC compiler must be installed.
65+
Currently it is recommended to use MSVC 2019.
66+
67+
Continue using the previous powershell session, and run the following command to download it:
68+
69+
.. code-block:: console
70+
71+
$ irm https://aka.ms/vs/16/release/vs_buildtools.exe -OutFile vs_buildtools_2019.exe
72+
73+
Now install MSVC 2019:
74+
75+
.. code-block:: console
76+
77+
$ .\vs_buildtools_2019.exe --quiet --wait --norestart --add Microsoft.Component.MSBuild --add Microsoft.Net.Component.4.6.1.TargetingPack --add Microsoft.Net.Component.4.8.SDK --add Microsoft.VisualStudio.Component.CoreBuildTools --add Microsoft.VisualStudio.Component.Roslyn.Compiler --add Microsoft.VisualStudio.Component.TextTemplating --add Microsoft.VisualStudio.Component.VC.CLI.Support --add Microsoft.VisualStudio.Component.VC.CoreBuildTools --add Microsoft.VisualStudio.Component.VC.CoreIde --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK --add Microsoft.VisualStudio.Component.Windows10SDK.19041 --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core --add Microsoft.VisualStudio.Workload.MSBuildTools --add Microsoft.VisualStudio.Workload.VCTools
78+
79+
.. note::
3980

40-
Install additional Python dependencies:
81+
The installation of MSVC can take a long time, and there is no feedback while it is progressing.
4182

42-
.. code-block:: bash
83+
Install pixi
84+
^^^^^^^^^^^^
4385

44-
$ pip install -U colcon-common-extensions coverage flake8 flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-deprecated flake8-docstrings flake8-import-order flake8-quotes mock mypy==0.931 pep8 pydocstyle pytest pytest-cov pytest-mock pytest-repeat pytest-rerunfailures pytest-runner vcstool
86+
ROS 2 uses `conda-forge <https://conda-forge.org/>`__ as a backend for packages, with `pixi <https://pixi.sh/latest/>`__ as the frontend.
87+
88+
Continue using the previous powershell session, and use the instructions from https://pixi.sh/latest/ to install ``pixi``.
89+
Once ``pixi`` has been installed, close the powershell session and start it again, which will ensure ``pixi`` is on the PATH.
90+
91+
Install dependencies
92+
^^^^^^^^^^^^^^^^^^^^
93+
94+
Download the pixi configuration file in the existing powershell session:
95+
96+
.. code-block:: console
97+
98+
$ cd C:\dev
99+
$ irm https://raw.githubusercontent.com/ros2/ros2/refs/heads/{REPOS_FILE_BRANCH}/pixi.toml -OutFile pixi.toml
100+
101+
Install dependencies:
102+
103+
.. code-block:: console
104+
105+
$ pixi install
106+
107+
You should now close the powershell session, as the rest of the instructions will use the Windows command prompt.
45108

46109
Build ROS 2
47110
-----------
48111

112+
Start a new Windows command prompt, which will be used for the build.
113+
114+
Source the MSVC compiler
115+
^^^^^^^^^^^^^^^^^^^^^^^^
116+
117+
This is required in the command prompt you'll use to compile ROS 2, but it is *not* required when running:
118+
119+
.. code-block:: console
120+
121+
$ call "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
122+
123+
Source the pixi environment
124+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
125+
126+
This is required in every command prompt you open to set up paths to the dependencies:
127+
128+
.. code-block:: console
129+
130+
$ cd C:\dev
131+
$ pixi shell
132+
49133
Get ROS 2 code
50134
^^^^^^^^^^^^^^
51135

52136
Now that we have the development tools we can get the ROS 2 source code.
53137

54-
First setup a development folder, for example ``C:\{DISTRO}``:
55-
56-
.. note::
57-
58-
It is very important that the chosen path is short, due to the short default Windows path limits (260 characters).
59-
To allow longer paths, see `maximum-file-path-limitation <https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry>`__.
138+
Setup a development folder, for example ``C:\dev\{DISTRO}``:
60139

61140
.. code-block:: console
62141
63-
$ md \{DISTRO}\src
64-
$ cd \{DISTRO}
142+
$ md C:\dev\{DISTRO}\src
143+
$ cd C:\dev\{DISTRO}
65144
66145
Get the ``ros2.repos`` file which defines the repositories to clone from:
67146

@@ -80,8 +159,6 @@ Build the code in the workspace
80159

81160
.. _windows-dev-build-ros2:
82161

83-
To build ROS 2 you will need a Visual Studio Command Prompt ("x64 Native Tools Command Prompt for VS 2019") running as Administrator.
84-
85162
To build the ``\{DISTRO}`` folder tree:
86163

87164
.. code-block:: console
@@ -93,23 +170,33 @@ To build the ``\{DISTRO}`` folder tree:
93170
We're using ``--merge-install`` here to avoid a ``PATH`` variable that is too long at the end of the build.
94171
If you're adapting these instructions to build a smaller workspace then you might be able to use the default behavior which is isolated install, i.e. where each package is installed to a different folder.
95172

96-
.. note::
97-
98-
If you are doing a debug build use ``python_d path\to\colcon_executable`` ``colcon``.
99-
See `Extra stuff for debug mode`_ for more info on running Python code in debug builds on Windows.
100-
101173
.. note::
102174

103175
Source installation can take a long time given the large number of packages being pulled into the workspace.
104176

105177
Setup environment
106178
-----------------
107179

108-
Start a command shell and source the ROS 2 setup file to set up the workspace:
180+
Start a new Windows command prompt, which will be used in the examples.
181+
182+
Source the pixi environment
183+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
184+
185+
This is required in every command prompt you open to set up paths to the dependencies:
109186

110187
.. code-block:: console
111188
112-
$ call C:\{DISTRO}\install\local_setup.bat
189+
$ cd C:\dev
190+
$ pixi shell
191+
192+
Source the ROS 2 environment
193+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
194+
195+
This is required in every command prompt you open to setup the ROS 2 workspace:
196+
197+
.. code-block:: console
198+
199+
$ call C:\dev\{DISTRO}\install\local_setup.bat
113200
114201
This will automatically set up the environment for any DDS vendors that support was built for.
115202

@@ -144,7 +231,7 @@ Then, run a C++ ``talker``\ :
144231
$ call install\local_setup.bat
145232
$ ros2 run demo_nodes_cpp talker
146233
147-
In a separate shell you can do the same, but instead run a Python ``listener``\ :
234+
In a separate command prompt you can do the same, but instead run a Python ``listener``\ :
148235

149236
.. code-block:: console
150237
@@ -164,84 +251,6 @@ Next steps
164251

165252
Continue with the :doc:`tutorials and demos <../../Tutorials>` to configure your environment, create your own workspace and packages, and learn ROS 2 core concepts.
166253

167-
Extra stuff for Debug mode
168-
--------------------------
169-
170-
If you want to be able to run all the tests in Debug mode, you'll need to install a few more things:
171-
172-
* To be able to extract the Python source tarball, you can use PeaZip:
173-
174-
.. code-block:: bash
175-
176-
choco install -y peazip
177-
178-
* You'll also need SVN, since some of the Python source-build dependencies are checked out via SVN:
179-
180-
.. code-block:: bash
181-
182-
choco install -y svn hg
183-
184-
* You'll need to quit and restart the command prompt after installing the above.
185-
* Get and extract the Python 3.8.3 source from the ``tgz``:
186-
187-
* `Python-3.8.3 <https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz>`__
188-
* To keep these instructions concise, please extract it to ``C:\dev\Python-3.8.3``
189-
190-
* Now, build the Python source in debug mode from a Visual Studio command prompt:
191-
192-
.. code-block:: bash
193-
194-
cd C:\dev\Python-3.8.3\PCbuild
195-
get_externals.bat
196-
build.bat -p x64 -d
197-
198-
* Finally, copy the build products into the Python38 installation directories, next to the Release-mode Python executable and DLL's:
199-
200-
.. code-block:: bash
201-
202-
cd C:\dev\Python-3.8.3\PCbuild\amd64
203-
copy python_d.exe C:\Python38 /Y
204-
copy python38_d.dll C:\Python38 /Y
205-
copy python3_d.dll C:\Python38 /Y
206-
copy python38_d.lib C:\Python38\libs /Y
207-
copy python3_d.lib C:\Python38\libs /Y
208-
copy sqlite3_d.dll C:\Python38\DLLs /Y
209-
for %I in (*_d.pyd) do copy %I C:\Python38\DLLs /Y
210-
211-
* Now, from a fresh command prompt, make sure that ``python_d`` works:
212-
213-
.. code-block:: bash
214-
215-
python_d -c "import _ctypes ; import coverage"
216-
217-
* Once you have verified the operation of ``python_d``, it is necessary to reinstall a few dependencies with the debug-enabled libraries:
218-
219-
.. code-block:: bash
220-
221-
python_d -m pip install --force-reinstall https://github.com/ros2/ros2/releases/download/numpy-archives/numpy-1.18.4-cp38-cp38d-win_amd64.whl
222-
python_d -m pip install --force-reinstall https://github.com/ros2/ros2/releases/download/lxml-archives/lxml-4.5.1-cp38-cp38d-win_amd64.whl
223-
224-
* To verify the installation of these dependencies:
225-
226-
.. code-block:: bash
227-
228-
python_d -c "from lxml import etree ; import numpy"
229-
230-
* When you wish to return to building release binaries, it is necessary to uninstall the debug variants and use the release variants:
231-
232-
.. code-block:: bash
233-
234-
python -m pip uninstall numpy lxml
235-
python -m pip install numpy lxml
236-
237-
* To create executables python scripts(``.exe``), python_d should be used to invoke colcon
238-
239-
.. code-block:: bash
240-
241-
python_d path\to\colcon_executable build
242-
243-
* Hooray, you're done!
244-
245254
Stay up to date
246255
---------------
247256

@@ -262,4 +271,4 @@ Uninstall
262271

263272
.. code-block:: console
264273
265-
$ rmdir /s /q \ros2_{DISTRO}
274+
$ rmdir /s /q C:\dev\{DISTRO}

0 commit comments

Comments
 (0)