Skip to content

Commit e77b920

Browse files
fix: a helper that reaches mcpplibs.os is not inline, which GCC 16 cannot read back from an importer
Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com>
1 parent 6305d89 commit e77b920

9 files changed

Lines changed: 22 additions & 14 deletions

File tree

‎dist/apk.cppm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ inline std::string sha256_file(const std::string& path) {
788788
// `mcpp::plugins::tool::capture`: no shell between, so no argument is quoted.
789789
// Only the explicit Maven modes and AAR extraction call it; an ordinary build
790790
// of an unchanged project runs nothing here.
791-
inline int run_capture(const std::vector<std::string>& argv, std::string& output,
791+
int run_capture(const std::vector<std::string>& argv, std::string& output,
792792
const std::filesystem::path& cwd = {}) {
793793
auto r = mcpp::plugins::tool::capture(argv, /*with_errors=*/true, cwd);
794794
output = std::move(r.out);

‎docs/plugin-development.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ Known differences, each one met in this package:
203203
- **No compiler's leniency is relied on.** An extension, a missing `typename`, or a template accepted only because one compiler instantiates it later is a failure in another lane.
204204
- **A build program does not use `std::println`.** On macOS 14 the build program links the system libc++, which lacks a symbol it needs; `std::format` into a string and `std::cout` work everywhere.
205205
- **No unit includes a header or branches on the platform in the preprocessor.** The C library comes from `std`, which exports the functions and types of ISO C (`std::isalnum`, `std::getenv`, `std::FILE`) but no macro; a macro of ISO C (`stdout`, `errno`, `SEEK_SET`) comes from `mcpplibs.mwrap.libc` under its own name (`mcpplibs::mwrap::libc::macros::stdout()`). The operating system comes from `mcpplibs.os`: a program a member asks for a fact runs through `mcpp::plugins::tool::capture` (its arguments as a vector, no shell, so nothing is quoted and no null device is named), a library opens through `mcpplibs::os::library::open`, and a child's environment is stated in its spawn options rather than written into this process's. A build program runs on the machine that builds, so a platform difference is a compile-time question of that machine: `if constexpr (mcpplibs::os::is_windows)`. CI refuses an `#include`, `#if` or `#ifdef` in a unit (0.21.0).
206+
- **A function that reaches mcpplibs.os is not `inline`.** A rule's helper that runs a program (`mcpp::plugins::tool::capture`) or opens a library is defined without `inline`, so it is compiled once in its module and an importer sees its declaration only. Under GCC 16 an importer that reads such a body from an inline function fails: "failed to read compiled module cluster: Bad file data", or an unresolved `std::optional<std::vector<grant>>` at the link (`tests/metal-consumer`, 0.21.0).
206207
- **A module does not instantiate `std::filesystem::path`'s iterator.** Under MSVC 14.52 every importer that then touches `std::filesystem` fails inside the STL; `mcpp::plugins::names::components` splits a path as a string instead.
207208

208209
## 5. A new plugin

‎rules/cuda.cppm‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ inline std::optional<toolkit> find_toolkit(const options& opt, bool& pending) {
318318
// The driver's version through the driver's own library, reached through the
319319
// sentinel package rather than /usr/lib. "" when there is no driver here,
320320
// which is a fact about the machine and not a failure of the build.
321-
inline std::string driver_version(const toolkit& t) {
321+
std::string driver_version(const toolkit& t) {
322322
if constexpr (kWindows) return {};
323323
if (t.driver_dir.empty()) return {};
324324
const auto lib = t.driver_dir + "/lib/libcuda.so.1";
@@ -443,7 +443,7 @@ inline bool libc_declares_c23_pi_math(std::string_view sysroot) {
443443

444444
// `<compiler> -dumpversion` → major. The host compiler is the toolchain mcpp
445445
// resolved for this build, so its version is a fact of the build, not a guess.
446-
inline int compiler_major(const std::string& cc) {
446+
int compiler_major(const std::string& cc) {
447447
if constexpr (kWindows) return 0;
448448
return major_of(mcpp::plugins::tool::first_line({cc, "-dumpversion"}));
449449
}
@@ -452,7 +452,7 @@ inline int compiler_major(const std::string& cc) {
452452
// nvcc invokes cicc, cudafe++, ptxas and fatbinary by bare name on a PATH it
453453
// states in the plan; a stage that does not resolve there fails the compile
454454
// with `sh: 1: cicc: not found`, naming nothing that helps.
455-
inline std::optional<std::string> unreachable_stage(const toolkit& t, const std::string& ccbin) {
455+
std::optional<std::string> unreachable_stage(const toolkit& t, const std::string& ccbin) {
456456
if constexpr (kWindows) return std::nullopt;
457457
const auto probe = std::filesystem::temp_directory_path() / "mcpp-rules-cuda-dryrun.cu";
458458
{ std::ofstream(probe) << "__global__ void k() {}\n"; }

‎rules/metal.cppm‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ inline std::vector<std::string> device_shaders() {
113113
// ─── The toolchain ─────────────────────────────────────────────────────────
114114

115115
// The SDK's path, or empty when `xcrun` cannot locate it.
116-
inline std::string sdk_path(const std::string& sdk) {
116+
std::string sdk_path(const std::string& sdk) {
117117
if constexpr (mcpplibs::os::is_windows) return {};
118118
const std::string path = mcpp::plugins::tool::first_line({"/usr/bin/xcrun", "--sdk", sdk, "--show-sdk-path"});
119119
std::error_code ec;
120120
return !path.empty() && std::filesystem::is_directory(path, ec) ? path : std::string();
121121
}
122122

123-
inline std::string find_tool(const std::string& sdk, const char* tool) {
123+
std::string find_tool(const std::string& sdk, const char* tool) {
124124
if constexpr (mcpplibs::os::is_windows) return {};
125125
const std::string path = mcpp::plugins::tool::first_line({"/usr/bin/xcrun", "--sdk", sdk, "--find", tool});
126126
std::error_code ec;

‎rules/slang.cppm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ inline mcpp::plugins::tool::found find_compiler(const options& opt) {
232232
}
233233

234234
// `slangc -v` prints the release on its own, e.g. `2026.14.1`.
235-
inline std::string compiler_version(const std::string& exe) {
235+
std::string compiler_version(const std::string& exe) {
236236
auto text = mcpp::plugins::tool::capture({exe, "-v"}, /*with_errors=*/true).out;
237237
for (auto& c : text) if (c == '\r') c = '\n';
238238
auto nl = text.find('\n');

‎rules/spirv.cppm‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,12 @@ inline compiler find_compiler(const options& opt) {
368368
// says so once — refusing would make an optional pass a requirement, and
369369
// passing it silently would let the manifest claim an optimisation that did
370370
// not happen.
371-
inline bool has_optimizer(const std::string& exe) {
371+
bool has_optimizer(const std::string& exe) {
372372
const auto out = mcpp::plugins::tool::capture({exe, "-Os", "--version"}, /*with_errors=*/true).out;
373373
return out.find("optimizer not linked") == std::string::npos;
374374
}
375375

376-
inline std::string compiler_version(const compiler& cc) {
376+
std::string compiler_version(const compiler& cc) {
377377
const std::string text = mcpp::plugins::tool::capture({cc.path, "--version"}).out;
378378
// glslc: `shaderc v2026.3 2fbab05...` on the first line. glslang:
379379
// `Glslang Version: 11:15.1.0`, whose first field is the SPIR-V generator

‎rules/swift.cppm‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,14 @@ inline std::vector<std::string> device_swift_sources() {
167167

168168
// ─── The toolchain ─────────────────────────────────────────────────────────
169169

170-
inline std::string sdk_path(const std::string& sdk) {
170+
std::string sdk_path(const std::string& sdk) {
171171
if constexpr (mcpplibs::os::is_windows) return {};
172172
const std::string path = mcpp::plugins::tool::first_line({"/usr/bin/xcrun", "--sdk", sdk, "--show-sdk-path"});
173173
std::error_code ec;
174174
return !path.empty() && std::filesystem::is_directory(path, ec) ? path : std::string();
175175
}
176176

177-
inline std::string find_swiftc(const std::string& sdk) {
177+
std::string find_swiftc(const std::string& sdk) {
178178
if constexpr (mcpplibs::os::is_windows) return {};
179179
const std::string path = mcpp::plugins::tool::first_line({"/usr/bin/xcrun", "--sdk", sdk, "--find", "swiftc"});
180180
std::error_code ec;

‎rules/sycl.cppm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ inline std::string cxx_gcc_root() {
270270
// `dpcpp --version` states the release and the intel/llvm revision it was
271271
// built from. Stated as a fact so a build log answers "which SYCL compiler"
272272
// without anyone reproducing the build.
273-
inline std::string compiler_version(const std::string& exe) {
273+
std::string compiler_version(const std::string& exe) {
274274
const std::string text = mcpp::plugins::tool::capture({exe, "--version"}).out;
275275
for (auto line : split(text, '\n')) {
276276
auto at = line.find("DPC++ compiler ");

‎src/tool.cppm‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,19 @@ inline std::string describe_missing(const spec& s, const found& f) {
353353
// error is dropped, or appended to the output when `with_errors`. A program that
354354
// does not end within a minute is ended; `status` is then the shell's code for
355355
// it, and -1 when the program could not be started at all.
356+
//
357+
// NOT INLINE: the two are compiled once, in this unit, and an importer sees
358+
// only their declarations. GCC 16 fails an importer that instantiates
359+
// mcpplibs.os's types from another module's inline body: it cannot read the
360+
// module back ("failed to read compiled module cluster: Bad file data") or
361+
// leaves `std::optional<std::vector<grant>>` unresolved at the link
362+
// (`tests/metal-consumer`; docs/plugin-development.md §4).
356363
struct printed {
357364
int status = -1;
358365
std::string out;
359366
};
360367

361-
inline printed capture(const std::vector<std::string>& argv, bool with_errors = false,
368+
printed capture(const std::vector<std::string>& argv, bool with_errors = false,
362369
const std::filesystem::path& cwd = {}) {
363370
namespace process = mcpplibs::os::process;
364371
if (argv.empty()) return {};
@@ -377,7 +384,7 @@ inline printed capture(const std::vector<std::string>& argv, bool with_errors =
377384

378385
// The first line a program prints, without its line end; empty when it prints
379386
// nothing or cannot be started.
380-
inline std::string first_line(const std::vector<std::string>& argv) {
387+
std::string first_line(const std::vector<std::string>& argv) {
381388
auto text = capture(argv).out;
382389
if (auto nl = text.find('\n'); nl != std::string::npos) text.resize(nl);
383390
while (!text.empty() && (text.back() == '\r' || text.back() == ' ')) text.pop_back();

0 commit comments

Comments
 (0)