Rev 27 | Rev 29 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 27 | Rev 28 | ||
---|---|---|---|
Line 8... | Line 8... | ||
8 | set QNXSDK_DIRNAME=qnx800 |
8 | set QNXSDK_DIRNAME=qnx800 |
9 | 9 | ||
10 | rem // list of Linux tools required by the cross-build script |
10 | rem // list of Linux tools required by the cross-build script |
11 | set REQUIRED_TOOLS=wget python3 cmake gcc g++ ninja:ninja-build ccache |
11 | set REQUIRED_TOOLS=wget python3 cmake gcc g++ ninja:ninja-build ccache |
12 | 12 | ||
- | 13 | ||
- | 14 | rem // welcome the wary user |
|
- | 15 | echo QNX8 toolchain cross-build script for WSL by Pierre-Marie Baty ^<pm@pmbaty.com^> |
|
- | 16 | echo. |
|
13 | 17 | ||
14 | rem // make sure we have at least Windows 10 |
18 | rem // make sure we have at least Windows 10 |
15 | for /f "tokens=4 delims=. " %%i in ('ver') do set VERSION=%%i |
19 | for /f "tokens=4 delims=. " %%i in ('ver') do set VERSION=%%i |
16 | echo Detected Windows NT kernel version: %VERSION% |
20 | echo Detected Windows NT kernel version: %VERSION% |
17 | if %VERSION% LSS 10 ( |
21 | if %VERSION% LSS 10 ( |
Line 20... | Line 24... | ||
20 | echo 19041 or a later version. |
24 | echo 19041 or a later version. |
21 | goto :exit_error |
25 | goto :exit_error |
22 | ) |
26 | ) |
23 | 27 | ||
24 | rem // if WSL is not installed, do so |
28 | rem // if WSL is not installed, do so |
25 | echo |
29 | echo|set /p=Checking whether the Windows Subsystem for Linux is installed... |
26 | wsl --list -v > nul 2>&1 || goto :install_wsl |
30 | wsl --list -v > nul 2>&1 || ( echo no & goto :install_wsl ) |
27 | echo |
31 | echo yes |
28 | 32 | ||
29 | rem // WSL is installed, make sure the Linux distribution we need is there |
33 | rem // WSL is installed, make sure the Linux distribution we need is there |
30 | echo |
34 | echo|set /p=Checking for the presence of the GNU/Linux distribution %WSL_DISTR% in WSL... |
31 | wsl --distribution %WSL_DISTR% -- cat /etc/os-release|find "%WSL_DISTR:-= %" > nul || goto :install_wsl |
35 | wsl --distribution %WSL_DISTR% -- cat /etc/os-release|find "%WSL_DISTR:-= %" > nul || ( echo no & goto :install_wsl ) |
32 | echo |
36 | echo yes |
33 | 37 | ||
34 | rem // WSL is |
38 | rem // WSL is installed with the right Linux distribution, make sure it's running WSL2 |
35 | echo |
39 | echo|set /p=Checking whether the WSL hypervisor is version 2... |
36 | wsl --distribution %WSL_DISTR% -- cat /proc/version|find "WSL2" > nul || ( |
40 | wsl --distribution %WSL_DISTR% -- cat /proc/version|find "WSL2" > nul || ( |
- | 41 | echo no |
|
37 | echo |
42 | echo|set /p=Attempting to convert the WSL distribution %WSL_DISTR% to WSL2... |
38 | rem // this distribution needs to be converted |
43 | rem // this distribution needs to be converted |
39 | wsl --set-version %WSL_DISTR% 2 || ( |
44 | wsl --set-version %WSL_DISTR% 2 || ( |
- | 45 | echo failed |
|
40 | echo Error: you need the Windows Subsystem for Linux to support WSL2 for this |
46 | echo Error: you need the Windows Subsystem for Linux to support WSL2 for this |
41 | echo cross-build script to work consistently. |
47 | echo cross-build script to work consistently. |
42 | echo Please upgrade your Windows operating system to Windows 10 version 2004 build |
48 | echo Please upgrade your Windows operating system to Windows 10 version 2004 build |
43 | echo 19041 or a later version. |
49 | echo 19041 or a later version. |
44 | goto :exit_error |
50 | goto :exit_error |
45 | ) |
51 | ) |
46 | rem // alright, this distribution is on WSL2 |
52 | rem // alright, this distribution is on WSL2 |
47 | ) |
53 | ) |
48 | echo |
54 | echo ok |
49 | 55 | ||
50 | rem // make sure we have the required tools, install them if not |
56 | rem // make sure we have the required tools, install them if not |
51 | set APT_CACHE_UPDATED=0 |
57 | set APT_CACHE_UPDATED=0 |
52 | for %%i in (%REQUIRED_TOOLS%) do ( |
58 | for %%i in (%REQUIRED_TOOLS%) do ( |
53 | rem // tool syntax: "<executable>:<optional APT package name>" |
59 | rem // tool syntax: "<executable>:<optional APT package name>" |
Line 56... | Line 62... | ||
56 | for /f "tokens=1-2 delims=:" %%j in ('echo !REQUIRED_TOOL_AND_PACKAGE!') do ( |
62 | for /f "tokens=1-2 delims=:" %%j in ('echo !REQUIRED_TOOL_AND_PACKAGE!') do ( |
57 | set REQUIRED_TOOL=%%j |
63 | set REQUIRED_TOOL=%%j |
58 | set REQUIRED_PACKAGE=%%k |
64 | set REQUIRED_PACKAGE=%%k |
59 | if "!REQUIRED_PACKAGE!"=="" set REQUIRED_PACKAGE=!REQUIRED_TOOL! |
65 | if "!REQUIRED_PACKAGE!"=="" set REQUIRED_PACKAGE=!REQUIRED_TOOL! |
60 | ) |
66 | ) |
61 | echo |
67 | echo|set /p=Checking for the presence of !REQUIRED_TOOL! from APT package !REQUIRED_PACKAGE!... |
62 | wsl --distribution %WSL_DISTR% -- !REQUIRED_TOOL! --version > nul 2>&1 && ( |
68 | wsl --distribution %WSL_DISTR% -- !REQUIRED_TOOL! --version > nul 2>&1 && ( |
63 | echo |
69 | echo yes |
64 | ) || ( |
70 | ) || ( |
- | 71 | echo no |
|
65 | echo !REQUIRED_TOOL! needs installation. Attempting to install it. |
72 | echo !REQUIRED_TOOL! needs installation. Attempting to install it. |
66 | if "!APT_CACHE_UPDATED!"=="0" ( |
73 | if "!APT_CACHE_UPDATED!"=="0" ( |
67 | rem // allow ourselves to run any commands by patching /etc/sudoers. Do this once. |
74 | rem // allow ourselves to run any commands by patching /etc/sudoers. Do this once. |
68 | wsl --distribution %WSL_DISTR% -- sudo sh -c ^"echo '%%sudo ALL=^(ALL^) NOPASSWD:ALL' ^>^> /etc/sudoers^" |
75 | wsl --distribution %WSL_DISTR% -- sudo sh -c ^"echo '%%sudo ALL=^(ALL^) NOPASSWD:ALL' ^>^> /etc/sudoers^" |
69 | rem // update APT cache before installing stuff, but just once. |
76 | rem // update APT cache before installing stuff, but just once. |
Line 76... | Line 83... | ||
76 | goto :exit_error |
83 | goto :exit_error |
77 | ) |
84 | ) |
78 | ) |
85 | ) |
79 | ) |
86 | ) |
80 | 87 | ||
81 | rem // set the QNX8 SDP build environment, deploying the toolchain symlinks if necessary |
- | |
82 | set THISDIR=%CD% |
- | |
83 | cd ..\qnx800 |
- | |
84 |
|
88 | rem // setup the QNX SDP on the WSL side |
85 | cd "%THISDIR%" |
- | |
86 | 89 | ||
87 | rem // The build script |
90 | rem // The build script initially recursively transferred the contents of $QNX_HOST and $QNX_TARGET to the WSL2 ext4 partition |
88 | rem // |
91 | rem // when necessary using the Plan9 NTFS to ext4 bridge (9p file protocol) implemented by Microsoft to transfer files |
- | 92 | rem // from Windows to WSL2. The only problem with this is, and Microsoft admits it, that 9p is *catastrophically slow*. |
|
- | 93 | rem // See https://learn.microsoft.com/en-us/windows/wsl/compare-versions - And when Microsoft says "slow", hear "unusable". |
|
89 | rem // |
94 | rem // To make this faster, here's what I do: |
90 | rem // 1. fire up |
95 | rem // 1. fire up an archiver and create a SINGLE FILE archive of the directory hierarchy to copy |
91 | rem // 2. |
96 | rem // 2. hand the file over to WSL2 |
92 | rem // 3. unpack the archive in |
97 | rem // 3. unpack the archive in place - as it's much faster to migrate a single file than a folder hierarchy. |
93 | rem // The prerequisite shall be that the archive format be *operable with the |
98 | rem // The only prerequisite shall be that the archive format be *operable with the tools at hand on both systems*. |
94 | rem // |
99 | rem // By using the "usr\bin\tar.exe" utility from the QNX8 Win64 host SDP tools and piping the data through a WSL2 instance running |
95 | rem // |
100 | rem // the Linux version of /usr/bin/tar to untar it directly at its location, we achieve 10x faster transfer speeds than 9p. |
- | 101 | rem // This is just ridiculous. I scoured the web for hours looking for an acceptable file transfer solution from Windows to WSL2 |
|
- | 102 | rem // and it looks just like nobody found that one yet. Ah well... |
|
96 | 103 | ||
- | 104 | rem // see if the SDP needs to be copied at all. Only do this when the modification time of the SDP directory on Windows is more recent than the one on Linux. |
|
- | 105 | rem // So test for the presence of the symlinks state file as it's the last file that's created (this ensures a complete copy), then check for the directory mtimes. |
|
97 | rem // NOTE: on WSL2, the QNX SDK will always be copied to $HOME, regardless of what xdg-user-dir DESKTOP says. |
106 | rem // NOTE: on WSL2, the QNX SDK will always be copied to $HOME, regardless of what xdg-user-dir DESKTOP says. |
- | 107 | echo|set /p=Checking if the %QNXSDK_DIRNAME% directory is present in WSL and up to date... |
|
- | 108 | wsl --distribution %WSL_DISTR% -- test ! -f "${HOME}/%QNXSDK_DIRNAME%/.symlinks-state" -o "../%QNXSDK_DIRNAME%" -nt "${HOME}/%QNXSDK_DIRNAME%" && ( |
|
- | 109 | echo no |
|
- | 110 | ||
- | 111 | rem // copy needed - cleanup and create the directories we'll need in $HOME to accomodate the QNX SDK. We want the Linux host tools, and the QNX target sysroot files |
|
- | 112 | echo|set /p=Preparing to copy QNX8 SDK files to WSL2 ext4 filesystem... |
|
98 | wsl --distribution %WSL_DISTR% -- mkdir -p |
113 | wsl --distribution %WSL_DISTR% -- rm -rf "${HOME}/%QNXSDK_DIRNAME%"; mkdir -p "${HOME}/%QNXSDK_DIRNAME%/host" "${HOME}/%QNXSDK_DIRNAME%/target" 2>nul |
- | 114 | echo done |
|
- | 115 | ||
- | 116 | rem // transfer the QNX SDK host files: tar on Windows, pipe to WSL2, untar on Linux - or die |
|
99 | echo |
117 | echo|set /p=Deploying QNX8 SDK Linux host files to WSL2 ext4 filesystem ^(this can take some time^)... |
100 | "% |
118 | "..\%QNXSDK_DIRNAME%\host\win64\x86_64\usr\bin\tar.exe" -c --directory="..\%QNXSDK_DIRNAME%\host" linux | wsl --distribution %WSL_DISTR% -- tar -x --directory="${HOME}/%QNXSDK_DIRNAME%/host" || ( echo failed & goto :exit_error ) |
- | 119 | echo done |
|
- | 120 | ||
- | 121 | rem // Windows has absolutely no notion of UNIX permissions. The best we can do here is to arbitrarily set the executable flags on relevant parts of the migrated tree. |
|
- | 122 | echo|set /p=Setting executable permissions to QNX8 SDK toolchain files... |
|
- | 123 | wsl --distribution %WSL_DISTR% -- chmod -R +x "${HOME}/%QNXSDK_DIRNAME%/host/linux/x86_64/usr/bin" "${HOME}/%QNXSDK_DIRNAME%/host/linux/x86_64/usr/lib/gcc" || goto :exit_error |
|
- | 124 | echo done |
|
- | 125 | ||
- | 126 | rem // transfer the QNX SDK target files: tar on Windows, pipe to WSL2, untar on Linux - or die |
|
101 | echo |
127 | echo|set /p=Deploying QNX8 SDK target sysroot files to WSL2 ext4 filesystem ^(this WILL take some time^)... |
102 | "% |
128 | "..\%QNXSDK_DIRNAME%\host\win64\x86_64\usr\bin\tar.exe" -c --directory="..\%QNXSDK_DIRNAME%\target" qnx | wsl --distribution %WSL_DISTR% -- tar -x --directory="${HOME}/%QNXSDK_DIRNAME%/target" || ( echo failed & goto :exit_error ) |
- | 129 | echo done |
|
- | 130 | ||
- | 131 | rem // setup the toolchain symlinks |
|
- | 132 | echo Setting up the QNX SDP platform-specific symlinks... |
|
- | 133 | "..\%QNXSDK_DIRNAME%\host\win64\x86_64\usr\bin\tar.exe" -c --directory="..\%QNXSDK_DIRNAME%" symlinks.sh | wsl --distribution %WSL_DISTR% -- tar -x --directory="${HOME}/%QNXSDK_DIRNAME%" || ( echo failed & goto :exit_error ) |
|
- | 134 | wsl --distribution %WSL_DISTR% -- cd "${HOME}/%QNXSDK_DIRNAME%" ^&^& find . -name symlinks.lst -exec ./symlinks.sh {} create $1 \; ^&^& printf 'present-v2' ^> "${HOME}/%QNXSDK_DIRNAME%/.symlinks-state" || goto :exit_error |
|
- | 135 | ) |
|
- | 136 | echo ok |
|
103 | 137 | ||
104 | rem // now |
138 | rem // now chain-call the POSIX Bourne shell build script |
- | 139 | echo Running POSIX build script... |
|
105 | wsl --distribution %WSL_DISTR% -- ./cross-build.sh || goto :exit_error |
140 | wsl --distribution %WSL_DISTR% -- ./cross-build.sh || goto :exit_error |
106 | 141 | ||
107 | rem // at this point, the story is supposed to have ended well. |
142 | rem // at this point, the story is supposed to have ended well. |
108 | rem // Keep calm, and I'll tell you another one tomorrow. |
143 | rem // Keep calm, and I'll tell you another one tomorrow. |
- | 144 | echo. |
|
- | 145 | echo ^-- on a true Linux desktop a colorful icon would be displayed here, but Windows ruins all the fun. Pah. |
|
109 | goto :exit_success |
146 | goto :exit_success |
110 | 147 | ||
111 | 148 | ||
112 | :install_wsl |
149 | :install_wsl |
113 | echo Installing the Windows Subsystem for Linux... |
150 | echo Installing the Windows Subsystem for Linux... |
Line 120... | Line 157... | ||
120 | echo Error: you need at least a version of Windows 10 which has the "wsl" command. |
157 | echo Error: you need at least a version of Windows 10 which has the "wsl" command. |
121 | echo Please upgrade your Windows operating system to Windows 10 version 2004 build |
158 | echo Please upgrade your Windows operating system to Windows 10 version 2004 build |
122 | echo 19041 or a later version. |
159 | echo 19041 or a later version. |
123 | goto :exit_error |
160 | goto :exit_error |
124 | ) |
161 | ) |
125 | echo The Windows Subsystem for Linux was successfully installed with the |
162 | echo The Windows Subsystem for Linux was successfully installed with the %WSL_DISTR% |
126 | echo distribution. |
163 | echo distribution. |
127 | echo Action required: please reboot your computer and run this script again. |
164 | echo Action required: please reboot your computer and run this script again. |
128 | pause |
165 | pause |
129 | goto :exit_success |
166 | goto :exit_success |
130 | 167 |