error: use of unresolved identifier 'DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2'
dropbear32 opened this issue ยท 22 comments
I'm getting this error after running the following commands:
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release . -D CMAKE_Swift_FLAGS="-sdk %SDK% -I %SDK%/usr/lib/swift -L %SDK%/usr/lib/swift/%OS%"
ninja -C build SwiftWin32 HelloSwift
I've run curl -sL "https://raw.githubusercontent.com/apple/swift/master/stdlib/public/Platform/winsdk.modulemap" -o "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap"
in an administrator Developer prompt and it made no difference.
Is there a different/newer/older modulemap I need to clone?
Bleh, this is a compatibility issue. DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
doesn't get pulled in correctly from the clang importer. We should provide a definition for it in WinSDK+Extensions.swift
for compatibility. Thanks for the report!
Sure! I'll do my best.
I would get this by going through the Windows.md guide again, right?
@atirit no, that is far overkill. I would say just apply the change (#26) to your repository and just build swift-win32.
Gotcha.
Adding the following to Application.swift
:
#if swift(>=5.3)
#else
// windef.h
internal let DPI_AWARENESS_CONTEXT_UNAWARE: DPI_AWARENESS_CONTEXT =
DPI_AWARENESS_CONTEXT(bitPattern: -1)!
internal let DPI_AWARENESS_CONTEXT_SYSTEM_AWARE: DPI_AWARENESS_CONTEXT =
DPI_AWARENESS_CONTEXT(bitPattern: -2)!
internal let DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE: DPI_AWARENESS_CONTEXT =
DPI_AWARENESS_CONTEXT(bitPattern: -3)!
internal let DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2: DPI_AWARENESS_CONTEXT =
DPI_AWARENESS_CONTEXT(bitPattern: -4)!
internal let DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED: DPI_AWARENESS_CONTEXT =
DPI_AWARENESS_CONTEXT(bitPattern: -5)!
#endif
results in the following errors:
..\Sources\Application\Application.swift:33:45: error: use of undeclared type 'DPI_AWARENESS_CONTEXT'
internal let DPI_AWARENESS_CONTEXT_UNAWARE: DPI_AWARENESS_CONTEXT =
^~~~~~~~~~~~~~~~~~~~~
..\Sources\Application\Application.swift:35:50: error: use of undeclared type 'DPI_AWARENESS_CONTEXT'
internal let DPI_AWARENESS_CONTEXT_SYSTEM_AWARE: DPI_AWARENESS_CONTEXT =
^~~~~~~~~~~~~~~~~~~~~
..\Sources\Application\Application.swift:37:55: error: use of undeclared type 'DPI_AWARENESS_CONTEXT'
internal let DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE: DPI_AWARENESS_CONTEXT =
^~~~~~~~~~~~~~~~~~~~~
..\Sources\Application\Application.swift:39:58: error: use of undeclared type 'DPI_AWARENESS_CONTEXT'
internal let DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2: DPI_AWARENESS_CONTEXT =
^~~~~~~~~~~~~~~~~~~~~
..\Sources\Application\Application.swift:41:55: error: use of undeclared type 'DPI_AWARENESS_CONTEXT'
internal let DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED: DPI_AWARENESS_CONTEXT =
^~~~~~~~~~~~~~~~~~~~~
..\Sources\Application\Application.swift:39:58: error: use of undeclared type 'DPI_AWARENESS_CONTEXT'
internal let DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2: DPI_AWARENESS_CONTEXT =
^~~~~~~~~~~~~~~~~~~~~
Is there a different place I should be putting it? (Perhaps I misunderstood you and you meant the Swift repository, not the swift-win32 repository.)
Nope, that is the right place, the error is interesting though. DPI_AWARENESS_CONTEXT
comes from the modulemap in the WinSDK directory:
https://docs.microsoft.com/en-us/windows/win32/hidpi/dpi-awareness-context
IIRC, ShellScalingApi.h
should include that header and provide the type definition. Can you verify that ShellCore
is in %UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap
?
That change allows for applications to actually scale properly for HiDPI (Retina in Apple parlance) displays.
I see the following in that file:
module ShellCore {
header "ShellScalingApi.h"
export *
link "shcore.lib"
}
Which version of the windows SDK are you using? (10.0.107763 or some other version?)
I believe I'm using version 10.0.17134.0
. I have the following in C:\Program Files (x86)\Windows Kits\10\Include
:
- 10.0.10240.0
- 10.0.16299.0
- 10.0.17134.0
- 10.0.17763.0
- 10.0.18362.0
I'm not quite sure how to determine the exact version I'm using.
Ah, that is the problem! 10.0.17763.0 is the minimum required version for Windows. %UCRTVersion%
in the environment should specify the version.
Running echo %UCRTVersion%
returns 10.0.18362.0
. Looks like I was wrong :P (I'm quite inept at Windows development if you couldn't tell already lol)
Okay, I just built locally against 10.0.17763.0 successfully. Going to try with 10.0.18362.0. (Note that I ran into the same issue with the winsdk modulemap being out of date)
Okay, I was able to build with 10.0.18362.0 as well.
@atirit what environment are you testing in? Im trying to figure out how to get you unblocked (I'll be looking at storing some of the artifacts soon)
I'm just in a Native Tools prompt. I'm not in Docker or anything.
Hmm, I wonder whats different about what Im doing to test vs what you are building. Perhaps you need to clear our the the caches in %TEMP%\org.llvm.*
?
I deleted that folder and reran cmake and ninja after removing build/, and it didn't make a difference. Here's the full output of ninja:
ninja: Entering directory `build'
[1/2] Linking Swift shared library SwiftWin32.dll
FAILED: SwiftWin32.dll CMakeFiles/SwiftWin32.dir/Sources/Application/Application.swift.obj CMakeFiles/SwiftWin32.dir/Sources/Application/ApplicationDelegate.swift.obj CMakeFiles/SwiftWin32.dir/Sources/Application/ApplicationMain.swift.obj CMakeFiles/SwiftWin32.dir/Sources/UI/Button.swift.obj CMakeFiles/SwiftWin32.dir/Sources/UI/Color.swift.obj CMakeFiles/SwiftWin32.dir/Sources/UI/Control.swift.obj CMakeFiles/SwiftWin32.dir/Sources/UI/EdgeInsets.swift.obj CMakeFiles/SwiftWin32.dir/Sources/UI/Font.swift.obj CMakeFiles/SwiftWin32.dir/Sources/UI/Label.swift.obj CMakeFiles/SwiftWin32.dir/Sources/UI/ProgressView.swift.obj CMakeFiles/SwiftWin32.dir/Sources/UI/Screen.swift.obj CMakeFiles/SwiftWin32.dir/Sources/UI/Slider.swift.obj CMakeFiles/SwiftWin32.dir/Sources/UI/TextField.swift.obj CMakeFiles/SwiftWin32.dir/Sources/UI/TextView.swift.obj CMakeFiles/SwiftWin32.dir/Sources/UI/View.swift.obj CMakeFiles/SwiftWin32.dir/Sources/UI/Window.swift.obj CMakeFiles/SwiftWin32.dir/Sources/UI/WindowClass.swift.obj CMakeFiles/SwiftWin32.dir/Sources/CG/AffineTransform.swift.obj CMakeFiles/SwiftWin32.dir/Sources/CG/Point.swift.obj CMakeFiles/SwiftWin32.dir/Sources/CG/Rect.swift.obj CMakeFiles/SwiftWin32.dir/Sources/CG/Size.swift.obj CMakeFiles/SwiftWin32.dir/Sources/Support/Logging.swift.obj CMakeFiles/SwiftWin32.dir/Sources/Support/Range.swift.obj CMakeFiles/SwiftWin32.dir/Sources/Support/Rect+UIExtensions.swift.obj CMakeFiles/SwiftWin32.dir/Sources/Support/String.swift.obj CMakeFiles/SwiftWin32.dir/Sources/Support/WindowsHandle.swift.obj CMakeFiles/SwiftWin32.dir/Sources/Support/WinSDK+Extensions.swift.obj swift/SwiftWin32.swiftmodule SwiftWin32.lib
cmd.exe /C "cd . && \Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -output-file-map CMakeFiles\SwiftWin32.dir\Release\output-file-map.json -incremental -j 12 -emit-library -o SwiftWin32.dll -module-name SwiftWin32 -module-link-name SwiftWin32 -emit-module -emit-module-path swift\SwiftWin32.swiftmodule -emit-dependencies -DSwiftWin32_EXPORTS -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -I C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk/usr/lib/swift -L C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk/usr/lib/swift/windows -O -Xcc -DNONAMELESSUNION -Xcc -DCOBJMACROS ..\Sources\Application\Application.swift ..\Sources\Application\ApplicationDelegate.swift ..\Sources\Application\ApplicationMain.swift ..\Sources\UI\Button.swift ..\Sources\UI\Color.swift ..\Sources\UI\Control.swift ..\Sources\UI\EdgeInsets.swift ..\Sources\UI\Font.swift ..\Sources\UI\Label.swift ..\Sources\UI\ProgressView.swift ..\Sources\UI\Screen.swift ..\Sources\UI\Slider.swift ..\Sources\UI\TextField.swift ..\Sources\UI\TextView.swift ..\Sources\UI\View.swift ..\Sources\UI\Window.swift ..\Sources\UI\WindowClass.swift ..\Sources\CG\AffineTransform.swift ..\Sources\CG\Point.swift ..\Sources\CG\Rect.swift ..\Sources\CG\Size.swift ..\Sources\Support\Logging.swift ..\Sources\Support\Range.swift ..\Sources\Support\Rect+UIExtensions.swift ..\Sources\Support\String.swift ..\Sources\Support\WindowsHandle.swift ..\Sources\Support\WinSDK+Extensions.swift -Xlinker -implib:SwiftWin32.lib -lUser32.lib -lGdi32.lib -lComCtl32.lib && cd ."
..\Sources\Application\Application.swift:33:45: error: use of undeclared type 'DPI_AWARENESS_CONTEXT'
internal let DPI_AWARENESS_CONTEXT_UNAWARE: DPI_AWARENESS_CONTEXT =
^~~~~~~~~~~~~~~~~~~~~
..\Sources\Application\Application.swift:35:50: error: use of undeclared type 'DPI_AWARENESS_CONTEXT'
internal let DPI_AWARENESS_CONTEXT_SYSTEM_AWARE: DPI_AWARENESS_CONTEXT =
^~~~~~~~~~~~~~~~~~~~~
..\Sources\Application\Application.swift:37:55: error: use of undeclared type 'DPI_AWARENESS_CONTEXT'
internal let DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE: DPI_AWARENESS_CONTEXT =
^~~~~~~~~~~~~~~~~~~~~
..\Sources\Application\Application.swift:39:58: error: use of undeclared type 'DPI_AWARENESS_CONTEXT'
internal let DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2: DPI_AWARENESS_CONTEXT =
^~~~~~~~~~~~~~~~~~~~~
..\Sources\Application\Application.swift:41:55: error: use of undeclared type 'DPI_AWARENESS_CONTEXT'
internal let DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED: DPI_AWARENESS_CONTEXT =
^~~~~~~~~~~~~~~~~~~~~
..\Sources\Application\Application.swift:39:58: error: use of undeclared type 'DPI_AWARENESS_CONTEXT'
internal let DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2: DPI_AWARENESS_CONTEXT =
^~~~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.
Can you run the swiftc
command with -Xcc -###
and get the clang importer invocation?
@compnerd figured it out. I needed to place that change in Sources/Support/WinSDK+Extensions.swift
rather than Sources/Application/Application.swift
since the former imports WinSDK
. It builds now. That's what you did in the commit; I don't know how I missed that.
Im planning on making some more improvements to the build, so LMK if you run into issues.