Skip to content

Commit

Permalink
Improve windows build.
Browse files Browse the repository at this point in the history
Specifically we create the extra files needed for MSVC linkage, and
document the MSYS2/MINGW setup process.

Also added a win-dist target which attempts to produce a directory
structure suitable for binary distribution.  This isn't executed by
default, but is a good aide-memoire and to simplify testing
compatibility with things like MSVC.

Ideally we'd have a similar mechanism for all platforms to permit easy
creation of binary distributions (see samtools#533).
  • Loading branch information
jkbonfield committed Jan 18, 2022
1 parent 4289991 commit 255cf57
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ install:
- set MSYSTEM=MINGW64
- set PATH=C:/msys64/usr/bin;C:/msys64/mingw64/bin;%PATH%
- set MINGWPREFIX=x86_64-w64-mingw32
- "sh -lc \"pacman -S --noconfirm --needed base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-autotools mingw-w64-x86_64-zlib mingw-w64-x86_64-bzip2 mingw-w64-x86_64-xz mingw-w64-x86_64-curl\""
- "sh -lc \"pacman -S --noconfirm --needed base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-autotools mingw-w64-x86_64-zlib mingw-w64-x86_64-bzip2 mingw-w64-x86_64-xz mingw-w64-x86_64-curl mingw-w64-x86_64-tools-git mingw-w64-x86_64-llvm\""

build_script:
- set HOME=.
Expand Down
21 changes: 21 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,24 @@ OpenSUSE
--------

sudo zypper install autoconf automake make gcc perl zlib-devel libbz2-devel xz-devel libcurl-devel libopenssl-devel

Windows MSYS2/MINGW64
---------------------

Follow MSYS2 installation instructions at
https://www.msys2.org/wiki/MSYS2-installation/

Then relaunch to MSYS2 shell using the "MSYS2 MinGW x64" executable.
Once in that environment (check $MSYSTEM equals "MINGW64") install the
compilers using pacman -S and the following package list:

base-devel mingw-w64-x86_64-toolchain
mingw-w64-x86_64-libdeflate mingw-w64-x86_64-zlib mingw-w64-x86_64-bzip2
mingw-w64-x86_64-xz mingw-w64-x86_64-curl mingw-w64-x86_64-autotools
mingw-w64-x86_64-tools-git mingw-w64-x86_64-llvm

(Those last two install gendef and llvm-dlltool and are only needed
for building libraries compatible with MSVC.)

A working binary distribution may then be made using "./configure &&
make win-dist". Building without autoconf is not supported on Windows.
38 changes: 36 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ SHLIB_FLAVOUR = cygdll
lib-shared: cyghts-$(LIBHTS_SOVERSION).dll
else ifeq "$(findstring MSYS,$(PLATFORM))" "MSYS"
SHLIB_FLAVOUR = dll
lib-shared: hts-$(LIBHTS_SOVERSION).dll
lib-shared: hts-$(LIBHTS_SOVERSION).lib
else ifeq "$(findstring MINGW,$(PLATFORM))" "MINGW"
SHLIB_FLAVOUR = dll
lib-shared: hts-$(LIBHTS_SOVERSION).dll
lib-shared: hts-$(LIBHTS_SOVERSION).lib
else
SHLIB_FLAVOUR = so
lib-shared: libhts.so
Expand Down Expand Up @@ -330,6 +330,40 @@ cyghts-$(LIBHTS_SOVERSION).dll libhts.dll.a: $(LIBHTS_OBJS)
hts-$(LIBHTS_SOVERSION).dll hts.dll.a: $(LIBHTS_OBJS)
$(CC) -shared -Wl,--out-implib=hts.dll.a -Wl,--enable-auto-import -Wl,--exclude-all-symbols $(LDFLAGS) -o $@ -Wl,--whole-archive $(LIBHTS_OBJS) -Wl,--no-whole-archive $(LIBS) -lpthread

hts-$(LIBHTS_SOVERSION).def: hts-$(LIBHTS_SOVERSION).dll
gendef hts-$(LIBHTS_SOVERSION).dll

hts-$(LIBHTS_SOVERSION).lib: hts-$(LIBHTS_SOVERSION).def
llvm-dlltool -m i386:x86-64 -d hts-$(LIBHTS_SOVERSION).def -l hts-$(LIBHTS_SOVERSION).lib

# Bundling libraries, binaries, dll dependencies, and licenses into a
# single directory.
#
# NOTE: only tested on the supported MSYS2/MINGW64 environment.
dist-windows: DESTDIR=
dist-windows: prefix=dist-windows
dist-windows: install
cp hts-$(LIBHTS_SOVERSION).def hts-$(LIBHTS_SOVERSION).lib dist-windows/lib
cp `ldd hts-$(LIBHTS_SOVERSION).dll| awk '/mingw64/ {print $$3}'` dist-windows/bin
mkdir -p dist-windows/share/licenses/htslib
cp -r /mingw64/share/licenses/mingw-w64-libraries \
/mingw64/share/licenses/brotli \
/mingw64/share/licenses/bzip2 \
/mingw64/share/licenses/gcc-libs \
/mingw64/share/licenses/libdeflate \
/mingw64/share/licenses/libpsl \
/mingw64/share/licenses/libtre \
/mingw64/share/licenses/libwinpthread \
/mingw64/share/licenses/openssl \
/mingw64/share/licenses/xz \
/mingw64/share/licenses/zlib \
/mingw64/share/licenses/zstd \
dist-windows/share/licenses/
cp -r /usr/share/licenses/curl \
dist-windows/share/licenses/
cp LICENSE dist-windows/share/licenses/htslib/


# Target to allow htslib.mk to build all the object files before it
# links the shared and static libraries.
hts-object-files: $(LIBHTS_OBJS)
Expand Down

0 comments on commit 255cf57

Please sign in to comment.