Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

Rev 27 | Rev 29 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23 pmbaty 1
@echo off
2
setlocal enableextensions enabledelayedexpansion
3
 
4
rem // set the WSL distribution to use
5
set WSL_DISTR=Ubuntu-22.04
6
 
27 pmbaty 7
rem // name of the QNX SDK root directory
8
set QNXSDK_DIRNAME=qnx800
9
 
23 pmbaty 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
12
 
13
 
28 pmbaty 14
rem // welcome the wary user
15
echo QNX8 toolchain cross-build script for WSL by Pierre-Marie Baty ^<pm@pmbaty.com^>
16
echo.
17
 
23 pmbaty 18
rem // make sure we have at least Windows 10
19
for /f "tokens=4 delims=. " %%i in ('ver') do set VERSION=%%i
24 pmbaty 20
echo Detected Windows NT kernel version: %VERSION%
23 pmbaty 21
if %VERSION% LSS 10 (
22
        echo Error: you need at least Windows 10 to cross-build LLVM to QNX 8.
24 pmbaty 23
        echo Please upgrade your Windows operating system to Windows 10 version 2004 build
24
        echo 19041 or a later version.
23 pmbaty 25
        goto :exit_error
26
)
27
 
28
rem // if WSL is not installed, do so
28 pmbaty 29
echo|set /p=Checking whether the Windows Subsystem for Linux is installed...
30
wsl --list -v > nul 2>&1 || ( echo no & goto :install_wsl )
31
echo yes
23 pmbaty 32
 
33
rem // WSL is installed, make sure the Linux distribution we need is there
28 pmbaty 34
echo|set /p=Checking for the presence of the GNU/Linux distribution %WSL_DISTR% in WSL...
35
wsl --distribution %WSL_DISTR% -- cat /etc/os-release|find "%WSL_DISTR:-= %" > nul || ( echo no & goto :install_wsl )
36
echo yes
23 pmbaty 37
 
28 pmbaty 38
rem // WSL is installed with the right Linux distribution, make sure it's running WSL2
39
echo|set /p=Checking whether the WSL hypervisor is version 2...
23 pmbaty 40
wsl --distribution %WSL_DISTR% -- cat /proc/version|find "WSL2" > nul || (
28 pmbaty 41
        echo no
42
        echo|set /p=Attempting to convert the WSL distribution %WSL_DISTR% to WSL2...
23 pmbaty 43
        rem // this distribution needs to be converted
44
        wsl --set-version %WSL_DISTR% 2 || (
28 pmbaty 45
                echo failed
23 pmbaty 46
                echo Error: you need the Windows Subsystem for Linux to support WSL2 for this
47
                echo cross-build script to work consistently.
48
                echo Please upgrade your Windows operating system to Windows 10 version 2004 build
49
                echo 19041 or a later version.
50
                goto :exit_error
51
        )
52
        rem // alright, this distribution is on WSL2
53
)
28 pmbaty 54
echo ok
23 pmbaty 55
 
56
rem // make sure we have the required tools, install them if not
57
set APT_CACHE_UPDATED=0
58
for %%i in (%REQUIRED_TOOLS%) do (
59
        rem // tool syntax: "<executable>:<optional APT package name>"
60
        rem // if package name is not specified, it defaults to <executable>
61
        set REQUIRED_TOOL_AND_PACKAGE=%%i
62
        for /f "tokens=1-2 delims=:" %%j in ('echo !REQUIRED_TOOL_AND_PACKAGE!') do (
63
                set REQUIRED_TOOL=%%j
64
                set REQUIRED_PACKAGE=%%k
65
                if "!REQUIRED_PACKAGE!"=="" set REQUIRED_PACKAGE=!REQUIRED_TOOL!
66
        )
28 pmbaty 67
        echo|set /p=Checking for the presence of !REQUIRED_TOOL! from APT package !REQUIRED_PACKAGE!...
23 pmbaty 68
        wsl --distribution %WSL_DISTR% -- !REQUIRED_TOOL! --version > nul 2>&1 && (
28 pmbaty 69
                echo yes
23 pmbaty 70
        ) || (
28 pmbaty 71
                echo no
23 pmbaty 72
                echo !REQUIRED_TOOL! needs installation. Attempting to install it.
73
                if "!APT_CACHE_UPDATED!"=="0" (
74
                        rem // allow ourselves to run any commands by patching /etc/sudoers. Do this once.
75
                        wsl --distribution %WSL_DISTR% -- sudo sh -c ^"echo '%%sudo  ALL=^(ALL^) NOPASSWD:ALL' ^>^> /etc/sudoers^"
76
                        rem // update APT cache before installing stuff, but just once.
77
                        wsl --distribution %WSL_DISTR% -- sudo apt-get -y update
78
                        set APT_CACHE_UPDATED=1
79
                )
80
                wsl --distribution %WSL_DISTR% sudo apt-get -y install !REQUIRED_PACKAGE! || (
81
                        echo Error: the required Linux tool !REQUIRED_TOOL! can't be installed with apt-get.
82
                        pause
83
                        goto :exit_error
84
                )
85
        )
86
)
87
 
28 pmbaty 88
rem // setup the QNX SDP on the WSL side
23 pmbaty 89
 
28 pmbaty 90
rem // The build script initially recursively transferred the contents of $QNX_HOST and $QNX_TARGET to the WSL2 ext4 partition
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".
94
rem // To make this faster, here's what I do:
95
rem //   1. fire up an archiver and create a SINGLE FILE archive of the directory hierarchy to copy
96
rem //   2. hand the file over to WSL2
97
rem //   3. unpack the archive in place - as it's much faster to migrate a single file than a folder hierarchy.
98
rem // The only prerequisite shall be that the archive format be *operable with the tools at hand on both systems*.
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
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...
24 pmbaty 103
 
28 pmbaty 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.
27 pmbaty 106
rem // NOTE: on WSL2, the QNX SDK will always be copied to $HOME, regardless of what xdg-user-dir DESKTOP says.
28 pmbaty 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
27 pmbaty 110
 
28 pmbaty 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...
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
117
        echo|set /p=Deploying QNX8 SDK Linux host files to WSL2 ext4 filesystem ^(this can take some time^)...
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
127
        echo|set /p=Deploying QNX8 SDK target sysroot files to WSL2 ext4 filesystem ^(this WILL take some time^)...
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
137
 
138
rem // now chain-call the POSIX Bourne shell build script
139
echo Running POSIX build script...
23 pmbaty 140
wsl --distribution %WSL_DISTR% -- ./cross-build.sh || goto :exit_error
141
 
142
rem // at this point, the story is supposed to have ended well.
143
rem // Keep calm, and I'll tell you another one tomorrow.
28 pmbaty 144
echo.
145
echo ^-- on a true Linux desktop a colorful icon would be displayed here, but Windows ruins all the fun. Pah.
23 pmbaty 146
goto :exit_success
147
 
148
 
149
:install_wsl
150
        echo Installing the Windows Subsystem for Linux...
151
        echo ############################################################################
152
        echo # NOTE: please define a *non-root* Linux user name and password when asked #
153
        echo #       ^(for example: 'utilisateur' / 'utilisateur'^)                       #
154
        echo #       then type 'exit' at the Linux shell ^(green prompt^) to continue.    #
155
        echo ############################################################################
156
        wsl --install --distribution %WSL_DISTR% || (
157
                echo Error: you need at least a version of Windows 10 which has the "wsl" command.
158
                echo Please upgrade your Windows operating system to Windows 10 version 2004 build
159
                echo 19041 or a later version.
160
                goto :exit_error
161
        )
28 pmbaty 162
        echo The Windows Subsystem for Linux was successfully installed with the %WSL_DISTR%
23 pmbaty 163
        echo distribution.
164
        echo Action required: please reboot your computer and run this script again.
165
        pause
166
        goto :exit_success
167
 
168
:exit_error
169
rem // failure exit
170
pause
171
exit /b 1
172
 
173
:exit_success
174
rem // successful exit
175
exit /b 0