Skip to content

Commit

Permalink
Avoid compilation errors for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
torognes committed Sep 11, 2024
1 parent 2801e61 commit 35d9e00
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/shuffle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ auto shuffle_deck(std::vector<int> & deck, long int const user_seed) -> void {

auto truncate_deck(std::vector<int> & deck,
long int const n_first_sequences) -> void {
auto const final_size = std::min(deck.size(),
static_cast<unsigned long>(n_first_sequences));
deck.resize(final_size);
if (deck.size() > static_cast<unsigned long>(n_first_sequences))
deck.resize(n_first_sequences);
}


Expand Down
5 changes: 2 additions & 3 deletions src/sortbylength.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,8 @@ auto output_median_length(std::vector<struct sortinfo_length_s> const & deck,

auto truncate_deck(std::vector<struct sortinfo_length_s> &deck,
long int const n_first_sequences) -> void {
auto const final_size = std::min(deck.size(),
static_cast<unsigned long>(n_first_sequences));
deck.resize(final_size);
if (deck.size() > static_cast<unsigned long>(n_first_sequences))
deck.resize(n_first_sequences);
}


Expand Down
5 changes: 2 additions & 3 deletions src/sortbysize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ auto output_median_abundance(std::vector<sortinfo_size_s> const & deck,

auto truncate_deck(std::vector<struct sortinfo_size_s> & deck,
long int const n_first_sequences) -> void {
auto const final_size = std::min(deck.size(),
static_cast<unsigned long>(n_first_sequences));
deck.resize(final_size);
if (deck.size() > static_cast<unsigned long>(n_first_sequences))
deck.resize(n_first_sequences);
}


Expand Down

3 comments on commit 35d9e00

@frederic-mahe
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @torognes !

How do you cross-compile for Windows? Maybe I can add that specific cross-compilation to my dev-tests? That would allow me to detect issues as the one above earlier, and avoid pushing them to the repository.

@torognes
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @frederic-mahe !

To compile for Windows, from my Mac, I build a Docker container with a Linux setup and use the g++ cross compiler. Here is the Dockerfile that does it all:

FROM debian:stable

# Quickly build vsearch for windows/x86_64 platform using cross-compilation

RUN apt update && apt -y upgrade && apt -y install \
        automake \
        g++ \
        ghostscript \
        groff \
        libz-mingw-w64-dev \
        make \
        mingw-w64 \
        wget \
        zstd

WORKDIR /opt/vsearch
COPY . .

# Get bz2 and zlib headers and dll's for Windows
RUN wget https://ftp.accum.se/mirror/msys2.org/mingw/mingw64/mingw-w64-x86_64-bzip2-1.0.8-3-any.pkg.tar.zst
RUN tar xvf mingw-w64-x86_64-bzip2-1.0.8-3-any.pkg.tar.zst --zstd
RUN cp -a mingw64/include/bzlib.h /usr/x86_64-w64-mingw32/include
RUN mkdir bin
RUN cp -a mingw64/bin/libbz2-1.dll bin/libbz2.dll
RUN cp -a /usr/x86_64-w64-mingw32/lib/zlib1.dll bin/zlib1.dll

RUN ./autogen.sh
RUN ./configure CFLAGS="-O3" CXXFLAGS="-O3" --host=x86_64-w64-mingw32
RUN make clean
RUN make -j 6 ARFLAGS="cr"
RUN cp -a bin/vsearch.exe bin/vsearch-win-x86_64.exe

# Check that the compression libraries are working well
RUN apt-get install -y wine
RUN wine --version
RUN wine bin/vsearch.exe -v

As you see, packages are installed and downloaded to get the bzip2 and gz compression libraries for windows (mingw64).

I run configure with --host=x86_64-w64-mingw32 to activate the cross compiler.

The script also tests that the resulting binary at least runs using the wine emulator.

Should be easier on a Linux box, but you see which packages are required.

@frederic-mahe
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @torognes !

Please sign in to comment.