diff --git a/.travis.yml b/.travis.yml index e80f8a1..4d046ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ - libevent-dev script: - - ./travis-ci.sh + - ./scripts/ci/travis.sh jobs: allow_failures: @@ -27,7 +27,7 @@ - stage: deploy d: ldc-1.19.0,dub os: osx - script: echo "Deploying to GitHub releases ..." && ./release.sh + script: echo "Deploying to GitHub releases ..." && ./scripts/ci/release.sh deploy: - provider: releases file_glob: true @@ -37,7 +37,7 @@ on: tags: true - d: ldc-1.19.0,dub - script: echo "Deploying to GitHub releases ..." && ./release.sh + script: echo "Deploying to GitHub releases ..." && ./scripts/ci/release.sh env: [ARCH=32] addons: apt: @@ -53,7 +53,7 @@ on: tags: true - d: ldc-1.19.0,dub - script: echo "Deploying to GitHub releases ..." && ./release.sh + script: echo "Deploying to GitHub releases ..." && ./scripts/ci/release.sh deploy: - provider: releases file_glob: true @@ -63,7 +63,7 @@ on: tags: true - d: ldc-1.19.0,dub - script: echo "Deploying to GitHub releases (win32) ..." && ./release-windows.sh + script: echo "Deploying to GitHub releases (win32) ..." && ./scripts/ci/release-windows.sh addons: apt: packages: @@ -77,7 +77,7 @@ on: tags: true - d: ldc-1.19.0,dub - script: echo "Deploying to GitHub releases (win64) ..." && ARCH=64 ./release-windows.sh + script: echo "Deploying to GitHub releases (win64) ..." && ARCH=64 ./scripts/ci/release-windows.sh addons: apt: packages: diff --git a/release-windows.sh b/release-windows.sh deleted file mode 100755 index 20da0cc..0000000 --- a/release-windows.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# Build the Windows binaries under Linux -set -eux -o pipefail - -BIN_NAME=dub - -# Allow the script to be run from anywhere -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -cd $DIR - -# Setup cross compiler -source setup-ldc-windows.sh - -# Run LDC with cross-compilation -archiveName="$BIN_NAME-$VERSION-$OS-$ARCH_SUFFIX.zip" -echo "Building $archiveName" -mkdir -p bin -DMD=ldmd2 ldc2 -run ./build.d -release ${LDC_XDFLAGS} - -cd bin -zip "$archiveName" "${BIN_NAME}.exe" diff --git a/release.sh b/release.sh deleted file mode 100755 index dbaf406..0000000 --- a/release.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash - -set -eux -o pipefail - -VERSION=$(git describe --abbrev=0 --tags) -ARCH="${ARCH:-64}" -CUSTOM_FLAGS=() -unameOut="$(uname -s)" -case "$unameOut" in - Linux*) - OS=linux - CUSTOM_FLAGS+=("-L--export-dynamic") - ;; - Darwin*) - OS=osx - CUSTOM_FLAGS+=("-L-dead_strip") - ;; - *) echo "Unknown OS: $unameOut"; exit 1 -esac - -if [[ $(basename "$DMD") =~ ldmd.* ]] ; then - CUSTOM_FLAGS+=("-flto=full") - # ld.gold is required on Linux - if [ ${OS:-} == "linux" ] ; then - CUSTOM_FLAGS+=("-linker=gold") - fi -fi - -case "$ARCH" in - 64) ARCH_SUFFIX="x86_64";; - 32) ARCH_SUFFIX="x86";; - *) echo "Unknown ARCH: $ARCH"; exit 1 -esac - -archiveName="dub-$VERSION-$OS-$ARCH_SUFFIX.tar.gz" - -echo "Building $archiveName" -DMD="$(command -v $DMD)" ./build.d -release -m$ARCH ${CUSTOM_FLAGS[@]} -tar cvfz "bin/$archiveName" -C bin dub diff --git a/scripts/ci/release-windows.sh b/scripts/ci/release-windows.sh new file mode 100755 index 0000000..5b87df2 --- /dev/null +++ b/scripts/ci/release-windows.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# Build the Windows binaries under Linux +set -eux -o pipefail + +BIN_NAME=dub + +# Allow the script to be run from anywhere +DIR="$( cd "$(dirname "${BASH_SOURCE[0]}")/../../" && pwd )" +cd $DIR + +# Setup cross compiler +source scripts/ci/setup-ldc-windows.sh + +# Run LDC with cross-compilation +archiveName="$BIN_NAME-$VERSION-$OS-$ARCH_SUFFIX.zip" +echo "Building $archiveName" +mkdir -p bin +DMD=ldmd2 ldc2 -run ./build.d -release ${LDC_XDFLAGS} + +cd bin +zip "$archiveName" "${BIN_NAME}.exe" diff --git a/scripts/ci/release.sh b/scripts/ci/release.sh new file mode 100755 index 0000000..65ac01f --- /dev/null +++ b/scripts/ci/release.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +set -eux -o pipefail + +# Get the directory root, which is two level ahead +ROOT_DIR="$( cd "$(dirname "${BASH_SOURCE[0]}")/../../" && pwd )" +cd ${ROOT_DIR} + +VERSION=$(git describe --abbrev=0 --tags) +ARCH="${ARCH:-64}" +CUSTOM_FLAGS=() +unameOut="$(uname -s)" +case "$unameOut" in + Linux*) + OS=linux + CUSTOM_FLAGS+=("-L--export-dynamic") + ;; + Darwin*) + OS=osx + CUSTOM_FLAGS+=("-L-dead_strip") + ;; + *) echo "Unknown OS: $unameOut"; exit 1 +esac + +if [[ $(basename "$DMD") =~ ldmd.* ]] ; then + CUSTOM_FLAGS+=("-flto=full") + # ld.gold is required on Linux + if [ ${OS:-} == "linux" ] ; then + CUSTOM_FLAGS+=("-linker=gold") + fi +fi + +case "$ARCH" in + 64) ARCH_SUFFIX="x86_64";; + 32) ARCH_SUFFIX="x86";; + *) echo "Unknown ARCH: $ARCH"; exit 1 +esac + +archiveName="dub-$VERSION-$OS-$ARCH_SUFFIX.tar.gz" + +echo "Building $archiveName" +DMD="$(command -v $DMD)" ./build.d -release -m$ARCH ${CUSTOM_FLAGS[@]} +tar cvfz "bin/$archiveName" -C bin dub diff --git a/scripts/ci/setup-ldc-windows.sh b/scripts/ci/setup-ldc-windows.sh new file mode 100644 index 0000000..efec21a --- /dev/null +++ b/scripts/ci/setup-ldc-windows.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +# sets up LDC for cross-compilation. Source this script, s.t. the new LDC is in PATH + +# Make sure this version matches the version of LDC2 used in .travis.yml, +# otherwise the compiler and the lib used might mismatch. +LDC_VERSION="1.19.0" +ARCH=${ARCH:-32} +VERSION=$(git describe --abbrev=0 --tags) +OS=windows + +# LDC should already be installed (see .travis.yml) +# However, we need the libraries, so download them +# We can't use the downloaded ldc2 itself, because obviously it's for Windows + +if [ "${ARCH}" == 64 ]; then + ARCH_SUFFIX='x86_64' + ZIP_ARCH_SUFFIX='x64' +else + ARCH_SUFFIX='i686' + ZIP_ARCH_SUFFIX='x86' +fi + +LDC_DIR_PATH="$(pwd)/ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}" +LDC_XDFLAGS="-conf=${LDC_DIR_PATH}/etc/ldc2.conf -mtriple=${ARCH_SUFFIX}-pc-windows-msvc" + +# Step 1: download the LDC Windows release +# Check if the user already have it (e.g. building locally) +if [ ! -d ${LDC_DIR_PATH} ]; then + if [ ! -d "ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}.7z" ]; then + wget "https://github.com/ldc-developers/ldc/releases/download/v${LDC_VERSION}/ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}.7z" + fi + 7z x "ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}.7z" > /dev/null +fi + +# Step 2: Generate a config file with the proper path +cat > ${LDC_DIR_PATH}/etc/ldc2.conf < 2.087.z ]; then + ./build.d -preview=dip1000 -w -g -debug +fi + +function clean() { + # Hard reset of the DUB local folder is necessary as some tests + # currently don't properly clean themselves + rm -rf ~/.dub + git clean -dxf -- test +} + +if [ "$COVERAGE" = true ]; then + # library-nonet fails to build with coverage (Issue 13742) + dub test --compiler=${DC} -b unittest-cov + ./build.d -cov + + wget https://codecov.io/bash -O codecov.sh + bash codecov.sh +else + ./build.d + DUB=`pwd`/bin/dub DC=${DC} test/run-unittest.sh +fi + +## Checks that only need to be done once per CI run +## Here the `COVERAGE` variable is abused for this purpose, +## as it's only defined once in the whole Travis matrix +if [ "$COVERAGE" = true ]; then + # run tests with different compilers + DUB=`pwd`/bin/dub DC=${DC} test/run-unittest.sh + clean + + export FRONTEND=2.077 + source $(~/dlang/install.sh ldc-1.7.0 --activate) + DUB=`pwd`/bin/dub DC=${DC} test/run-unittest.sh + deactivate + clean + + export FRONTEND=2.068 + source $(~/dlang/install.sh gdc-4.8.5 --activate) + DUB=`pwd`/bin/dub DC=${DC} test/run-unittest.sh + deactivate + + # check for trailing whitespace + find . -type f -name '*.d' -exec grep -Hn "[[:blank:]]$" {} \; + # check that the man page generation still works + source $(~/dlang/install.sh dmd --activate) + source $(~/dlang/install.sh dub --activate) + dub --single -v scripts/man/gen_man.d +fi diff --git a/semaphore-ci.sh b/semaphore-ci.sh index 94fc0aa..c942ed9 100755 --- a/semaphore-ci.sh +++ b/semaphore-ci.sh @@ -38,4 +38,4 @@ . $(curl --connect-timeout 5 --max-time 10 --retry 5 --retry-delay 1 --retry-max-time 60 https://dlang.org/install.sh | bash -s "$D_VERSION" -a) fi -./travis-ci.sh +./scripts/ci/travis.sh diff --git a/setup-ldc-windows.sh b/setup-ldc-windows.sh deleted file mode 100644 index efec21a..0000000 --- a/setup-ldc-windows.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash - -# sets up LDC for cross-compilation. Source this script, s.t. the new LDC is in PATH - -# Make sure this version matches the version of LDC2 used in .travis.yml, -# otherwise the compiler and the lib used might mismatch. -LDC_VERSION="1.19.0" -ARCH=${ARCH:-32} -VERSION=$(git describe --abbrev=0 --tags) -OS=windows - -# LDC should already be installed (see .travis.yml) -# However, we need the libraries, so download them -# We can't use the downloaded ldc2 itself, because obviously it's for Windows - -if [ "${ARCH}" == 64 ]; then - ARCH_SUFFIX='x86_64' - ZIP_ARCH_SUFFIX='x64' -else - ARCH_SUFFIX='i686' - ZIP_ARCH_SUFFIX='x86' -fi - -LDC_DIR_PATH="$(pwd)/ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}" -LDC_XDFLAGS="-conf=${LDC_DIR_PATH}/etc/ldc2.conf -mtriple=${ARCH_SUFFIX}-pc-windows-msvc" - -# Step 1: download the LDC Windows release -# Check if the user already have it (e.g. building locally) -if [ ! -d ${LDC_DIR_PATH} ]; then - if [ ! -d "ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}.7z" ]; then - wget "https://github.com/ldc-developers/ldc/releases/download/v${LDC_VERSION}/ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}.7z" - fi - 7z x "ldc2-${LDC_VERSION}-windows-${ZIP_ARCH_SUFFIX}.7z" > /dev/null -fi - -# Step 2: Generate a config file with the proper path -cat > ${LDC_DIR_PATH}/etc/ldc2.conf < 2.087.z ]; then - ./build.d -preview=dip1000 -w -g -debug -fi - -function clean() { - # Hard reset of the DUB local folder is necessary as some tests - # currently don't properly clean themselves - rm -rf ~/.dub - git clean -dxf -- test -} - -if [ "$COVERAGE" = true ]; then - # library-nonet fails to build with coverage (Issue 13742) - dub test --compiler=${DC} -b unittest-cov - ./build.d -cov - - wget https://codecov.io/bash -O codecov.sh - bash codecov.sh -else - ./build.d - DUB=`pwd`/bin/dub DC=${DC} test/run-unittest.sh -fi - -## Checks that only need to be done once per CI run -## Here the `COVERAGE` variable is abused for this purpose, -## as it's only defined once in the whole Travis matrix -if [ "$COVERAGE" = true ]; then - # run tests with different compilers - DUB=`pwd`/bin/dub DC=${DC} test/run-unittest.sh - clean - - export FRONTEND=2.077 - source $(~/dlang/install.sh ldc-1.7.0 --activate) - DUB=`pwd`/bin/dub DC=${DC} test/run-unittest.sh - deactivate - clean - - export FRONTEND=2.068 - source $(~/dlang/install.sh gdc-4.8.5 --activate) - DUB=`pwd`/bin/dub DC=${DC} test/run-unittest.sh - deactivate - - # check for trailing whitespace - find . -type f -name '*.d' -exec grep -Hn "[[:blank:]]$" {} \; - # check that the man page generation still works - source $(~/dlang/install.sh dmd --activate) - source $(~/dlang/install.sh dub --activate) - dub --single -v scripts/man/gen_man.d -fi