Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

Rev 28 | Rev 30 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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