thebrowsercompany / windows-samples

Sample Apps for Swift on Windows
MIT License
262 stars 13 forks source link

Can it build on virtual machine on Apple silicon Macs? #3

Closed StefanCosminR closed 10 months ago

StefanCosminR commented 10 months ago

Hi!

I am not sure if I can't get the environment setup correctly or it's not supposed to work like this. I have a MacBook Pro with M2 Max and I run Windows 11 on Parallels Desktop.

Is this setup supported? If not, is it possible to work in the near future?

StefanCosminR commented 10 months ago

This is the error I get in Visual Studio Code.

I installed Swift using the arm64 installer from the swift-build repository

build task started....
"C:\Program Files\CMake\bin\cmake.EXE" --build C:/windowsapps/windows-samples/WinUI3AnimationsPreview/build --target all
[  0%] Built target WinUI3AnimationsPreview
[  7%] Running Swift build...
error: 'winui3animationspreview': Invalid manifest (compiled with: ["C:\\Users\\stefanromanescu\\AppData\\Local\\Programs\\Swift\\Toolchains\\0.0.0+Asserts\\usr\\bin\\swiftc.exe", "-vfsoverlay", "C:\\Users\\STEFAN~1\\AppData\\Local\\Temp\\TemporaryDirectory.2jIci2\\vfs.yaml", "-L", "C:\\Users\\stefanromanescu\\AppData\\Local\\Programs\\Swift\\Toolchains\\0.0.0+Asserts\\usr\\lib\\swift\\pm\\ManifestAPI", "-lPackageDescription", "-sdk", "C:\\Users\\stefanromanescu\\AppData\\Local\\Programs\\Swift\\Platforms\\0.0.0\\Windows.platform\\Developer\\SDKs\\Windows.sdk", "-libc", "MD", "-I", "C:\\Users\\stefanromanescu\\AppData\\Local\\Programs\\Swift\\Platforms\\0.0.0\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows", "-I", "C:\\Users\\stefanromanescu\\AppData\\Local\\Programs\\Swift\\Platforms\\0.0.0\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\aarch64", "-L", "C:\\Users\\stefanromanescu\\AppData\\Local\\Programs\\Swift\\Platforms\\0.0.0\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\aarch64", "-use-ld=lld", "-swift-version", "5", "-I", "C:\\Users\\stefanromanescu\\AppData\\Local\\Programs\\Swift\\Toolchains\\0.0.0+Asserts\\usr\\lib\\swift\\pm\\ManifestAPI", "-package-description-version", "5.7.0", "C:\\windowsapps\\windows-samples\\WinUI3AnimationsPreview\\Package.swift", "-Xfrontend", "-disable-implicit-concurrency-module-import", "-Xfrontend", "-disable-implicit-string-processing-module-import", "-o", "C:\\Users\\STEFAN~1\\AppData\\Local\\Temp\\TemporaryDirectory.kIXuxU\\winui3animationspreview-manifest.exe"])
error: fatalError
error: link command failed with exit code 1 (use -v to see invocation)
lld-link: error: msvcrt.lib(exe_main.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(loadcfg.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(utility.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(gs_support.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(matherr.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(argv_mode.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(commit_mode.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(file_mode.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(new_mode.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(thread_locale.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(tncleanup.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(env_mode.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(invalid_parameter_handler.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(denormal_control.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(default_local_stdio_options.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(matherr_detection.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(dyn_tls_init.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(dyn_tls_dtor.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(utility_desktop.obj): machine type x64 conflicts with arm64
lld-link: error: msvcrt.lib(initsect.obj): machine type x64 conflicts with arm64
lld-link: error: too many errors emitted, stopping now (use /errorlimit:0 to see all errors)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
NMAKE : fatal error U1077: 'echo >nul && "C:\Program Files\CMake\bin\cmake.exe" -E env --unset=VCINSTALLDIR CC=clang CXX=clang++ -- swift build --disable-automatic-resolution -Xswiftc -g -Xlinker -debug:dwarf -Xlinker -ignore:4217 -Xcc -IC:/windowsapps/windows-samples/build/NugetPackages/Microsoft.WindowsAppSDK.1.4.231008000/include -Xlinker -LC:/windowsapps/windows-samples/build/NugetPackages/Microsoft.WindowsAppSDK.1.4.231008000/lib/win10-x64 -c debug --scratch-path C:/windowsapps/windows-samples/build/spm' : return code '0x1'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\HostX64\x64\nmake.exe" -s -f CMakeFiles\WinUI3AnimationsPreview-SPM.dir\build.make /nologo -SL                 CMakeFiles\WinUI3AnimationsPreview-SPM.dir\build' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\HostX64\x64\nmake.exe" -s -f CMakeFiles\Makefile2 /nologo -LS                 all' : return code '0x2'
Stop.
build finished with error(s).
StefanCosminR commented 10 months ago

And if compiling with the X64 version of Visual Studio Community it still fails, but with something "kernel32.lib" related.

[proc] Executing command: cmake --version
[proc] Executing command: cmake -E capabilities
[variant] Loaded new set of variants
[kit] Successfully loaded 16 kits from C:\Users\stefanromanescu\AppData\Local\CMakeTools\cmake-tools-kits.json
[presetController] Successfully validated presets in C:\windowsapps\windows-samples\WinUI3AnimationsPreview\CMakePresets.json
[variant] Loaded new set of variants
[variant] Loaded new set of variants
[variant] Loaded new set of variants
[variant] Loaded new set of variants
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --version
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -E capabilities
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -SC:/windowsapps/windows-samples/WinUI3AnimationsPreview -BC:/windowsapps/windows-samples/WinUI3AnimationsPreview/build -G "NMake Makefiles"
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" -SC:/windowsapps/windows-samples/WinUI3AnimationsPreview -BC:/windowsapps/windows-samples/WinUI3AnimationsPreview/build -G "NMake Makefiles" exited with code: 1
[main] Configuring project: WinUI3AnimationsPreview 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_MODULE_PATH=C:/windowsapps/windows-samples/WinUI3AnimationsPreview/cmake -DCMAKE_INSTALL_PREFIX=C:/windowsapps/windows-samples/WinUI3AnimationsPreview/out -SC:/windowsapps/windows-samples/WinUI3AnimationsPreview -BC:/windowsapps/windows-samples/WinUI3AnimationsPreview/build -G "NMake Makefiles"
[cmake] -- The C compiler identification is MSVC 19.37.32825.0
[cmake] -- The CXX compiler identification is MSVC 19.37.32825.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - failed
[cmake] -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe
[cmake] -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe - broken
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.27/Modules/CMakeTestCCompiler.cmake:67 (message):
[cmake]   The C compiler
[cmake] 
[cmake]     "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe"
[cmake] 
[cmake]   is not able to compile a simple test program.
[cmake] 
[cmake]   It fails with the following output:
[cmake] 
[cmake]     Change Dir: 'C:/windowsapps/windows-samples/WinUI3AnimationsPreview/build/CMakeFiles/CMakeScratch/TryCompile-tdyudl'
[cmake]     
[cmake]     Run Build Command(s): "C:/Program Files/CMake/bin/cmake.exe" -E env VERBOSE=1 nmake -f Makefile /nologo cmTC_d5222\fast
[cmake]         "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\Hostx64\x64\nmake.exe"  -f CMakeFiles\cmTC_d5222.dir\build.make /nologo -L                  CMakeFiles\cmTC_d5222.dir\build
[cmake]     Building C object CMakeFiles/cmTC_d5222.dir/testCCompiler.c.obj
[cmake]         "C:\Program Files\CMake\bin\cmake.exe" -E cmake_cl_compile_depends --dep-file=CMakeFiles\cmTC_d5222.dir\testCCompiler.c.obj.d --working-dir=C:\windowsapps\windows-samples\WinUI3AnimationsPreview\build\CMakeFiles\CMakeScratch\TryCompile-tdyudl --filter-prefix="Note: including file: " -- C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1437~1.328\bin\Hostx64\x64\cl.exe @C:\Users\STEFAN~1\AppData\Local\Temp\nm9CE0.tmp
[cmake]     testCCompiler.c
[cmake]     Linking C executable cmTC_d5222.exe
[cmake]         "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_d5222.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\arm64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\arm64\mt.exe --manifests -- C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1437~1.328\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cmTC_d5222.dir\objects1.rsp @C:\Users\STEFAN~1\AppData\Local\Temp\nm9D5E.tmp
[cmake]     Visual Studio Incremental Link with embedded manifests
[cmake]     Create CMakeFiles\cmTC_d5222.dir/manifest.rc
[cmake]     Create empty: CMakeFiles\cmTC_d5222.dir/embed.manifest
[cmake]     RC Pass 1:
[cmake]     C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\arm64\rc.exe /fo CMakeFiles\cmTC_d5222.dir/manifest.res CMakeFiles\cmTC_d5222.dir/manifest.rc
[cmake]     LINK Pass 1:
[cmake]     C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1437~1.328\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cmTC_d5222.dir\objects1.rsp /out:cmTC_d5222.exe /implib:cmTC_d5222.lib /pdb:C:\windowsapps\windows-samples\WinUI3AnimationsPreview\build\CMakeFiles\CMakeScratch\TryCompile-tdyudl\cmTC_d5222.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_d5222.dir/intermediate.manifest CMakeFiles\cmTC_d5222.dir/manifest.res
[cmake]     LINK Pass 1: command "C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1437~1.328\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cmTC_d5222.dir\objects1.rsp /out:cmTC_d5222.exe /implib:cmTC_d5222.lib /pdb:C:\windowsapps\windows-samples\WinUI3AnimationsPreview\build\CMakeFiles\CMakeScratch\TryCompile-tdyudl\cmTC_d5222.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_d5222.dir/intermediate.manifest CMakeFiles\cmTC_d5222.dir/manifest.res" failed (exit code 1104) with the following output:
[cmake]     LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
[cmake]     NMAKE : fatal error U1077: '"C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_d5222.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\arm64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\arm64\mt.exe --manifests -- C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1437~1.328\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cmTC_d5222.dir\objects1.rsp @C:\Users\STEFAN~1\AppData\Local\Temp\nm9D5E.tmp' : return code '0xffffffff'
[cmake]     Stop.
[cmake]     NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\Hostx64\x64\nmake.exe"  -f CMakeFiles\cmTC_d5222.dir\build.make /nologo -L                  CMakeFiles\cmTC_d5222.dir\build' : return code '0x2'
[cmake]     Stop.
[cmake]     
[cmake]     
[cmake] 
[cmake]   
[cmake] 
[cmake]   CMake will not be able to correctly generate this project.
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:2 (project)
StefanCosminR commented 10 months ago

I got it to build using the amd64 (yes, amd64 on an ARM device) release from the swift-build repository.

I also had to replace this part of the file WinRTPreBuild.cmake

if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
    set(WINSDK_BIN_ARCH x64)
else()
    set(WINSDK_BIN_ARCH ${CMAKE_SYSTEM_PROCESSOR})
endif()

To simply this

set(WINSDK_BIN_ARCH x64)

The architecture will