Skip to content

Commit 24eaa41

Browse files
committed
resources: a cross gcc's Windows headers are the toolchain's; an include nothing provides is the script's own
- system_include_dirs reads a cross gcc's own <root>/<triple>-w64-mingw32/include when no payload is paired: under the mingw provider, a script's "winres.h" was taken for a file of the project that no action produces, and the build failed in ninja (e2e 1058, the cross gcc case). - A quoted include found in no directory is an input only when a build action writes it; otherwise the script's preprocessing decides (#if __has_include) and the resource compiler names a missing one with the script and line (e2e 1072). - docs/04 (en, zh) and CHANGELOG.
1 parent 0261393 commit 24eaa41

7 files changed

Lines changed: 114 additions & 16 deletions

‎CHANGELOG.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,13 @@
146146
each place it looked in and the configuration that declared the stores.
147147
- A GNU-ABI Windows row finds its resource compiler in the paired payload or
148148
uses `llvm-rc`, and a quoted `"winres.h"` is the toolchain's header, not a
149-
generated input.
149+
generated input: the paired payload's, or a cross gcc's own
150+
(`<root>/x86_64-w64-mingw32/include`).
151+
- A resource script's quoted include that no directory holds and no build
152+
action writes is no longer an input of the build graph. Such a build failed
153+
in ninja without the script's name, even when the script included the file
154+
only `#if __has_include`; the resource compiler now reports a missing one
155+
with the script's name and line.
150156
- `patches` on a git dependency that is a workspace member is applied in a
151157
copy of the whole repository, so the member's edges to its siblings hold
152158
(mcpp#911 N5).

‎docs/04-mcpp-toml.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2117,7 +2117,11 @@ statements (`ICON`, `RCDATA`, `MANIFEST`, the numeric type `24`, …), and makes
21172117
them build inputs, so editing the icon relinks. A relative file name is resolved
21182118
against the script's own directory, which is also where rc.exe, llvm-rc and
21192119
windres look for it. Angled includes (`<windows.h>`) are the toolchain's
2120-
and are covered by the toolchain fingerprint instead.
2120+
and are covered by the toolchain fingerprint instead, as is a quoted include the
2121+
toolchain's Windows headers hold (`"winres.h"`). A quoted include found nowhere is
2122+
an input only when a build action writes it; otherwise the script's own
2123+
preprocessing decides (`#if __has_include("x.h")`), and the resource compiler
2124+
reports a missing one with the script's name and line (2026.11.10.1+).
21212125

21222126
A file name reached through a macro (`1 ICON APP_ICON`) is invisible to that
21232127
scan. mcpp names what it could not resolve and requires an explicit declaration:

‎docs/zh/04-mcpp-toml.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,10 @@ mcpp 读取 `.rc` 里带引号的 `#include`,以及资源语句(`ICON`、
19291929
`RCDATA`、`MANIFEST`、数字类型 `24` 等)命名的文件,并把它们变成构建输入,
19301930
所以修改图标会触发重新链接。相对文件名按脚本自己所在的目录解析,rc.exe、
19311931
llvm-rc 与 windres 也在那里查找它。尖括号 include(`<windows.h>`)属于工具链,由
1932-
工具链指纹覆盖,而不是这项扫描。
1932+
工具链指纹覆盖,而不是这项扫描;工具链的 Windows 头文件中已有的带引号 include
1933+
(`"winres.h"`)同样如此。各处都找不到的带引号 include,只有在某个构建动作写出它时
1934+
才是输入;否则由脚本自身的预处理决定(`#if __has_include("x.h")`),缺失时由资源
1935+
编译器报告,并给出脚本名与行号(2026.11.10.1+)。
19331936

19341937
一个经由宏到达的文件名(`1 ICON APP_ICON`)对这项扫描是不可见的。
19351938
mcpp 会点名它无法解析的部分,并要求显式声明:

‎src/build/prepare/windows_resources.cpp‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,21 @@ std::expected<void, std::string> step13_windows_resources(PrepareState& state, B
424424
"UTF-8</activeCodePage>` to your manifest and set "
425425
"`windows_code_page = \"legacy\"`, or drop your manifest.",
426426
rcSrc.filename().generic_string()));
427-
auto inputs = std::move(scan.inputs);
427+
// A name found nowhere is an input only when a build action
428+
// writes it. Otherwise the script's own preprocessing decides
429+
// (`#if __has_include`), or the resource compiler names it; a
430+
// build graph edge on a file nothing produces would only fail
431+
// in ninja, without the script's name.
432+
std::vector<std::filesystem::path> inputs;
433+
for (auto& in : scan.inputs) {
434+
std::error_code ec;
435+
const bool written = std::ranges::any_of(ctx.plan.actions, [&](auto const& act) {
436+
return std::ranges::any_of(act.outputs, [&](auto const& o) {
437+
return std::filesystem::path(o).filename() == in.filename();
438+
});
439+
});
440+
if (written || std::filesystem::exists(in, ec)) inputs.push_back(std::move(in));
441+
}
428442
inputs.insert(inputs.end(), extraInputs.begin(), extraInputs.end());
429443
if (auto a = add_unit(rcSrc, rcSrc.stem().string(),
430444
std::move(inputs),

‎src/build/resources.cppm‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ std::string coff_target_flag(const RcTool& tool, std::string_view targetTriple);
9797

9898
// The toolchain's Windows header directories, which a resource script reaches
9999
// with `#include "winres.h"` as well as with angle brackets: the INCLUDE an
100-
// MSVC backend states, and on a GNU-ABI row the paired payload's
101-
// `<arch>-w64-mingw32/include` (design 2026-11-10 E3). One list for the
100+
// MSVC backend states, and on a GNU-ABI row the paired payload's (or a cross
101+
// gcc's own) `<arch>-w64-mingw32/include` (design 2026-11-10 E3). One list for the
102102
// compile's `/I` and for the scan of what the script reads.
103103
std::vector<std::filesystem::path> system_include_dirs(const mcpp::toolchain::Toolchain& tc,
104104
std::string_view dialectId);
@@ -211,17 +211,27 @@ std::vector<std::filesystem::path> system_include_dirs(const mcpp::toolchain::To
211211
if (ev.key != "INCLUDE") continue;
212212
for (auto dir : split_env_list(ev.value)) out.emplace_back(std::string(dir));
213213
}
214-
if (dialectId != "msvc" && !tc.pairedSysroot.empty()) {
215-
std::error_code ec;
216-
// A base package keeps the headers of every architecture in one
217-
// `<root>/include` (E9); a gcc payload under `<triple>/include`.
218-
if (std::filesystem::is_directory(tc.pairedSysroot / "include", ec))
219-
out.push_back(tc.pairedSysroot / "include");
220-
for (auto const& entry : std::filesystem::directory_iterator(tc.pairedSysroot, ec))
214+
if (dialectId == "msvc") return out;
215+
std::error_code ec;
216+
// A gcc payload keeps the target's headers under `<triple>/include`.
217+
auto add_triple_dirs = [&](const std::filesystem::path& root) {
218+
for (auto const& entry : std::filesystem::directory_iterator(root, ec))
221219
if (auto inc = entry.path() / "include";
222220
entry.path().filename().string().ends_with("-w64-mingw32")
223221
&& std::filesystem::is_directory(inc, ec))
224222
out.push_back(inc);
223+
};
224+
if (!tc.pairedSysroot.empty()) {
225+
// A base package keeps the headers of every architecture in one
226+
// `<root>/include` (E9).
227+
if (std::filesystem::is_directory(tc.pairedSysroot / "include", ec))
228+
out.push_back(tc.pairedSysroot / "include");
229+
add_triple_dirs(tc.pairedSysroot);
230+
} else if (!tc.binaryPath.empty()) {
231+
// A cross gcc is its own payload: `<root>/bin/<triple>-gcc` beside
232+
// `<root>/<triple>/include` (its configured sysroot names where it was
233+
// built, not where it is).
234+
add_triple_dirs(tc.binaryPath.parent_path().parent_path());
225235
}
226236
return out;
227237
}

‎tests/e2e/1058_a_gnu_abi_windows_row_compiles_its_resources.sh‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ source "$(dirname "${BASH_SOURCE[0]}")/_toolchain_env.sh"
88
# `[resources]`, while the payload's `bin/` held one. The search now includes the paired payload;
99
# a clang with no windres anywhere compiles with the `llvm-rc` beside it, whose `.res` `ld.lld`
1010
# links on this row. A script that includes the toolchain's `"winres.h"` reads it from the
11-
# payload's headers, not from the project.
11+
# payload's headers, not from the project: the paired payload's under llvm, and under the cross
12+
# gcc of the `mingw` provider, which is its own payload, `<root>/x86_64-w64-mingw32/include`.
1213
#
13-
# Criteria: the program builds with `[resources]` under llvm paired with MinGW-w64 and carries a
14-
# VERSIONINFO resource.
14+
# Criteria: the program builds with `[resources]` under llvm paired with MinGW-w64 and under the
15+
# cross gcc, and carries a VERSIONINFO resource each time.
1516
set -e
1617
t=$(mktemp -d); trap 'rm -rf "$t"' EXIT
1718
fail() { echo "FAIL: $1"; [ -n "${2:-}" ] && printf '%s\n' "$2" | tail -20; exit 1; }
@@ -52,4 +53,12 @@ exe=$(find target/x86_64-windows-gnu -path '*/bin/verinfo.exe' -type f | head -1
5253
readobj="$_e2e_registry_base/xim-x-llvm/${LLVM_VERSION}/bin/llvm-readobj"
5354
[ -x "$readobj" ] || fail "no llvm-readobj in the llvm payload ($readobj)"
5455
"$readobj" --coff-resources "$exe" | grep -q 'VERSIONINFO' || fail "the program carries no VERSIONINFO" "$("$readobj" --coff-resources "$exe" | head -20)"
56+
# The cross gcc: before, its `"winres.h"` was taken for a file of the project that no action
57+
# produces (`ninja: error: '<project>/winres.h' ... missing`).
58+
rm -rf target
59+
out=$("$MCPP" build --target x86_64-windows-gnu 2>&1) \
60+
|| fail "[resources] did not build on x86_64-windows-gnu with the cross gcc" "$out"
61+
exe=$(find target/x86_64-windows-gnu -path '*/bin/verinfo.exe' -type f | head -1)
62+
[ -n "$exe" ] || fail "no program from the cross gcc"
63+
"$readobj" --coff-resources "$exe" | grep -q 'VERSIONINFO' || fail "the cross gcc's program carries no VERSIONINFO"
5564
echo "PASS: 1058 a GNU-ABI Windows row compiles its resources"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
# requires: mingw-cross
3+
source "$(dirname "${BASH_SOURCE[0]}")/_toolchain_env.sh"
4+
# 1072 -- a resource script's quoted include that no directory holds and no build action writes is
5+
# the script's own matter, not an input of the build graph.
6+
#
7+
# The scan of a script records each quoted include it finds in the script's directories, else
8+
# against the script's directory, where a file a build action produces is ordered before the
9+
# compile. A name nothing produces became a graph input no rule makes, and the build failed in
10+
# ninja without the script's name (`ninja: error: '<project>/absent.h', needed by 'res/app.o',
11+
# missing and no known rule to make it`), even when the script includes it only
12+
# `#if __has_include`. Such a name is now left to the script's preprocessing and to the resource
13+
# compiler, which names the script and its line; a name a build action writes stays an input.
14+
#
15+
# Criteria: a script that includes an absent header under `__has_include` builds; one that
16+
# includes it unconditionally fails with the resource compiler's message naming the script.
17+
set -e
18+
t=$(mktemp -d); trap 'rm -rf "$t"' EXIT
19+
fail() { echo "FAIL: $1"; [ -n "${2:-}" ] && printf '%s\n' "$2" | tail -20; exit 1; }
20+
mkdir -p "$t/src"
21+
cat > "$t/mcpp.toml" <<'TOML'
22+
[package]
23+
name = "rcinc"
24+
version = "0.1.0"
25+
26+
[resources]
27+
files = ["app.rc"]
28+
29+
[targets.rcinc]
30+
kind = "bin"
31+
main = "src/main.c"
32+
TOML
33+
echo 'int main(void) { return 0; }' > "$t/src/main.c"
34+
cat > "$t/app.rc" <<'RC'
35+
#if __has_include("absent.h")
36+
#include "absent.h"
37+
#endif
38+
1 VERSIONINFO
39+
FILEVERSION 1,0,0,0
40+
BEGIN
41+
END
42+
RC
43+
cd "$t"
44+
out=$("$MCPP" build --target x86_64-windows-gnu 2>&1) \
45+
|| fail "a script that includes an absent header under __has_include did not build" "$out"
46+
find target/x86_64-windows-gnu -path '*/bin/rcinc.exe' -type f | grep -q . || fail "no program"
47+
# Unconditional: the resource compiler's error, naming the script.
48+
sed -i '1d;3d' app.rc
49+
if out=$("$MCPP" build --target x86_64-windows-gnu 2>&1); then fail "an absent header included unconditionally built" "$out"; fi
50+
grep -q 'ninja: error' <<<"$out" && fail "the build failed in ninja, not in the resource compiler" "$out"
51+
grep -q 'app.rc' <<<"$out" || fail "the failure does not name the script" "$out"
52+
echo "PASS: 1072 a resource include nothing provides is the script's own"

0 commit comments

Comments
 (0)