_stati64 patch (Was: [PATCH] Fix include path separator)

Joshua Watt jpewhacker@gmail.com
Tue Jan 1 00:00:00 GMT 2019


On Mon, Jul 15, 2019 at 5:27 PM Mark Wielaard <mark@klomp.org> wrote:
>
> Hi Joshua,
>
> On Mon, 2019-07-15 at 08:58 -0500, Joshua Watt wrote:
> > On 7/14/19 4:23 PM, Mark Wielaard wrote:
> > >
> > > That is really awesome. Thanks so much for testing that out.
> > > Can a cross build bzip2 using MinGw (and msys) be run under Wine?
> > > That might give us a build CI pipeline for testing bzip2 using the
> > > buildbot. It might not be identical to running under actual Windows.
> > > But it might be scripted/automated.
> >
> > We do something similar to that to test our MinGW SDKs for the Yocto
> > Project. We cross compile the SDK using the MinGW toolchain on Linux
> > (note that MSYS is not required; the Linux system already has all the
> > POSIX tools), then run a set of automated tests under Wine.
>
> OK nice. So for testing you can just use the normal scripts/tools, just
> make sure the binary itself is ran through wine?

correct

>
> > You might be able to take this approach also. It wouldn't verify that
> > you can actually compile under Windows (as stated, it is a cross compile
> > from Linux), but it would give some amount of confidence that you can
> > actually run the cross compiled bzip2 on Windows and it will pass the
> > tests. You are correct that Wine isn't a fully faithful reproduction of
> > Windows; I've found a few things that just refuse to run properly under
> > wine, but do fine on actual Windows.
>
> Right. We only want to test that it builds as if for Windows. That is
> test the code with BZ_UNIX 0 and BZ_LCCWIN32 1 compiles correctly.
>
> > Most distros have a ready-made MinGW GCC compiler that can be installed.
> > The harder part is getting any additional dependencies. Most of the
> > distros I've seen don't have very many of the MinGW cross compiled
> > library (why would they?) so if your trying to cross compile a large
> > codebase, you can easily get into trouble with missing dependencies. The
> > Yocto project has an advantage in this regard because we are already
> > compiling everything from source anyway, so cross compiling the
> > requisite dependencies for MinGW isn't any additional work. I think that
> > bzip2 might also be able to be cross compiled easily because it doesn't
> > have very many dependencies.
>
> As far as I know bzip2 really shouldn't have any dependencies except
> for what is provided by MinGW GCC itself.
>
> > If you want to verify that you can compile under Windows, you might be
> > able to install MSVC in wine and use it to build bzip2. You *might* also
> > be able to install the Windows version of MinGW and MSYS in wine. I
> > don't know how stable this would be or if it would work at all.
>
> Both may go a bit too far. Just being able to (cross) compile to a
> Windows binary and then check it works as expected seems all that is
> really necessary to make sure we don't break thing (too much).
>
> Lets see... So I installed mingw32-gcc and wine for my distro.
>
> $ make CC=i686-w64-mingw32-gcc
> [... mostly seems to work ...]
> i686-w64-mingw32-gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64  -o
> bzip2 bzip2.o -L. -lbz2
> ./libbz2.a: error adding symbols: Archive has no index; run ranlib to
> add one
> collect2: error: ld returned 1 exit status
> make: *** [bzip2] Error 1
>
> OK, that is odd, but lets do what it says:
> $ i686-w64-mingw32-ranlib ./libbz2.a
>
> $ i686-w64-mingw32-gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 \
>                        -o bzip2 bzip2.o -L. -lbz2
>
> $ file bzip2
> ./bzip2: PE32 executable (console) Intel 80386, for MS Windows
>
> Nice!
>
> But...
> $ wine ./bzip2
> wine: Bad EXE format for Z:\home\mark\src\bzip2-work\bzip2..
>
> OK, apparently I needed mingw64-gcc.
>
> So, same as above with make CC=i686-w64-mingw32-gcc
> x86_64-w64-mingw32-ranlib ./libbz2.a and
> x86_64-w64-mingw32-gcc -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64  -o
> bzip2 bzip2.o -L. -lbz2

I think some of the distro support for MinGW is a little quirky.

I ran into these same issues with ranlib and the executable not
running. It's been a while, but I *think* that you can compile for
32-bit windows by always using the 64-bit compiler, but telling it to
produce 32-bit executables, i.e.:

 CC="x86_64-w64-mingw32-gcc -m32"

I never was able to dig up an actual 32-bit install of Windows to test
that it would actually run there though. I also suspect that only
supporting 64-bit would be acceptable at this point, so it may not
matter too much.

>
> $ file bzip2
> bzip2: PE32+ executable (console) x86-64, for MS Windows
>
> $ wine ./bzip2 --help
> bzip2, a block-sorting file compressor.  Version 1.0.8, 13-Jul-2019.
>
>    usage: bzip2 [flags and input files in any order]
>
>    -h --help           print this message
>    -d --decompress     force decompression
>    -z --compress       force compression
>    -k --keep           keep (don't delete) input files
>    -f --force          overwrite existing output files
>    -t --test           test compressed file integrity
>    -c --stdout         output to standard out
>    -q --quiet          suppress noncritical error messages
>    -v --verbose        be verbose (a 2nd -v gives more)
>    -L --license        display software version & license
>    -V --version        display software version & license
>    -s --small          use less memory (at most 2500k)
>    -1 .. -9            set block size to 100k .. 900k
>    --fast              alias for -1
>    --best              alias for -9
>
>    If invoked as `bzip2', default action is to compress.
>               as `bunzip2',  default action is to decompress.
>               as `bzcat', default action is to decompress to stdout.
>
>    If no file names are given, bzip2 compresses or decompresses
>    from standard input to standard output.  You can combine
>    short flags, so `-v -4' means the same as -v4 or -4v, &c.
>
>
> That is so awesome! Even though I am not exactly sure what I did.
> But it seems possible with some tweaks to get this working.
>
> Could you share some hints and tips on your setup? Or simply explain
> what went wrong in the above or what accidentally worked and why?
>
> Also is there a "command line wine"?

Not really. Much like Windows proper, wine includes the whole GUI
library. The only way to not show any of the GUI is to be careful not
to invoke any programs that might show it.

> The first time you run wine it seems to spawn all kinds of windows
> setup thingies. That would work on the buildbots of course.

You can still do everything that you care about on the buildbots,
since bzip2 doesn't actually do anything with the GUI, it won't be
displayed.
There are two environment variables you want to set, WINEPREFIX and
WINEARCH. See https://linuxconfig.org/using-wine-prefixes .

In your CI tests you will want to do something like this:

 export WINEPREFIX=$(mktemp -d) # Make a new empty wine installation
(a.k.a bottle)
 export WINEARCH=win64 # Make the new bottle a 64-bit install... can
also be win32 for a 32-bit install.
 wine ./bzip2 # Run bzip2 in the new bottle

This ensures you get a fresh wine install with the default
configuration each time the CI job runs (of course, you may want to do
something other than mktemp -d for your temp dir).

>
> Thanks,
>
> Mark



More information about the Bzip2-devel mailing list