thebrowsercompany / windows-samples

Sample Apps for Swift on Windows
MIT License
271 stars 15 forks source link

Error while building from VSCode `Run and Debug` #5

Closed oskargargas closed 9 months ago

oskargargas commented 12 months ago

Hi!

Thanks for opensourcing this great project and leading the way into Swift Windows development. It motivated me to kickstart a side project that was long overdue.

Going to the issue. I have a problem building, running and debugging from VSCode. Command line builds work. I can run the app manually. VSCode build after clicking Build in bottom bar CMake menu also works. Run and Debug does not. Finishes with an error quoted below.

I use Windows 10 Pro. Intel CPU. No VM. Clean install for development purposes. Swift from yours nightly build. I run VSCode form inside Developer PowerShell. What am I doing wrong? :)

Swift

swiftc --version
compnerd.org Swift version 5.11-dev (LLVM fe9a485647a386d, Swift 98e65d015979c7b)
Target: x86_64-unknown-windows-msvc

launch.json

{
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "sourceLanguages": [
                "swift"
            ],
            "args": [],
            "cwd": "${workspaceFolder:WinUI3AnimationsPreview}",
            "name": "Debug WinUI3AnimationsPreview",
            "program": "${workspaceFolder:WinUI3AnimationsPreview}\\build\\debug\\WinUI3AnimationsPreview.exe",
            "preLaunchTask": "swift: Build Debug WinUI3AnimationsPreview"
        },
        {
            "type": "lldb",
            "request": "launch",
            "sourceLanguages": [
                "swift"
            ],
            "args": [],
            "cwd": "${workspaceFolder:WinUI3AnimationsPreview}",
            "name": "Release WinUI3AnimationsPreview",
            "program": "${workspaceFolder:WinUI3AnimationsPreview}\\build\\release\\WinUI3AnimationsPreview.exe",
            "preLaunchTask": "swift: Build Release WinUI3AnimationsPreview"
        }
    ]
}

Build log:


 *  Executing task in folder WinUI3AnimationsPreview: C:\Users\oskar\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr/bin/swift.exe build --scratch-path build --product WinUI3AnimationsPreview -Xlinker -debug:dwarf 

Building for debugging...
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "../../Headers/CWinAppSDK-Bridging-Header.h"
         ^
C:\Users\oskar\Developer\windows-samples\Shared\CWinAppSDK\Sources\CWinAppSDK/../../Headers/CWinAppSDK-Bridging-Header.h:9:10: error: 'MddBootstrap.h' file not found
#include <MddBootstrap.h>
         ^
C:\Users\oskar\Developer\windows-samples\WinUI3AnimationsPreview\Sources\WinUI3AnimationsPreview\SwiftWinApp.swift:2:8: error: could not build C module 'CWinAppSDK'
import CWinAppSDK
       ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "../../Headers/CWinAppSDK-Bridging-Header.h"
         ^
C:\Users\oskar\Developer\windows-samples\Shared\CWinAppSDK\Sources\CWinAppSDK/../../Headers/CWinAppSDK-Bridging-Header.h:9:10: error: 'MddBootstrap.h' file not found
#include <MddBootstrap.h>
         ^
C:\Users\oskar\Developer\windows-samples\WinUI3AnimationsPreview\Sources\WinUI3AnimationsPreview\SwiftWinApp.swift:2:8: error: could not build C module 'CWinAppSDK'
import CWinAppSDK
       ^
error: emit-module command failed with exit code 1 (use -v to see invocation)
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "../../Headers/CWinAppSDK-Bridging-Header.h"
         ^
C:\Users\oskar\Developer\windows-samples\Shared\CWinAppSDK\Sources\CWinAppSDK/../../Headers/CWinAppSDK-Bridging-Header.h:9:10: error: 'MddBootstrap.h' file not found
#include <MddBootstrap.h>
         ^
C:\Users\oskar\Developer\windows-samples\WinUI3AnimationsPreview\Sources\WinUI3AnimationsPreview\SwiftWinApp.swift:2:8: error: could not build C module 'CWinAppSDK'
import CWinAppSDK
       ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "../../Headers/CWinAppSDK-Bridging-Header.h"
         ^
C:\Users\oskar\Developer\windows-samples\Shared\CWinAppSDK\Sources\CWinAppSDK/../../Headers/CWinAppSDK-Bridging-Header.h:9:10: error: 'MddBootstrap.h' file not found
#include <MddBootstrap.h>
         ^
C:\Users\oskar\Developer\windows-samples\WinUI3AnimationsPreview\Sources\WinUI3AnimationsPreview\SwiftWinApp.swift:2:8: error: could not build C module 'CWinAppSDK'
import CWinAppSDK
       ^
error: fatalError

 *  The terminal process "C:\Users\oskar\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift.exe 'build', '--scratch-path', 'build', '--product', 'WinUI3AnimationsPreview', '-Xlinker', '-debug:dwarf'" terminated with exit code: 1. 
 * ```
deevus commented 11 months ago

Same issue here.

deevus commented 11 months ago

I'm still trying to understand this issue. MddBootstrap.h resides in the Windows App SDK. And I can see the file in build\NugetPackages\Microsoft.WindowsAppSDK.1.4.231008000\include

I'm not sure why this directory isn't included when building.

oskargargas commented 11 months ago

@deevus I've finally managed to make it working. Thou not sure which step was the fix.

deevus commented 11 months ago

@deevus I've finally managed to make it working. Thou not sure which step was the fix.

  • Make sure that you have VSCode workspace open
  • Select your-app-name (workspace) as your Run & Debug target
  • In VSCode settings chachk Swift: Build Path and Cmake: Build Directory and direct them to the same place (build, and ${workspaceFolder}/build in my case)
  • Some additional notes: https://gist.github.com/oskargargas/1a9b925bdbc486ffc96ee4d82fac66a5
  • After setting all above manually remove all build folders and retry

Could you be a bit more explicit in your instructions?

Where do you find the Swift: Build Path and Cmake: Build Directory settings?

oskargargas commented 11 months ago

Could you be a bit more explicit in your instructions?

Where do you find the Swift: Build Path and Cmake: Build Directory settings?

I mean VScode settings, to be exact (put those in settings search window in VSCode):

But I actually don't think that those matter. I've reset those settings yesterday.

Be sure to:

  1. Open Developer Command Prompt or Developer Power Shell
  2. cd into project directory (for me: cd ~\Developer\windows-samples)
  3. Open VSCode in this directory code .
  4. Open Workspace
    1. Open project-name.code-workspace file
    2. Click on Open Worskpace button in bottom right
  5. In Run & Debug select target declared in workspace, not the one from launch.json Zrzut ekranu 2023-12-28 151129
  6. You might also need to scope workspaceFolder variable as I did here: https://github.com/thebrowsercompany/windows-samples/pull/12
stevenbrix commented 9 months ago

I think this issue should be fixed now with #13 . let me know if you are still having build issues!