diff --git a/.github/workflows/probe-windows-archive.yml b/.github/workflows/probe-windows-archive.yml new file mode 100644 index 00000000..74468f79 --- /dev/null +++ b/.github/workflows/probe-windows-archive.yml @@ -0,0 +1,33 @@ +# Temporary probe (closed after it answers): (1) does MSVC's link.exe keep a +# locally defined function reached only through an __imp_ slot under /OPT:REF, +# where lld-link collects it; (2) do compat.xz and compat.libarchive stating their static-API macros for +# their consumers (a default-implied feature) end the archive members' crash. +name: probe-windows-archive +on: + pull_request: + paths: ['.github/workflows/probe-windows-archive.yml'] +jobs: + archive: + runs-on: windows-2022 + timeout-minutes: 60 + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@v4 + - name: mcpp 2026.11.21.1 + run: | + set -euo pipefail + curl -fsSL --retry 5 -o m.zip "https://github.com/mcpp-community/mcpp/releases/download/v2026.11.21.1/mcpp-2026.11.21.1-windows-x86_64.zip" + unzip -q m.zip + echo "$PWD/mcpp-2026.11.21.1-windows-x86_64/bin" >> "$GITHUB_PATH" + echo "MCPP_HOME=$HOME/.mcpp-probe" >> "$GITHUB_ENV" + - name: the archive members with LZMA_API_STATIC and LIBARCHIVE_STATIC + run: | + set +e + for p in archive-tests libarchive-bundle; do + echo "== $p" + mcpp test -p "$p" --toolchain llvm@23.1.3 2>&1 | tail -25 + echo "RESULT $p exit=${PIPESTATUS[0]}" + done + exit 0 diff --git a/pkgs/c/compat.libarchive.lua b/pkgs/c/compat.libarchive.lua index e658a4ba..4e73656d 100644 --- a/pkgs/c/compat.libarchive.lua +++ b/pkgs/c/compat.libarchive.lua @@ -44,9 +44,21 @@ package = { include_dirs = {"*", "*/libarchive", "mcpp_generated/include"}, cflags = { "-D_GNU_SOURCE", - "-DLIBARCHIVE_STATIC", "-DPLATFORM_CONFIG_H=\\\"mcpp_libarchive_config.h\\\"", }, + -- archive.h and archive_entry.h declare every function + -- __declspec(dllimport) on Windows unless LIBARCHIVE_STATIC is defined, + -- and this package is a static library. Every TU that includes them + -- needs it, this package's and its consumers': a consumer without it + -- calls through `__imp_archive_*` slots that lld-link makes, and a link + -- that collects unreferenced sections drops the functions behind them + -- (the first call jumps to the image's first byte; compat.xz states the + -- measurement). A feature's `defines` reach the consumer, and `default` + -- implies it unconditionally, as CURL_STATICLIB in compat.curl. + features = { + ["default"] = { implies = { "staticlib" } }, + ["staticlib"] = { defines = { "LIBARCHIVE_STATIC" } }, + }, -- macOS with musl as the C library (an openkal graph). libarchive -- reads __APPLE__ as "the Apple SDK is present" (TargetConditionals.h, -- copyfile, quarantine) in four private translation units and in the diff --git a/pkgs/c/compat.xz.lua b/pkgs/c/compat.xz.lua index 979e12be..77c29ac9 100644 --- a/pkgs/c/compat.xz.lua +++ b/pkgs/c/compat.xz.lua @@ -52,6 +52,22 @@ package = { "*/src/liblzma/simple", "*/src/common", }, + + -- declares every function __declspec(dllimport) on Windows + -- unless LZMA_API_STATIC is defined, and this package is a static + -- library. A consumer that includes it without the macro calls through + -- `__imp_lzma_*` slots that lld-link makes for the locally defined + -- functions; a link that collects unreferenced sections (the release + -- profile, a test's link) drops the functions behind the slots, and + -- the first call jumps to the image's first byte. The macro reaches + -- every TU that includes the header the same way CURL_STATICLIB does + -- in compat.curl: a feature's `defines` reach the consumer, and + -- `default` implies it unconditionally. + features = { + ["default"] = { implies = { "staticlib" } }, + ["staticlib"] = { defines = { "LZMA_API_STATIC" } }, + }, + cflags = { "-D_GNU_SOURCE", "-DSIZEOF_SIZE_T=8",