genometools icon indicating copy to clipboard operation
genometools copied to clipboard

GenomeTools Windows Port

Open gordon opened this issue 12 years ago • 8 comments

I'm currently porting GenomeTools to Windows (MinGW). Some notes can be found here: https://github.com/genometools/genometools/wiki/GenomeTools-Windows-Port I'm pushing in this branch: https://github.com/gordon/genometools/tree/windows It's not ready for a pull request, though. Comments welcome.

gordon avatar Aug 24 '13 21:08 gordon

Nice! I will have a look at it tomorrow.

satta avatar Aug 24 '13 23:08 satta

Cool. But don't bother with mmap(), I already know how to do it and will code it tomorrow as well.

gordon avatar Aug 25 '13 00:08 gordon

mmap() is ported now and it is possible to compile libgenometools with

scripts/build_windows.sh lib/libgenometools.a

and compiling the gt binary with

scripts/build_windows.sh bin/gt

also works. The libarary contains all subdirectories, but there are multiple places where I just outcommented the UNIX specific code. For example, process forking for Windows is missing completely.

I think we should pull this into the master soon so that others can contribute to the port. Any opinions on this?

gordon avatar Aug 25 '13 13:08 gordon

Thanks for the initial work!

satta avatar Sep 08 '13 14:09 satta

I am just using fileutils, and I am extending it by a function that concatenates dir, basename and suffix. I was thinking about different dir separators in *NIX Windows. Do we have to worry about that?

Garonenur avatar Sep 20 '13 14:09 Garonenur

Yes, please use the defines from core/compat.h.

gordon avatar Sep 20 '13 14:09 gordon

thanks, found it, and aborted the plan for concatenation. Variable number of parameters is too problematic, and using GtStr anyone can concatenate strings easily.

Garonenur avatar Sep 20 '13 15:09 Garonenur

@stefan-kurtz asked on #863 about the missing parts for the Windows port of GenomeTools, let's continue the discussion here. A few more notes for whomever wants to continue working on a native port for Windows (that is, one which can be compiled with MinGW directly and doesn't depend on a POSIX compatibility layer provided by Cygwin):

  • Travis does only checks that the code compiles for Windows (by cross-compiling it with mingw-gcc), it doesn't check that it actually works.
  • In the past I pushed it to the point that everything GenomeThreader depends on works, that's why there is a native binary of GenomeThreader for Windows.
  • The Travis test makes sure that the GenomeTools code still compiles on Windows.

Things that have to be considered when porting to Windows

  • Windows has different path separators. Use the defines in https://github.com/genometools/genometools/blob/master/src/core/compat.h for that.
  • Windows hat different line endings (\r\n instead of \n). Code that doesn't take that into account will fail.
  • The native C compiler on Windows (Visual Studio) only supports C89 and not C99. Since we are only targetting MinGW at this point it doesn't matter, but it is good to keep that in mind to not make the problem worse. For example, in C89 there is no stdbool.h header.
  • POSIX functions are not available on Windows, they have to be wrapped into a compatibility layer and their functionality implemented with the Windows API. That's usually possible, but a bit cumbersome.

How to do a full port to Windows

  • Grep for all occurences of _WIN32 in the source which is not in compat.[ch]. Create a wrapper function for the corresponding POSIX function and look for an equivalent Windows API function. Implement the wrapper for Windows as well (with ifdef _WIN32 in compat.c).

How to test the code

  1. On Linux compile with mingw32-gcc (as done in https://github.com/genometools/genometools/blob/master/.travis.yml). You can probably test most of the code by using Wine. That is, compile the 32-bit version with MinGW and then call the binary with wine gt.

  2. Compile natively on Windows with MinGW.

Even if the code is developed and tested on Linux (with Wine) it has to be tested on Windows natively! For that one has to figure out how to get the test suite running on Windows, maybe one can install Ruby with pacman as well.

How to setup your MinGW environment on Windows

  1. Download the MSYS2 installer from http://www.msys2.org/ (usually you want the x86_64 installer no matter what you want to compile, unless you are still running a 32bit version of Windows).
  2. Run the installer and install MSYS2 into C:\msys64 (or C:\msys32 for the 32bit version) and launch the MSYS2 shell (C:\msys64\msys2).
  3. In the MSYS2 shell enter: pacman -Sy pacman (to update the package DB and pacman)
  4. Close the MSYS2 shell and launch it again (C:\msys64\msys2). In the MSYS2 shell enter: pacman -Syu (to update the package DB and install the core system packages).
  5. Close the MSYS2 shell and launch it again (C:\msys64\msys2). Update the rest with pacman -Su
  6. Close the MSYS2 shell and launch it again (C:\msys64\msys2). Install MinGW 64bit: pacman -S mingw-w64-x86_64-gcc (to compile for 64bit). Install MinGW 32bit: pacman -S mingw-w64-i686-gcc (to compile for 32bit).
  7. Install make: pacman -S make.
  8. Optionally install any libraries/tools you may need. You can search the repository by pacman -Ss name_of_package and install a package by pacman -S name_of_package.
  9. To compile the GenomeTools for Windows (MinGW) 64bit lauch C:\msys64\mingw64 and for 32bit launch C:\msys64\mingw32

If you start working on that, please start sending small pull requests immediately and do not wait until the whole thing is finished. That way we can give early feedback. PRs are fine as long as they still compile and do not break anything for Linux and Mac.

gordon avatar Jun 12 '17 21:06 gordon