Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

Rev 29 | Rev 31 | 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
 
29 pmbaty 4
rem // what we're building
5
set PRODUCT_NAME=the LLVM compiler suite
6
 
7
rem // the WSL distribution to use
23 pmbaty 8
set WSL_DISTR=Ubuntu-22.04
9
 
27 pmbaty 10
rem // name of the QNX SDK root directory
11
set QNXSDK_DIRNAME=qnx800
12
 
23 pmbaty 13
rem // list of Linux tools required by the cross-build script
14
set REQUIRED_TOOLS=wget python3 cmake gcc g++ ninja:ninja-build ccache
15
 
16
 
28 pmbaty 17
rem // welcome the wary user
18
echo QNX8 toolchain cross-build script for WSL by Pierre-Marie Baty ^<pm@pmbaty.com^>
19
echo.
20
 
23 pmbaty 21
rem // make sure we have at least Windows 10
22
for /f "tokens=4 delims=. " %%i in ('ver') do set VERSION=%%i
24 pmbaty 23
echo Detected Windows NT kernel version: %VERSION%
23 pmbaty 24
if %VERSION% LSS 10 (
29 pmbaty 25
        echo Error: you need at least Windows 10 to cross-build %PRODUCT_NAME% to QNX 8.
24 pmbaty 26
        echo Please upgrade your Windows operating system to Windows 10 version 2004 build
27
        echo 19041 or a later version.
23 pmbaty 28
        goto :exit_error
29
)
30
 
31
rem // if WSL is not installed, do so
28 pmbaty 32
echo|set /p=Checking whether the Windows Subsystem for Linux is installed...
33
wsl --list -v > nul 2>&1 || ( echo no & goto :install_wsl )
34
echo yes
23 pmbaty 35
 
36
rem // WSL is installed, make sure the Linux distribution we need is there
28 pmbaty 37
echo|set /p=Checking for the presence of the GNU/Linux distribution %WSL_DISTR% in WSL...
38
wsl --distribution %WSL_DISTR% -- cat /etc/os-release|find "%WSL_DISTR:-= %" > nul || ( echo no & goto :install_wsl )
39
echo yes
23 pmbaty 40
 
28 pmbaty 41
rem // WSL is installed with the right Linux distribution, make sure it's running WSL2
42
echo|set /p=Checking whether the WSL hypervisor is version 2...
23 pmbaty 43
wsl --distribution %WSL_DISTR% -- cat /proc/version|find "WSL2" > nul || (
28 pmbaty 44
        echo no
45
        echo|set /p=Attempting to convert the WSL distribution %WSL_DISTR% to WSL2...
23 pmbaty 46
        rem // this distribution needs to be converted
47
        wsl --set-version %WSL_DISTR% 2 || (
28 pmbaty 48
                echo failed
23 pmbaty 49
                echo Error: you need the Windows Subsystem for Linux to support WSL2 for this
50
                echo cross-build script to work consistently.
51
                echo Please upgrade your Windows operating system to Windows 10 version 2004 build
52
                echo 19041 or a later version.
53
                goto :exit_error
54
        )
55
        rem // alright, this distribution is on WSL2
56
)
28 pmbaty 57
echo ok
23 pmbaty 58
 
59
rem // make sure we have the required tools, install them if not
30 pmbaty 60
set ETC_SUDOERS_PATCHED=0
23 pmbaty 61
for %%i in (%REQUIRED_TOOLS%) do (
62
        rem // tool syntax: "<executable>:<optional APT package name>"
63
        rem // if package name is not specified, it defaults to <executable>
64
        set REQUIRED_TOOL_AND_PACKAGE=%%i
65
        for /f "tokens=1-2 delims=:" %%j in ('echo !REQUIRED_TOOL_AND_PACKAGE!') do (
66
                set REQUIRED_TOOL=%%j
67
                set REQUIRED_PACKAGE=%%k
68
                if "!REQUIRED_PACKAGE!"=="" set REQUIRED_PACKAGE=!REQUIRED_TOOL!
69
        )
28 pmbaty 70
        echo|set /p=Checking for the presence of !REQUIRED_TOOL! from APT package !REQUIRED_PACKAGE!...
23 pmbaty 71
        wsl --distribution %WSL_DISTR% -- !REQUIRED_TOOL! --version > nul 2>&1 && (
28 pmbaty 72
                echo yes
23 pmbaty 73
        ) || (
28 pmbaty 74
                echo no
23 pmbaty 75
                echo !REQUIRED_TOOL! needs installation. Attempting to install it.
30 pmbaty 76
                if "!ETC_SUDOERS_PATCHED!"=="0" (
77
                        rem // allow ourselves to run any commands by patching /etc/sudoers. Do this once, and only if necessary.
78
                        wsl --distribution %WSL_DISTR% -- sudo sh -c ^"grep '%%sudo  ALL=^(ALL^) NOPASSWD:ALL' /etc/sudoers ^|^| echo '%%sudo  ALL=^(ALL^) NOPASSWD:ALL' ^>^> /etc/sudoers^"
79
rem                     rem // update APT cache before installing stuff, but just once.
80
rem                     wsl --distribution %WSL_DISTR% -- sudo apt-get -y update
81
                        set ETC_SUDOERS_PATCHED=1
23 pmbaty 82
                )
30 pmbaty 83
rem             wsl --distribution %WSL_DISTR% sudo apt-get -y install !REQUIRED_PACKAGE! || (
84
                wsl --distribution %WSL_DISTR% sudo apt-get -y install "../../Third-party software/Ubuntu 22.04 Debian packages for WSL2/!REQUIRED_PACKAGE!.deb" || (
23 pmbaty 85
                        echo Error: the required Linux tool !REQUIRED_TOOL! can't be installed with apt-get.
86
                        pause
87
                        goto :exit_error
88
                )
89
        )
90
)
91
 
28 pmbaty 92
rem // setup the QNX SDP on the WSL side
23 pmbaty 93
 
28 pmbaty 94
rem // The build script initially recursively transferred the contents of $QNX_HOST and $QNX_TARGET to the WSL2 ext4 partition
95
rem // when necessary using the Plan9 NTFS to ext4 bridge (9p file protocol) implemented by Microsoft to transfer files
96
rem // from Windows to WSL2. The only problem with this is, and Microsoft admits it, that 9p is *catastrophically slow*.
97
rem // See https://learn.microsoft.com/en-us/windows/wsl/compare-versions - And when Microsoft says "slow", hear "unusable".
98
rem // To make this faster, here's what I do:
99
rem //   1. fire up an archiver and create a SINGLE FILE archive of the directory hierarchy to copy
100
rem //   2. hand the file over to WSL2
101
rem //   3. unpack the archive in place - as it's much faster to migrate a single file than a folder hierarchy.
102
rem // The only prerequisite shall be that the archive format be *operable with the tools at hand on both systems*.
103
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
104
rem // the Linux version of /usr/bin/tar to untar it directly at its location, we achieve 10x faster transfer speeds than 9p.
105
rem // This is just ridiculous. I scoured the web for hours looking for an acceptable file transfer solution from Windows to WSL2
106
rem // and it looks just like nobody found that one yet. Ah well...
24 pmbaty 107
 
28 pmbaty 108
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.
109
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 110
rem // NOTE: on WSL2, the QNX SDK will always be copied to $HOME, regardless of what xdg-user-dir DESKTOP says.
28 pmbaty 111
echo|set /p=Checking if the %QNXSDK_DIRNAME% directory is present in WSL and up to date...
112
wsl --distribution %WSL_DISTR% -- test ! -f "${HOME}/%QNXSDK_DIRNAME%/.symlinks-state" -o "../%QNXSDK_DIRNAME%" -nt "${HOME}/%QNXSDK_DIRNAME%" && (
113
        echo no
27 pmbaty 114
 
28 pmbaty 115
        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
116
        echo|set /p=Preparing to copy QNX8 SDK files to WSL2 ext4 filesystem...
117
        wsl --distribution %WSL_DISTR% -- rm -rf "${HOME}/%QNXSDK_DIRNAME%"; mkdir -p "${HOME}/%QNXSDK_DIRNAME%/host" "${HOME}/%QNXSDK_DIRNAME%/target" 2>nul
118
        echo done
119
 
120
        rem // transfer the QNX SDK host files: tar on Windows, pipe to WSL2, untar on Linux - or die
121
        echo|set /p=Deploying QNX8 SDK Linux host files to WSL2 ext4 filesystem ^(this can take some time^)...
122
        "..\%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 )
123
        echo done
124
 
125
        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.
126
        echo|set /p=Setting executable permissions to QNX8 SDK toolchain files...
127
        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
128
        echo done
129
 
130
        rem // transfer the QNX SDK target files: tar on Windows, pipe to WSL2, untar on Linux - or die
131
        echo|set /p=Deploying QNX8 SDK target sysroot files to WSL2 ext4 filesystem ^(this WILL take some time^)...
132
        "..\%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 )
133
        echo done
134
 
135
        rem // setup the toolchain symlinks
136
        echo Setting up the QNX SDP platform-specific symlinks...
137
        "..\%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 )
138
        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
139
)
140
echo ok
141
 
142
rem // now chain-call the POSIX Bourne shell build script
143
echo Running POSIX build script...
23 pmbaty 144
wsl --distribution %WSL_DISTR% -- ./cross-build.sh || goto :exit_error
145
 
146
rem // at this point, the story is supposed to have ended well.
147
rem // Keep calm, and I'll tell you another one tomorrow.
28 pmbaty 148
echo.
29 pmbaty 149
echo The build ended successfully.
23 pmbaty 150
goto :exit_success
151
 
152
 
153
:install_wsl
154
        echo Installing the Windows Subsystem for Linux...
155
        echo ############################################################################
156
        echo # NOTE: please define a *non-root* Linux user name and password when asked #
157
        echo #       ^(for example: 'utilisateur' / 'utilisateur'^)                       #
158
        echo #       then type 'exit' at the Linux shell ^(green prompt^) to continue.    #
159
        echo ############################################################################
160
        wsl --install --distribution %WSL_DISTR% || (
161
                echo Error: you need at least a version of Windows 10 which has the "wsl" command.
162
                echo Please upgrade your Windows operating system to Windows 10 version 2004 build
163
                echo 19041 or a later version.
164
                goto :exit_error
165
        )
28 pmbaty 166
        echo The Windows Subsystem for Linux was successfully installed with the %WSL_DISTR%
23 pmbaty 167
        echo distribution.
168
        echo Action required: please reboot your computer and run this script again.
169
        goto :exit_success
170
 
171
:exit_error
172
rem // failure exit
173
pause
174
exit /b 1
175
 
176
:exit_success
177
rem // successful exit
29 pmbaty 178
pause
23 pmbaty 179
exit /b 0