Skip to content

Commit 28fb453

Browse files
committed
finally it works
1 parent 6add851 commit 28fb453

File tree

6 files changed

+105
-57
lines changed

6 files changed

+105
-57
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**

Dockerfile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# escape=`
2+
3+
FROM --platform=windows/amd64 mcr.microsoft.com/windows/servercore:ltsc2025 AS BUILD_TOOLS
4+
5+
ARG WINDOWS_11_SDK_VERSION="22621"
6+
ARG VC_VERSION="14.42.17.12"
7+
ARG MSVC_VERSION="14.42.34433"
8+
9+
ENV WINDOWS_11_SDK_VERSION=${WINDOWS_11_SDK_VERSION} VC_VERSION=${VC_VERSION} MSVC_VERSION=${MSVC_VERSION} BUILD_TOOLS_DIR="C:\artifacts"
10+
11+
RUN mkdir C:\Temp && cd C:\Temp `
12+
&& curl -SL --output vs_buildtools.exe https://aka.ms/vs/17/release/vs_buildtools.exe `
13+
&& (start /w vs_buildtools.exe --quiet --wait --norestart --nocache `
14+
--remove Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
15+
--add Microsoft.VisualStudio.Component.VC.%VC_VERSION%.x86.x64 `
16+
--add Microsoft.VisualStudio.Component.Windows11SDK.%WINDOWS_11_SDK_VERSION% `
17+
--installPath %BUILD_TOOLS_DIR% `
18+
|| IF "%ERRORLEVEL%"=="3010" EXIT 0) `
19+
&& dir %BUILD_TOOLS_DIR%\VC\Tools\MSVC `
20+
&& if exist %BUILD_TOOLS_DIR%\VC\Tools\MSVC\%MSVC_VERSION% ( `
21+
for /d %i in (%BUILD_TOOLS_DIR%\VC\Tools\MSVC\*) do if /I not "%i"=="%BUILD_TOOLS_DIR%\VC\Tools\MSVC\%MSVC_VERSION%" rd /s /q "%i" `
22+
) else ( `
23+
echo "Error: Expected MSVC version directory %MSVC_VERSION% does not exist!" && exit /b 1 `
24+
)
25+
26+
RUN (echo { "WINDOWS_SDK_VERSION": "10.0.%WINDOWS_11_SDK_VERSION%.0", "VC_VERSION": "%VC_VERSION%", "MSVC_VERSION": "%MSVC_VERSION%" }) > %BUILD_TOOLS_DIR%\env.json
27+
28+
FROM mcr.microsoft.com/windows/nanoserver:ltsc2022
29+
30+
ARG BUILD_TOOLS_DIR="C:\BuildTools"
31+
ARG WINDOWS_KITS_10_DIR="C:\WindowsKits10SDK"
32+
ARG CMAKE_VERSION=3.31.0
33+
ARG CMAKE_DIR="C:\CMake"
34+
ARG PYTHON_VERSION=3.11.0
35+
ARG PYTHON_DIR="C:\Python"
36+
ARG NINJA_VERSION=1.12.1
37+
ARG NINJA_DIR="C:\Ninja"
38+
ARG NASM_VERSION=2.16.03
39+
ARG NASM_DIR="C:\Nasm"
40+
41+
COPY --link --from=BUILD_TOOLS ["C:/Program Files (x86)/Windows Kits/10", "${WINDOWS_KITS_10_DIR}"]
42+
COPY --link --from=BUILD_TOOLS ["C:/artifacts", "${BUILD_TOOLS_DIR}"]
43+
44+
ENV CMAKE_WINDOWS_KITS_10_DIR=${WINDOWS_KITS_10_DIR} BUILD_TOOLS_DIR=${BUILD_TOOLS_DIR} `
45+
CMAKE_VERSION=${CMAKE_VERSION} CMAKE_URL=https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-windows-x86_64.zip CMAKE_DIR=${CMAKE_DIR} `
46+
PYTHON_VERSION=${PYTHON_VERSION} PYTHON_URL=https://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}-embed-amd64.zip PYTHON_DIR=${PYTHON_DIR} `
47+
NINJA_VERSION=${NINJA_VERSION} NINJA_URL=https://github.com/ninja-build/ninja/releases/download/v${NINJA_VERSION}/ninja-win.zip NINJA_DIR=${NINJA_DIR} `
48+
NASM_VERSION=${NASM_VERSION} NASM_URL=https://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/win64/nasm-${NASM_VERSION}-win64.zip NASM_DIR=${NASM_DIR}
49+
50+
RUN mkdir "%CMAKE_DIR%" && curl -SL --output cmake.zip %CMAKE_URL% && tar -xf cmake.zip -C "%CMAKE_DIR%" && del cmake.zip
51+
RUN mkdir "%PYTHON_DIR%" && curl -SL --output python.zip %PYTHON_URL% && tar -xf python.zip -C "%PYTHON_DIR%" && del python.zip
52+
RUN mkdir "%NINJA_DIR%" && curl -SL --output ninja.zip %NINJA_URL% && tar -xf ninja.zip -C "%NINJA_DIR%" && del ninja.zip
53+
RUN mkdir "%NASM_DIR%" && curl -SL --output nasm.zip %NASM_URL% && tar -xf nasm.zip -C "%NASM_DIR%" && del nasm.zip
54+
55+
RUN cd %BUILD_TOOLS_DIR% && "%PYTHON_DIR%\python.exe" -c "import json, os; env=json.load(open('./env.json')); [os.system(f'setx {k} \"{v}\"') for k,v in env.items()]" `
56+
&& setx PATH "%CMAKE_DIR%\cmake-%CMAKE_VERSION%-windows-x86_64\bin;%PYTHON_DIR%;%NINJA_DIR%;%NASM_DIR%\nasm-%NASM_VERSION%;%PATH%" `
57+
&& setx MSVC_TOOLSET_DIR "%BUILD_TOOLS_DIR%\VC\Tools\MSVC\%MSVC_VERSION%"
58+
59+
SHELL ["cmd", "/c"]
60+
ENTRYPOINT ["cmd"]
61+
CMD ["/noexit"]

cmake/winsdk-msvc-toolchain.cmake

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,44 @@
11
message(STATUS "Configuring with \"${CMAKE_CURRENT_LIST_FILE}\" toolchain")
22

3+
if(CMAKE_VERSION VERSION_LESS "3.31.0")
4+
message(FATAL_ERROR "CMake version must be at least 3.31.0 to use this toolchain file!")
5+
endif()
6+
37
if(NOT CMAKE_GENERATOR MATCHES "Ninja*")
48
message(FATAL_ERROR "CMAKE_GENERATOR = \"${CMAKE_GENERATOR}\" is unsupported, use Ninja (single or multi config) generators!")
59
endif()
610

7-
cmake_path(CONVERT $ENV{WINDOWS_SDK_VERSION} TO_CMAKE_PATH_LIST WINDOWS_SDK_VERSION NORMALIZE)
811
cmake_path(CONVERT $ENV{CMAKE_WINDOWS_KITS_10_DIR} TO_CMAKE_PATH_LIST WINDOWS_KITS_10_DIR NORMALIZE)
12+
cmake_path(CONVERT $ENV{WINDOWS_SDK_VERSION} TO_CMAKE_PATH_LIST WINDOWS_SDK_VERSION NORMALIZE)
913
cmake_path(CONVERT $ENV{MSVC_TOOLSET_DIR} TO_CMAKE_PATH_LIST MSVC_TOOLSET_DIR NORMALIZE)
1014

11-
message(STATUS "WINDOWS_KITS_10_DIR = \"${WINDOWS_KITS_10_DIR}\"")
12-
message(STATUS "WINDOWS_SDK_VERSION = \"${WINDOWS_SDK_VERSION}\"")
13-
message(STATUS "MSVC_TOOLSET_DIR = \"${MSVC_TOOLSET_DIR}\"")
15+
if(VERBOSE)
16+
message(STATUS "WINDOWS_KITS_10_DIR = \"${WINDOWS_KITS_10_DIR}\"")
17+
message(STATUS "WINDOWS_SDK_VERSION = \"${WINDOWS_SDK_VERSION}\"")
18+
message(STATUS "MSVC_TOOLSET_DIR = \"${MSVC_TOOLSET_DIR}\"")
19+
endif()
1420

1521
set(CMAKE_SYSTEM_NAME Windows)
22+
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
1623

17-
# TODO: one could allow for cross platform builds
18-
# and more archs but I hardcode temporary windows-x86_64
19-
set(CMAKE_SYSTEM_PROCESSOR x86_64)
24+
if(ARCH)
25+
if(ARCH MATCHES "x64")
26+
elseif(ARCH MATCHES "arm64")
27+
set(CMAKE_SYSTEM_PROCESSOR arm64)
28+
# never tested it but I'm pretty sure _COMPILER needs to be updated depending on target ARCH
29+
message(FATAL_ERROR "TODO, Cross compilation requires ARM64 build tools compoment and updates to the toolchain file!")
30+
else()
31+
message(STATUS "Unsupported ARCH = \"${ARCH}\"")
32+
message(FATAL_ERROR "Supported ARCH = \"x64\", \"arm64\"")
33+
endif()
34+
else()
35+
set(ARCH x64)
36+
endif()
2037

2138
set(LIB
22-
"${WINDOWS_KITS_10_DIR}/Lib/${WINDOWS_SDK_VERSION}/ucrt/x64"
23-
"${WINDOWS_KITS_10_DIR}/Lib/${WINDOWS_SDK_VERSION}/um/x64"
24-
"${MSVC_TOOLSET_DIR}/lib/x64"
39+
"${WINDOWS_KITS_10_DIR}/Lib/${WINDOWS_SDK_VERSION}/ucrt/${ARCH}"
40+
"${WINDOWS_KITS_10_DIR}/Lib/${WINDOWS_SDK_VERSION}/um/${ARCH}"
41+
"${MSVC_TOOLSET_DIR}/lib/${ARCH}"
2542
)
2643

2744
set(INCLUDE
@@ -48,15 +65,15 @@ endfunction()
4865
_VALIDATE_ENV_V_(LIB)
4966
_VALIDATE_ENV_V_(INCLUDE)
5067

51-
set(CMAKE_C_COMPILER "${MSVC_TOOLSET_DIR}/bin/Hostx64/x64/cl.exe")
52-
set(CMAKE_CXX_COMPILER "${MSVC_TOOLSET_DIR}/bin/Hostx64/x64/cl.exe")
53-
set(CMAKE_ASM_COMPILER "${MSVC_TOOLSET_DIR}/bin/Hostx64/x64/cl.exe")
54-
set(CMAKE_ASM_MASM_COMPILER "${MSVC_TOOLSET_DIR}/bin/Hostx64/x64/ml64.exe")
68+
set(CMAKE_C_COMPILER "${MSVC_TOOLSET_DIR}/bin/Host${ARCH}/${ARCH}/cl.exe")
69+
set(CMAKE_CXX_COMPILER "${MSVC_TOOLSET_DIR}/bin/Host${ARCH}/${ARCH}/cl.exe")
70+
set(CMAKE_ASM_COMPILER "${MSVC_TOOLSET_DIR}/bin/Host${ARCH}/${ARCH}/cl.exe")
71+
set(CMAKE_ASM_MASM_COMPILER "${MSVC_TOOLSET_DIR}/bin/Host${ARCH}/${ARCH}/ml64.exe")
5572
find_program(CMAKE_ASM_NASM_COMPILER nasm HINTS ENV PATH ENV NASM_DIR NO_CACHE REQUIRED)
56-
set(CMAKE_RC_COMPILER "${WINDOWS_KITS_10_DIR}/bin/${WINDOWS_SDK_VERSION}/x64/rc.exe")
57-
set(CMAKE_LINKER "${MSVC_TOOLSET_DIR}/bin/Hostx64/x64/link.exe")
58-
set(CMAKE_AR "${MSVC_TOOLSET_DIR}/bin/Hostx64/x64/lib.exe")
59-
set(CMAKE_MT "${WINDOWS_KITS_10_DIR}/bin/${WINDOWS_SDK_VERSION}/x64/mt.exe")
73+
set(CMAKE_RC_COMPILER "${WINDOWS_KITS_10_DIR}/bin/${WINDOWS_SDK_VERSION}/${ARCH}/rc.exe")
74+
set(CMAKE_LINKER "${MSVC_TOOLSET_DIR}/bin/Host${ARCH}/${ARCH}/link.exe")
75+
set(CMAKE_AR "${MSVC_TOOLSET_DIR}/bin/Host${ARCH}/${ARCH}/lib.exe")
76+
set(CMAKE_MT "${WINDOWS_KITS_10_DIR}/bin/${WINDOWS_SDK_VERSION}/${ARCH}/mt.exe")
6077

6178
macro(_UPDATE_STANDARD_DIRECTORIES_ WHAT VARV)
6279
set(CMAKE_C_STANDARD_${WHAT}_DIRECTORIES ${VARV})

docker/mount.dockerfile

Lines changed: 0 additions & 37 deletions
This file was deleted.

docker/xcache.dockerfile

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/src/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ add_test(NAME NANO_EXE_S_TEST
3939
add_test(NAME NANO_EXE_D_TEST
4040
COMMAND $<TARGET_FILE:NanoDExe>
4141
COMMAND_EXPAND_LISTS
42+
)
43+
44+
cmake_path(GET CMAKE_CXX_COMPILER PARENT_PATH CL_DIR)
45+
set_tests_properties(NANO_EXE_S_TEST NANO_EXE_D_TEST
46+
# this allows me to fire tests with correct DLLs in search path,
47+
# note you should distibute used redists or make sure your end
48+
# user install them system wide
49+
PROPERTIES ENVIRONMENT_MODIFICATION PATH=path_list_prepend:${CL_DIR}
4250
)

0 commit comments

Comments
 (0)