Skip to content

fix(windows): extract mdk-sdk via realpath to avoid CMake symlink rejection#367

Merged
wang-bin merged 2 commits into
wang-bin:masterfrom
abdelaziz-mahdy:fix/mdk-sdk-extract-through-symlink
Jun 20, 2026
Merged

fix(windows): extract mdk-sdk via realpath to avoid CMake symlink rejection#367
wang-bin merged 2 commits into
wang-bin:masterfrom
abdelaziz-mahdy:fix/mdk-sdk-extract-through-symlink

Conversation

@abdelaziz-mahdy

Copy link
Copy Markdown
Contributor

Fixes #366.

Problem

flutter build windows --release fails in fvp_setup_deps while extracting mdk-sdk-windows-x64.7z:

CMake Error: Problem with archive_write_header(): Cannot extract through symlink
  ...\windows\flutter\ephemeral\.plugin_symlinks\fvp
Failed to extract mdk-sdk.

On Flutter Windows, CMAKE_CURRENT_SOURCE_DIR is reached through the generated plugin symlink (.plugin_symlinks/fvp). Newer CMake's cmake -E tar extracts with ARCHIVE_EXTRACT_SECURE_SYMLINKS and refuses to write entries through a symlinked directory. The download itself is fine (verified: byte-identical 7z, valid magic) — only the extraction step is rejected. This started when CI runner images bumped their bundled CMake (≥ 3.31), with no project change.

Fix

Resolve CMAKE_CURRENT_SOURCE_DIR to its real (non-symlinked) path and extract there:

get_filename_component(MDK_SDK_EXTRACT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH)
execute_process(
  COMMAND ${CMAKE_COMMAND} -E tar "xvf" ${MDK_SDK_SAVE}
  WORKING_DIRECTORY ${MDK_SDK_EXTRACT_DIR}
  ...)

get_filename_component(... REALPATH) is used instead of file(REAL_PATH) to stay compatible with the plugin's cmake_minimum_required(VERSION 3.17). On platforms where the path is not a symlink, REALPATH is a no-op (resolves to the same directory), so behavior is unchanged elsewhere. The subsequent include(${CMAKE_CURRENT_SOURCE_DIR}/mdk-sdk/.../FindMDK.cmake) still resolves through the symlink (reading through a symlink is fine).

Verification

Built the example/ app on windows-latest (same runner image that fails today, same plugin-symlink scenario, same mdk-sdk download). It now extracts and builds successfully:

Downloading mdk-sdk from https://sourceforge.net/projects/mdk-sdk/files/nightly/mdk-sdk-windows-x64.7z
MDK_SDK_MD5_SAVE: 1e59ba0aed23f2723642c69fec07888e
Building Windows application...                    79.3s
√ Built build\windows\x64\runner\Release\fvp_example.exe

(no Cannot extract through symlink.)

…ection

On Flutter Windows, CMAKE_CURRENT_SOURCE_DIR is reached through the generated
plugin symlink (.../flutter/ephemeral/.plugin_symlinks/fvp). Newer CMake's
`cmake -E tar` extracts with ARCHIVE_EXTRACT_SECURE_SYMLINKS and refuses to
write entries through that symlinked directory:

    CMake Error: Problem with archive_write_header():
      Cannot extract through symlink ...\.plugin_symlinks\fvp
    Failed to extract mdk-sdk.

Resolve CMAKE_CURRENT_SOURCE_DIR to its real (non-symlinked) path with
get_filename_component(... REALPATH) and use it as the tar WORKING_DIRECTORY,
so extraction no longer traverses the symlink. REALPATH (not file(REAL_PATH))
keeps this compatible with cmake_minimum_required(VERSION 3.17).

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request resolves the real path of CMAKE_CURRENT_SOURCE_DIR to prevent extraction failures on Flutter Windows, where the directory is accessed via a symlink and newer CMake versions refuse to extract through symlinks. The feedback recommends wrapping the path variables in double quotes within the execute_process command to avoid build failures when paths contain spaces.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread cmake/deps.cmake
Comment on lines 87 to 92
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar "xvf" ${MDK_SDK_SAVE} # "--format=7zip"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
WORKING_DIRECTORY ${MDK_SDK_EXTRACT_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE EXTRACT_RET
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential build failures when the project path or the build directory contains spaces (which is common on Windows, e.g., under C:\Program Files or user directories with spaces), it is highly recommended to wrap ${MDK_SDK_SAVE} and ${MDK_SDK_EXTRACT_DIR} in double quotes within the execute_process command.

    execute_process(
      COMMAND ${CMAKE_COMMAND} -E tar "xvf" "${MDK_SDK_SAVE}" # "--format=7zip"
      WORKING_DIRECTORY "${MDK_SDK_EXTRACT_DIR}"
      OUTPUT_STRIP_TRAILING_WHITESPACE
      RESULT_VARIABLE EXTRACT_RET
    )

Per review (paths with spaces): quote MDK_SDK_SAVE and the resolved
WORKING_DIRECTORY so extraction doesn't break on paths containing spaces.
@wang-bin wang-bin merged commit ce6236d into wang-bin:master Jun 20, 2026
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flutter build windows fails: cmake -E tar cannot extract mdk-sdk through .plugin_symlinks (secure-symlink extraction in newer CMake)

2 participants