Skip to content

Commit 2b4a121

Browse files
committed
save work
1 parent ff527f9 commit 2b4a121

File tree

1 file changed

+60
-9
lines changed

1 file changed

+60
-9
lines changed

tools/nsc/CMakeLists.txt

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ set(NBL_CE_GENERATE_CONFIG_COMMAND
120120
-P "${CMAKE_CURRENT_SOURCE_DIR}/ce-generate-config.cmake"
121121
)
122122

123-
set(NBL_DOCKER_CE_COMPOSE_BASE "${NBL_ROOT_PATH}/docker/compiler-explorer/compose.yml")
123+
set(NBL_DOCKER_CE_DOCKER_CTX "${NBL_ROOT_PATH}/docker/compiler-explorer")
124+
set(NBL_DOCKER_CE_DOCKERFILE_BASE "${NBL_DOCKER_CE_DOCKER_CTX}/Dockerfile")
125+
set(NBL_DOCKER_CE_COMPOSE_BASE "${NBL_DOCKER_CE_DOCKER_CTX}/compose.yml")
124126
cmake_path(NATIVE_PATH NBL_DOCKER_CE_COMPOSE_BASE NORMALIZE NBL_DOCKER_CE_COMPOSE_BASE)
125127
set(NBL_DOCKER_CE_COMPOSE_TARGET "${GODBOLT_BINARY_DIRECTORY}/.dev-compose.yml")
126128

@@ -273,20 +275,21 @@ ON
273275
set(BASE_IMAGE dr.devsh.eu/compiler-explorer/windows)
274276

275277
# NOTE to self: could be all done with single docker file & compose file but buildkit works bad with windows driver, yet need to wait for stuff to be implemented
276-
set(OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/docker/devel")
278+
set(DEVEL_CTX "${CMAKE_CURRENT_BINARY_DIR}/docker/devel")
277279
set(CT_REDIST_DIR "${CT_TOOLSET_REDIST_TARGET}/${REDIST_CRT_TOOLSET_VERSION}")
278280
set(CT_NONREDIST_CTR_DIR "${CT_REDIST_DIR}/${DEBUG_CRT_RELATIVE}")
279281
cmake_path(NATIVE_PATH CT_REDIST_DIR NORMALIZE CT_REDIST_DIR)
280282
cmake_path(NATIVE_PATH CT_NONREDIST_CTR_DIR NORMALIZE CT_NONREDIST_CTR_DIR)
281-
set(DEVEL_DOCKERFILE "${OUTPUT_DIRECTORY}/Dockerfile")
283+
set(DEVEL_DOCKERFILE "${DEVEL_CTX}/Dockerfile")
282284

283-
GEN_DOCKER_CONTENT("" "${OUTPUT_DIRECTORY}"
285+
GEN_DOCKER_CONTENT("" "${DEVEL_CTX}"
284286
[=[
285287
286-
COPY --from=@DOCKER_VULKAN_TAG@ /@CT_VULKAN_TARGET@ /@CT_VULKAN_TARGET@
287-
COPY --from=@DOCKER_CRT_TAG@ /@CT_TOOLSET_REDIST_TARGET@ /@CT_TOOLSET_REDIST_TARGET@
288+
COPY --link --from=@DOCKER_VULKAN_TAG@ /@CT_VULKAN_TARGET@ /@CT_VULKAN_TARGET@
289+
COPY --link --from=@DOCKER_CRT_TAG@ /@CT_TOOLSET_REDIST_TARGET@ /@CT_TOOLSET_REDIST_TARGET@
288290
289-
RUN .\@CT_REDIST_DIR@\vc_redist.x64.exe /quiet /install
291+
# TODO
292+
# RUN .\@CT_REDIST_DIR@\vc_redist.x64.exe /quiet /install
290293
RUN xcopy .\@CT_NONREDIST_CTR_DIR@\*.dll %SystemRoot%\System32 /Y
291294
RUN xcopy .\@CT_TOOLSET_REDIST_TARGET@\ucrtbased.dll %SystemRoot%\System32 /Y
292295
@@ -348,8 +351,56 @@ string(CONFIGURE "${COMPOSE_CONTENT}" COMPOSE_CONTENT @ONLY)
348351
file(WRITE "${NBL_DOCKER_CE_COMPOSE_TARGET}" "${COMPOSE_CONTENT}")
349352
make_directory("${GODBOLT_BINARY_DIRECTORY}/.ctx")
350353

351-
execute_process(COMMAND "${DOCKER_EXE}" compose -f "${NBL_DOCKER_CE_COMPOSE_BASE}" build)
352-
execute_process(COMMAND "${DOCKER_EXE}" compose -f "${NBL_DOCKER_CE_COMPOSE_TARGET}" build)
354+
function(_PROMOTE_PROCESS_ISOLATION_ KERNEL BASES VAR)
355+
set(${VAR} True)
356+
set(ix 0)
357+
list(LENGTH BASES LEN)
358+
359+
while(ix LESS ${LEN})
360+
list(GET BASES ${ix} BASE)
361+
362+
execute_process(COMMAND "${DOCKER_EXE}" inspect --format={{.OsVersion}} ${BASE} RESULT_VARIABLE EXIT_LEVEL OUTPUT_VARIABLE TARGET_KERNEL OUTPUT_STRIP_TRAILING_WHITESPACE)
363+
364+
if(${EXIT_LEVEL} EQUAL 0)
365+
if(${KERNEL} VERSION_LESS ${TARGET_KERNEL})
366+
set(${VAR} False PARENT_SCOPE)
367+
message(STATUS "While inspecting ${BASE} - host Kernel ${KERNEL} too low to use container process isolation (target ${TARGET_KERNEL}), falling back to HyperV. Please update your host OS.")
368+
return()
369+
endif()
370+
math(EXPR ix "${ix} + 1")
371+
else()
372+
message(STATUS "Docker image ${BASE} not found locally, pulling...")
373+
execute_process(COMMAND "${DOCKER_EXE}" pull ${BASE})
374+
endif()
375+
endwhile()
376+
377+
set(${VAR} ${${VAR}} PARENT_SCOPE)
378+
endfunction()
379+
380+
execute_process(COMMAND cmd /C ver OUTPUT_VARIABLE PIPE OUTPUT_STRIP_TRAILING_WHITESPACE)
381+
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+" HOST_KERNEL "${PIPE}")
382+
383+
set(BASES
384+
mcr.microsoft.com/windows/nanoserver:ltsc2022
385+
mcr.microsoft.com/powershell:lts-nanoserver-ltsc2022
386+
)
387+
388+
_PROMOTE_PROCESS_ISOLATION_("${HOST_KERNEL}" "${BASES}" PROMOTE_TO_PROCESS)
389+
390+
function(_BUILD_IMAGE_ DOCKERFILE CTX TAG)
391+
set(CMD "${DOCKER_EXE}" build)
392+
if(PROMOTE_TO_PROCESS)
393+
list(APPEND CMD --isolation "process")
394+
endif()
395+
list(APPEND CMD -t ${TAG} -f "${DOCKERFILE}" .)
396+
397+
execute_process(COMMAND ${CMD} WORKING_DIRECTORY "${CTX}")
398+
endfunction()
399+
400+
_BUILD_IMAGE_("${NBL_DOCKER_CE_DOCKERFILE_BASE}" "${NBL_DOCKER_CE_DOCKER_CTX}" godbolt/base/windows)
401+
_BUILD_IMAGE_("${DEVEL_DOCKERFILE}" "${DEVEL_CTX}" godbolt/devel/windows)
402+
403+
message(FATAL_ERROR "STOP TEST, PROMOTE_TO_PROCESS = ${PROMOTE_TO_PROCESS}")
353404

354405
string(APPEND BAT_PRODUCTION_INSTALL
355406
[=[

0 commit comments

Comments
 (0)