Skip to content

Commit

Permalink
Build win{32,64} binaries with LDC
Browse files Browse the repository at this point in the history
  • Loading branch information
wilzbach authored and Basile-z committed Apr 1, 2019
1 parent 313b886 commit 793a575
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 26 deletions.
43 changes: 31 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
include:
- stage: GitHub Release
#if: tag IS present
d: ldc-1.8.0
d: ldc-1.13.0
os: linux
script: echo "Deploying to GitHub releases ..." && ./release.sh
deploy:
Expand All @@ -37,7 +37,7 @@ jobs:
tags: true
- stage: GitHub Release
#if: tag IS present
d: ldc-1.8.0
d: ldc-1.13.0
os: osx
script: echo "Deploying to GitHub releases ..." && ./release.sh
deploy:
Expand All @@ -60,16 +60,35 @@ jobs:
apt:
packages:
- p7zip-full
- wine
deploy:
provider: releases
api_key: $GH_REPO_TOKEN
file_glob: true
file: bin/dfmt-*.zip
skip_cleanup: true
on:
repo: dlang-community/dfmt
tags: true
deploy:
provider: releases
api_key: $GH_REPO_TOKEN
file_glob: true
file: bin/dfmt-*.zip
skip_cleanup: true
on:
repo: dlang-community/dfmt
tags: true
- stage: GitHub Release
#if: tag IS present
d: dmd
os: linux
language: generic
sudo: yes
script: echo "Deploying to GitHub releases ..." && ARCH=64 ./release-windows.sh
addons:
apt:
packages:
- p7zip-full
deploy:
provider: releases
api_key: $GH_REPO_TOKEN
file_glob: true
file: bin/dfmt-*.zip
skip_cleanup: true
on:
repo: dlang-community/dfmt
tags: true
stages:
- name: test
if: type = pull_request or (type = push and branch = master)
3 changes: 3 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ DMD_FLAGS := -O -inline $(DMD_COMMON_FLAGS)
DMD_TEST_FLAGS := -unittest -g $(DMD_COMMON_FLAGS)
LDC_FLAGS := -g -w -oq $(INCLUDE_PATHS)
GDC_FLAGS := -g -w -oq $(INCLUDE_PATHS)
override DMD_FLAGS += $(DFLAGS)
override LDC_FLAGS += $(DFLAGS)
override GDC_FLAGS += $(DFLAGS)
DC ?= dmd
LDC ?= ldc2
GDC ?= gdc
Expand Down
23 changes: 9 additions & 14 deletions release-windows.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
#!/usr/bin/env bash
# Build the Windows binaries under Linux (requires wine)
# Build the Windows binaries under Linux
set -eux -o pipefail
VERSION=$(git describe --abbrev=0 --tags)
OS=windows
ARCH_SUFFIX="x86"

BIN_NAME=dfmt

# Allow the script to be run from anywhere
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR

# Step 1: download the DMD binaries
if [ ! -d dmd2 ] ; then
wget http://downloads.dlang.org/releases/2.x/2.079.0/dmd.2.079.0.windows.7z
7z x dmd.2.079.0.windows.7z > /dev/null
fi
source setup-ldc-windows.sh

# Step 2: Run DMD via wineconsole
archiveName="dfmt-$VERSION-$OS-$ARCH_SUFFIX.zip"
# Run LDC with cross-compilation
archiveName="$BIN_NAME-$VERSION-$OS-$ARCH_SUFFIX.zip"
echo "Building $archiveName"
mkdir -p bin
git describe --tags > bin/githash.txt # no git installed under Wine
DC="$DIR/dmd2/windows/bin/dmd.exe" wine cmd /C build.bat
DC=ldmd2 make ldc

cd bin
zip "$archiveName" dfmt.exe
mv "${BIN_NAME}" "${BIN_NAME}.exe"
zip "$archiveName" "${BIN_NAME}.exe"
70 changes: 70 additions & 0 deletions setup-ldc-windows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash

# sets up LDC for cross-compilation. Source this script, s.t. the new LDC is in PATH

LDC_VERSION="1.13.0"
ARCH=${ARCH:-32}
VERSION=$(git describe --abbrev=0 --tags)
OS=windows

# Step 0: install ldc
if [ ! -f install.sh ] ; then
wget https://dlang.org/install.sh
fi
. $(bash ./install.sh -a "ldc-${LDC_VERSION}")

# for the install.sh script only
LDC_PATH="$(dirname $(dirname $(which ldc2)))"

# Step 1a: download the LDC x64 windows binaries
if [ "${ARCH}" == 64 ] && [ ! -d "ldc2-${LDC_VERSION}-windows-x64" ] ; then
wget "https://github.com/ldc-developers/ldc/releases/download/v1.13.0/ldc2-${LDC_VERSION}-windows-x64.7z"
7z x "ldc2-${LDC_VERSION}-windows-x64.7z" > /dev/null
# Step 2a: Add LDC windows binaries to LDC Linux
if [ ! -d "${LDC_PATH}/lib-win64" ] ; then
cp -r ldc2-1.13.0-windows-x64/lib "${LDC_PATH}/lib-win64"
cat >> "$LDC_PATH"/etc/ldc2.conf <<EOF
"x86_64-.*-windows-msvc":
{
switches = [
"-defaultlib=phobos2-ldc,druntime-ldc",
"-link-defaultlib-shared=false",
];
lib-dirs = [
"%%ldcbinarypath%%/../lib-win64",
];
};
EOF
fi
fi
# Step 1b: download the LDC x86 windows binaries
if [ "${ARCH}" == 32 ] && [ ! -d "ldc2-${LDC_VERSION}-windows-x86" ] ; then
wget "https://github.com/ldc-developers/ldc/releases/download/v1.13.0/ldc2-${LDC_VERSION}-windows-x86.7z"
7z x "ldc2-${LDC_VERSION}-windows-x86.7z" > /dev/null
# Step 2b: Add LDC windows binaries to LDC Linux
if [ ! -d "${LDC_PATH}/lib-win32" ] ; then
cp -r ldc2-1.13.0-windows-x86/lib "${LDC_PATH}/lib-win32"
cat >> "$LDC_PATH"/etc/ldc2.conf <<EOF
"i686-.*-windows-msvc":
{
switches = [
"-defaultlib=phobos2-ldc,druntime-ldc",
"-link-defaultlib-shared=false",
];
lib-dirs = [
"%%ldcbinarypath%%/../lib-win32",
];
};
EOF
fi
fi

# set suffices and compilation flags
if [ "$ARCH" == "64" ] ; then
ARCH_SUFFIX="x86_64"
export DFLAGS="-mtriple=x86_64-windows-msvc"
else
ARCH_SUFFIX="x86"
export DFLAGS="-mtriple=i686-windows-msvc"
fi

0 comments on commit 793a575

Please sign in to comment.