flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
163.12k stars 26.85k forks source link

Flutter preview device depends on VS debug dlls #142755

Open christopherfujino opened 5 months ago

christopherfujino commented 5 months ago

When running the dumpbin.exe tool on a compiled flutter_preview.exe to determine dynamically linked dependencies:

PS D:\git\flutter> & "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\Hostx64\x64\dumpbin.exe" /dependents .\bin\cache\artifacts\flutter_preview\flutter_preview.exe
Microsoft (R) COFF/PE Dumper Version 14.37.32825.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file .\bin\cache\artifacts\flutter_preview\flutter_preview.exe

File Type: EXECUTABLE IMAGE

  Image has the following dependencies:

    dwmapi.dll
    flutter_windows.dll
    KERNEL32.dll
    USER32.dll
    SHELL32.dll
    ole32.dll
    ADVAPI32.dll
    MSVCP140D.dll
    VCRUNTIME140D.dll
    VCRUNTIME140_1D.dll
    ucrtbased.dll

Of these, the following are commonly available on new Windows installation:

flutter_windows.dll is explicitly provided by the flutter tool. The following are not part of a new Windows installation, however, and are C/C++ debug libraries:

The first three of these are distributed with Visual Studio, in a directory marked "debug_nondredist" (see https://learn.microsoft.com/en-us/visualstudio/releases/2022/redistribution#visual-c-runtime-files).

The last, ucrtbased.dll, I found under C:\Program Files (x86)\WIndows Kits\10\bin...

christopherfujino commented 5 months ago

I attempted to link a release build of a Flutter C++ entrypoint to a debug engine, but got the following linker errors:

[        ] "D:\git\tmp\delete_me_flutter\build\windows\x64\INSTALL.vcxproj" (default target) (1) ->
[        ] "D:\git\tmp\delete_me_flutter\build\windows\x64\ALL_BUILD.vcxproj" (default target) (3) ->
[        ] "D:\git\tmp\delete_me_flutter\build\windows\x64\runner\delete_me_flutter.vcxproj" (default target) (4) ->
[        ] (Link target) ->
[        ]   flutter_wrapper_app.lib(core_implementations.obj) : error LNK2001: unresolved external symbol __imp__invalid_parameter [D:\git\tmp\delete_me_flutter\build\windows\x64\runner\delete_me_flutter.vcxproj]
[        ]   flutter_window.obj : error LNK2001: unresolved external symbol __imp__invalid_parameter [D:\git\tmp\delete_me_flutter\build\windows\x64\runner\delete_me_flutter.vcxproj]
[        ]   main.obj : error LNK2001: unresolved external symbol __imp__invalid_parameter [D:\git\tmp\delete_me_flutter\build\windows\x64\runner\delete_me_flutter.vcxproj]
[        ]   utils.obj : error LNK2001: unresolved external symbol __imp__invalid_parameter [D:\git\tmp\delete_me_flutter\build\windows\x64\runner\delete_me_flutter.vcxproj]
[        ]   flutter_wrapper_app.lib(flutter_engine.obj) : error LNK2001: unresolved external symbol __imp__invalid_parameter [D:\git\tmp\delete_me_flutter\build\windows\x64\runner\delete_me_flutter.vcxproj]
[        ]   flutter_wrapper_app.lib(core_implementations.obj) : error LNK2001: unresolved external symbol __imp__CrtDbgReport [D:\git\tmp\delete_me_flutter\build\windows\x64\runner\delete_me_flutter.vcxproj]
[        ]   flutter_window.obj : error LNK2001: unresolved external symbol __imp__CrtDbgReport [D:\git\tmp\delete_me_flutter\build\windows\x64\runner\delete_me_flutter.vcxproj]
[        ]   main.obj : error LNK2001: unresolved external symbol __imp__CrtDbgReport [D:\git\tmp\delete_me_flutter\build\windows\x64\runner\delete_me_flutter.vcxproj]
[        ]   utils.obj : error LNK2001: unresolved external symbol __imp__CrtDbgReport [D:\git\tmp\delete_me_flutter\build\windows\x64\runner\delete_me_flutter.vcxproj]
[        ]   flutter_wrapper_app.lib(flutter_engine.obj) : error LNK2001: unresolved external symbol __imp__CrtDbgReport [D:\git\tmp\delete_me_flutter\build\windows\x64\runner\delete_me_flutter.vcxproj]
[        ]   D:\git\tmp\delete_me_flutter\build\windows\x64\runner\Debug\delete_me_flutter.exe : fatal error LNK1120: 2 unresolved externals [D:\git\tmp\delete_me_flutter\build\windows\x64\runner\delete_me_flutter.vcxproj]
[        ]     0 Warning(s)
[        ]     11 Error(s)

Loic got similar errors with https://github.com/loic-sharma/flutter_raw_cpp, which is a pure C++/Visual Studio project that links to the debug flutter engine (link). This project succeeds in debug mode, but fails to link in release mode.

mkustermann commented 5 months ago

From a brief look:

The Dart dependencies on windows are listed here, they are due to process wide memory allocators, sockets, etc.

Flutter seems to have a copy_dlls step in the build root that copies various dlls (see here - which includes those non-dist dlls). This code in the buildroot is very old and therfore unclear for what it's needed (if it's still needed).

I don't know what "flutter preview device" is how how it's built, but it may be that it's build is linked against all those dlls that are copied by the build root scripts.

christopherfujino commented 4 months ago

I don't know what "flutter preview device" is how how it's built, but it may be that it's build is linked against all those dlls that are copied by the build root scripts.

Right, this is not (directly) related to the engine or Dart VM, but the way we build the preview device's main.cc entrypoint. The Preview Device is essentially a debug build of the Flutter counter app for Windows, so we use the open source toolchain (CMake, MSBuild, VS compiler).

flutter-triage-bot[bot] commented 3 weeks ago

This issue is marked P1 but has had no recent status updates.

The P1 label indicates high-priority issues that are at the top of the work list. This is the highest priority level a bug can have if it isn't affecting a top-tier customer or breaking the build. Bugs marked P1 are generally actively being worked on unless the assignee is dealing with a P0 bug (or another P1 bug). Issues at this level should be resolved in a matter of months and should have monthly updates on GitHub.

Please consider where this bug really falls in our current priorities, and label it or assign it accordingly. This allows people to have a clearer picture of what work is actually planned. Thanks!