Skip to content

Commit 7245760

Browse files
committed
m3: a stated program name on every row, one linked file, resources for Windows programs
- N9: the statement's program and library names are followed on a built-in row as on a platform's; the temporary link name keeps the file's extension, so DJGPP writes one file. - N16: [resources] is compiled for a PE row whose execution system is Windows, not for UEFI.
1 parent d96e7fd commit 7245760

7 files changed

Lines changed: 69 additions & 9 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@
3131

3232
### Fixed
3333

34+
- A name a build program, this machine or the project states for a program
35+
(`mcpp::artifact_name("exe", "{name}")`) is followed on a built-in row as on
36+
a platform's: a program named `cmd.exe` was `cmd.exe.exe` on
37+
x86_64-windows-gnu and `cmd.exe` on x86_64-windows-musl (design 2026-11-15
38+
N9).
39+
- A linked program is written under a temporary name that keeps its extension
40+
(`<dir>/.<file>`, then renamed). DJGPP's driver names a second file after the
41+
output's extension, so `<out>.tmp` left two programs in `bin/` on
42+
i586-dos-djgpp (N9).
43+
- `[resources]` and the application manifest are compiled only for a PE row
44+
whose execution system is Windows; the UEFI row, a PE image the firmware
45+
loads, failed the build with them (N16).
3446
- Two `[build-dependencies]` requests of one package that no version
3547
satisfies are refused as such, naming both requesters, the merge's reason and
3648
the `override` line. The engine tried to rename the second copy's modules,

‎docs/04-mcpp-toml.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,8 +2056,10 @@ generates the resource script automatically.
20562056
| `version-info` | bool | `false` opts out of the generated version resource |
20572057
| `[resources.version-info]` | table | `company`, `product`, `description`, `copyright`, `original-filename`, `internal-name` |
20582058

2059-
**Only PE targets *compile* this.** On Linux and macOS the section is
2060-
*inapplicable*: no resource units, no diagnostics, byte-identical build. You do
2059+
**Only targets whose programs Windows runs *compile* this**: PE rows whose
2060+
execution system is Windows. Elsewhere the section is *inapplicable* --- Linux,
2061+
macOS, and a PE row another system loads, such as `x86_64-uefi` (2026.11.16.1):
2062+
no resource units, no diagnostics, byte-identical build. You do
20612063
**not** need (and cannot use) a `cfg(windows)` predicate — write it once,
20622064
unconditionally.
20632065

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,8 +1874,8 @@ icon = "assets/app.ico"
18741874
| `version-info` | 布尔值 | `false` 退出自动生成版本资源 |
18751875
| `[resources.version-info]` | 表 | `company`、`product`、`description`、`copyright`、`original-filename`、`internal-name` |
18761876

1877-
**只有 PE 目标会*编译*它。** 在 Linux 与 macOS 上,这一节*不适用*:
1878-
没有资源单元、没有诊断、构建逐字节相同。**不需要**(也不能用)一个
1877+
**只有程序由 Windows 运行的目标会*编译*它**:执行系统为 Windows 的 PE 行。在其他目标上这一节*不适用*——
1878+
Linux、macOS,以及由其他系统加载的 PE 行,如 `x86_64-uefi`(2026.11.16.1):没有资源单元、没有诊断、构建逐字节相同。**不需要**(也不能用)一个
18791879
`cfg(windows)` 谓词——写一次,无条件生效即可。
18801880

18811881
资源属于拥有可执行程序或共享库的包。依赖的 executable artifact 与共享库在通过

‎src/build/ninja_backend.cppm‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,8 +2393,14 @@ std::string emit_ninja_string(const BuildPlan& plan, std::string* placements,
23932393
if (inPlaceTarget) return cmd;
23942394
const auto pos = cmd.find("-o $out");
23952395
if (pos == std::string::npos) return cmd;
2396-
cmd.replace(pos, 7, "-o $out.tmp");
2397-
return cmd + " && mv -f $out.tmp $out";
2396+
// THE TEMPORARY NAME KEEPS THE FILE'S EXTENSION: `<dir>/.<file>`,
2397+
// not `<out>.tmp`. A linker that names a file after its output's
2398+
// extension writes a second file otherwise: DJGPP's driver, given
2399+
// `-o x.exe.tmp`, writes `x.exe.tmp` and `x.exe.exe` (measured with
2400+
// GCC 12.2.0 for i586-pc-msdosdjgpp; `-o x.exe` writes one file),
2401+
// and the package held two programs (design 2026-11-15 N9).
2402+
cmd.replace(pos, 7, "-o $$t");
2403+
return "t=$$(dirname $out)/.$$(basename $out) && " + cmd + " && mv -f $$t $out";
23982404
}
23992405
};
24002406
{

‎src/build/plan.cppm‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1976,7 +1976,16 @@ make_plan(const mcpp::manifest::Manifest& manifest,
19761976
// The patterns were checked where they were read.
19771977
// `ArtifactNaming` holds views; these are views into the platform's own
19781978
// strings, which outlive the plan's construction.
1979-
if (platform && platform->active) {
1979+
//
1980+
// THE STATEMENT NAMES THEM ON EVERY ROW (design 2026-11-15 N9), with a
1981+
// platform or without: a build program, this machine or the project that
1982+
// names a program `{name}` is followed on a built-in row as on a
1983+
// platform's. The row's own suffix (`.exe` of a Windows row) was appended
1984+
// regardless where no platform was selected, and a program the project
1985+
// named `cmd.exe` was `cmd.exe.exe` on x86_64-windows-gnu and `cmd.exe` on
1986+
// x86_64-windows-musl. A platform's own suffix still stands against a
1987+
// build program (`keep_platform_naming`).
1988+
if (platform) {
19801989
constexpr std::string_view kName = "{name}";
19811990
auto const& l = platform->fields.link;
19821991
if (l.exe.set && mcpp::platform::split_name_pattern(l.exe.value)) {

‎src/build/prepare/windows_resources.cpp‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ std::expected<void, std::string> step13_windows_resources(PrepareState& state, B
264264
// see a typo in `icon = …` at all and only the Windows job went red,
265265
// which is the same "find out late" failure the hard error exists to
266266
// remove. Existence is checked everywhere; only COMPILATION is PE-only.
267-
// 3. On a non-PE target nothing is compiled — no units, no warning,
267+
// 3. On a target whose programs Windows does not run (not PE, or a PE
268+
// row whose execution system is another, UEFI's) nothing is
269+
// compiled — no units, no warning,
268270
// byte-identical build. This is what makes `cfg(windows)` unnecessary
269271
// (and it could not be used anyway: the conditional channel carries
270272
// BuildInputs only).
@@ -634,7 +636,12 @@ std::expected<void, std::string> step13_windows_resources(PrepareState& state, B
634636
return {};
635637
};
636638

637-
if (trip.is_pe())
639+
// Windows resources are a property of a program Windows runs, not
640+
// of the PE container: a UEFI application is a PE image the
641+
// firmware loads, and `[resources]` compiled into it failed the
642+
// build (design 2026-11-15 N16). The row's execution system
643+
// decides (SPEC-016 §6), as rule 3 does for every other target.
644+
if (trip.is_pe() && trip.execution_system() == "windows")
638645
if (auto r = plan_resources(); !r) return std::unexpected(r.error());
639646
}
640647
}

‎tests/e2e/windows/rows.cpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,30 @@ E2E rows{"rows", [] {
7373
expect(fatal(e2e::succeeded(r))) << "[resources] did not build on x86_64-windows-musl: " << s::text(r);
7474
carries_versioninfo(p, "x86_64-windows-musl", "verinfo");
7575
};
76+
77+
"1089 a program's stated name is followed on every windows row"_test[s::mingw_cross][s::llvm] = [] {
78+
// A build program that names the program `{name}` is followed on the built-in GNU-ABI row
79+
// as on the row a platform serves: a target named `cmd.exe` is `cmd.exe` on both, and
80+
// no `cmd.exe.exe` (design 2026-11-15 N9).
81+
s::project p{{"mcpp.toml", "[package]\nname = \"named\"\nversion = \"0.1.0\"\n\n[targets.\"cmd.exe\"]\nkind = \"bin\"\nmain = \"src/main.c\"\n"},
82+
{"src/main.c", "int main(void) { return 0; }\n"},
83+
{"build.mcpp", "import mcpp;\nint main() { mcpp::artifact_name(\"exe\", \"{name}\"); return 0; }\n"}};
84+
for (std::string_view row : {"x86_64-windows-gnu", "x86_64-windows-musl"}) {
85+
auto r = p.mcpp({"build", "--target", std::string(row), "--toolchain", "llvm@" + s::llvm_version()});
86+
expect(fatal(e2e::succeeded(r))) << row << ": " << s::text(r);
87+
expect(fatal(s::find_file(p.at("target") / std::string(row), "cmd.exe").has_value())) << row << ": no cmd.exe";
88+
expect(fatal(!s::find_file(p.at("target") / std::string(row), "cmd.exe.exe").has_value())) << row << ": the row's suffix was appended to the stated name";
89+
}
90+
};
91+
92+
"1090 a uefi application compiles no windows resources"_test[s::llvm] = [] {
93+
// `[resources]` belongs to a program Windows runs: the UEFI row, a PE image the firmware
94+
// loads, builds without them and without a word (design 2026-11-15 N16).
95+
s::project p{{"mcpp.toml", manifest("efiapp")}, {"src/main.c", "int main(void) { return 0; }\n"}, {"app.rc", verinfo_rc}};
96+
const auto r = p.mcpp({"build", "--target", "x86_64-uefi"});
97+
expect(fatal(e2e::succeeded(r))) << "[resources] failed the UEFI build: " << s::text(r);
98+
expect(fatal(s::lacks(s::text(r), "app.rc"))) << "the UEFI build spoke of the resource script: " << s::text(r);
99+
};
76100
}};
77101

78102
} // namespace

0 commit comments

Comments
 (0)