Newer
Older
dub_jkp / scripts / ci / setup-ldc-windows.sh
  1. #!/usr/bin/env bash
  2.  
  3. # sets up LDC for cross-compilation. Source this script, s.t. the new LDC is in PATH
  4.  
  5. # Make sure this version matches the version of LDC2 used in .travis.yml,
  6. # otherwise the compiler and the lib used might mismatch.
  7. LDC_VERSION="1.22.0"
  8. ARCH=${ARCH:-32}
  9. VERSION=$(git describe --abbrev=0 --tags)
  10. OS=windows
  11.  
  12. # LDC should already be installed (see .travis.yml)
  13. # However, we need the libraries, so download them
  14. # We can't use the downloaded ldc2 itself, because obviously it's for Windows
  15.  
  16. if [ "${ARCH}" == 64 ]; then
  17. ARCH_SUFFIX='x86_64'
  18. ZIP_ARCH_SUFFIX='x64'
  19. else
  20. ARCH_SUFFIX='i686'
  21. ZIP_ARCH_SUFFIX='x86'
  22. fi
  23.  
  24. LDC_DIR_PATH="$(pwd)/ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}"
  25. LDC_XDFLAGS="-conf=${LDC_DIR_PATH}/etc/ldc2.conf -mtriple=${ARCH_SUFFIX}-pc-windows-msvc"
  26.  
  27. # Step 1: download the LDC Windows release
  28. # Check if the user already have it (e.g. building locally)
  29. if [ ! -d ${LDC_DIR_PATH} ]; then
  30. if [ ! -d "ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}.7z" ]; then
  31. wget "https://github.com/ldc-developers/ldc/releases/download/v${LDC_VERSION}/ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}.7z"
  32. fi
  33. 7z x "ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}.7z" > /dev/null
  34. fi
  35.  
  36. # Step 2: Generate a config file with the proper path
  37. cat > ${LDC_DIR_PATH}/etc/ldc2.conf <<EOF
  38. default:
  39. {
  40. switches = [
  41. "-defaultlib=phobos2-ldc,druntime-ldc",
  42. "-link-defaultlib-shared=false",
  43. ];
  44. post-switches = [
  45. "-I${LDC_DIR_PATH}/import",
  46. ];
  47. lib-dirs = [
  48. "${LDC_DIR_PATH}/lib/",
  49. "${LDC_DIR_PATH}/lib/mingw/",
  50. ];
  51. };
  52. EOF