linebender / piet

An abstraction for 2D graphics.
Apache License 2.0
1.23k stars 95 forks source link

Is it possible to link d2d1 statically on Windows? #443

Open ngugcx opened 3 years ago

ngugcx commented 3 years ago

I want to build a single file app with druid on Windows. But druid depends on direct2d, d2d1.dll is dynamically linked.

raphlinus commented 3 years ago

It's getting that DLL from the system, it's not bundled with the executable. Is there a specific problem you're trying to solve here?

ngugcx commented 3 years ago

@raphlinus , I built my app(based on druid) on Windows 10 with "-C target-feature=+crt-static". It failed to run on Windows 7 because of missing d2d1.dll and api-ms-win-core-libraryloader-l1-2-0.dll. I have no idea why it needs api-ms-win-core-libraryloader-l1-2-0.dll. I can't find it even on my Windows 10 system, there is only api-ms-win-core-libraryloader-l1-1-0.dll, that's weird.

I wonder if linking d2d1 statically will solve the problem.

raphlinus commented 3 years ago

I don't understand all subtleties in linking and packaging. To be honest, when testing on Windows 7 I always build on Windows 7, but I definitely see the value in being able to distribute a binary that can run across multiple versions.

From what I do understand, it seems unlikely that statically linking would solve the problem. I can't imagine that a version of d2d1 for Windows 10 would work on Windows 7, and can imagine other problems.

ngugcx commented 3 years ago

I made a mistake, there IS a d2d1.dll shipped with Windows 7 system. My app fails with:

C:\tests>.\flex.exe
Apr 26 11:55:17.566  INFO druid_shell::platform::windows::util:
 No shcore.dll
Apr 26 11:55:17.566  INFO druid_shell::platform::windows::util:
 Could not load `GetDpiForSystem`. Windows 10 or later is needed
Apr 26 11:55:17.566  INFO druid_shell::platform::windows::util:
 Could not load `GetDpiForWindow`. Windows 10 or later is needed
Apr 26 11:55:17.566  INFO druid_shell::platform::windows::util:
 Could not load `SetProcessDpiAwarenessContext`. Windows 10 or later is needed
Apr 26 11:55:17.566  INFO druid_shell::platform::windows::util:
 Could not load `GetSystemMetricsForDpi`. Windows 10 or later is needed
Apr 26 11:55:17.566  INFO druid_shell::platform::windows::util:
 No dcomp.dll
Apr 26 11:55:17.582 DEBUG druid::localization: available locale
s [], current en-US
Apr 26 11:55:17.582 DEBUG druid::localization: resolved: [en-US
]
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: hresult
80004002', druid-shell\src\platform\windows\window.rs:1303:48

image

I may need to open an issue for druid.

raphlinus commented 3 years ago

Hmm, odd for that function to be failing (it's D2D1CreateFactory - here's where it's being called). Does this crash if compiled on the Windows 7 machine, or only when compiled on Windows 10 and the executable is run on Windows 7.

The error code is E_NOINTERFACE, which is odd. One thing to try is removing the D2D1_DEBUG_LEVEL_INFORMATION, as suggested in this StackOverflow question.

ngugcx commented 3 years ago

My Windows 7 box doesn't have a good network, I can't setup the rust build tools there. Where is D2D1_DEBUG_LEVEL_INFORMATION set? I can't find it in the code.

jrmuizel commented 3 years ago

Does your Windows 7 box have the platform update applied? https://www.microsoft.com/en-ca/download/details.aspx?id=36805

ngugcx commented 3 years ago

@jrmuizel , the update fixes the problem. Is it possible to get rid of this dependence?

raphlinus commented 3 years ago

No, we've chosen platform update as the minimum compatibility level for piet and druid. Being compatible with earlier versions would require significant compromise, which we do not think is worth it given that it is pretty far out of date.

I think this issue can be closed?

ngugcx commented 3 years ago

This should be documented.