mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.51k stars 1.6k forks source link

sizeof tests fail on windows 8.1 with MSVC (VS 14 build tools) #2985

Open kkartaltepe opened 6 years ago

kkartaltepe commented 6 years ago

I hope this is the right place to log this bug. If not please point me in the right direction.

Using ninja backend the sizeof test case builds in debug mode and links against the windows c debug runtime. Since ucrtbased.dll is not intended to be installed execution of the test cases fails.

Ideally this test would either use release mode to link against ucrtbase.dll which should be installed and available or use an alternate method of return so as not to require linking against the c runtime at all.

Installing the ucrtbased.dll globally works around the issue but is not a solution.

Example output logged when error occurs (I use cygwin for my terminal but I use the native toolchain)

Running compile:
Working directory:  D:\windows_programs\cygwin\tmp\tmpcqq593nt
Command line:  cl D:\windows_programs\cygwin\tmp\tmpcqq593nt\testfile.c /MDd /Od kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /nologo /showIncludes /FeD:\windows_programs\cygwin\tmp\tmpcqq593nt\output.exe 

Code:
 #include<stdio.h>

        int main(int argc, char **argv) {
            printf("%ld\n", (long)(sizeof(char)));
            return 0;
        };
Compiler stdout:
 testfile.c
Note: including file: C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\stdio.h
Note: including file:  C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\corecrt.h
Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vcruntime.h
Note: including file:    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\sal.h
Note: including file:     C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\ConcurrencySal.h
Note: including file:    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vadefs.h
Note: including file:  C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\corecrt_wstdio.h
Note: including file:   C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\corecrt_stdio_config.h

Compiler stderr:

Program stdout:

Program stderr:
nirbheek commented 6 years ago

Since ucrtbased.dll is not intended to be installed execution of the test cases fails.

So the dll is not in PATH, but the .lib is in the library search path, so the tests link against the .lib and can't find the dll?

That's strange. Why does MSVC in debug mode have such a broken setup? How do people run executables linked in debug mode?

FWIW, I have not seen this problem on Windows 8.1 with VS14 in debug mode.

kkartaltepe commented 6 years ago

I do not use cmd/powershell so it may be a case of env vars not propagating to meson's testing process. I believe this DLL may be picked up in a normal build from %LIB% (windows LD_LIBRARY_PATH equivalent) (Which is set in my shell but not set globally, similarly to how the MSVC Build Tools command prompts set up environment variables). I havnt tested with the Build Tools command prompts but I suspect that will also display this issue.

--Edit-- I have confirmed the issue also appears when using the MSVC Build Tools command prompt. Most likely it is due to how meson calls out to the start the process in both my case and the case when using a real cmd instance. It probably does not inherit the environment variables.

nirbheek commented 6 years ago

What are the detailed steps to reproduce this? Starting with which build tools cmd.exe you ran, what VS version you have installed (community or enterprise), etc.

It would also be useful to attach the output of set from inside the cmd.exe env.

kkartaltepe commented 6 years ago

pre) Confirm you do not have some ill begotten ucrtbased.dll in %WINDIR%/system32 1) Install VS14 build tools. Available here http://landinghub.visualstudio.com/visual-cpp-build-tools 2) run native x64 build prompt 3) attempt to compile any meson project that requires these checks (for example glib) 4) Confirm config.h does not specify the size of computed values (such as SIZEOF_SIZE_T) 5) Cry because meson doesnt bother to report it failed to even run the check.

kkartaltepe commented 6 years ago

I've been redoing my build process. so i went ahead and checked up on this and its still occurring. Though it looks like the error is being reported and is due to urctbased as expected example of recent compilation attempt: https://i.imgur.com/HBHP4QJ.png output of set: https://gist.github.com/kkartaltepe/d68355f72a0059f88caa4c220c83c2d6

Still on the same toolchain, compiling x64 to x86 currently. It looks like it wasnt mentioned earlier but this is using the ninja backend and not the VS backend.

pwnorbitals commented 3 years ago

@kkartaltepe, is this still happening now ?

kkartaltepe commented 3 years ago

I dont have have a windows machine to compile on or the intention to get one again in the immediate future. Likely its neigh impossible to acquire either windows 8.1 or vs14 build tools though, I dont know if it affected other versions of the compiler or other platforms.

--- edit anyone with a windows platform can try I was simply building an unmodified glib https://gitlab.gnome.org/GNOME/glib

--- edit2 It may require setting the build to debug instead of debugoptimized, im not sure if that default had changed since I first made this report. But in debugoptimized I dont think msvc will link the debug urctd and will instead use the regular and available ucrt.