Commit 0b82803
authored
refactor: platform abstraction layer + fix macOS stdin hang (#55)
* feat: add msvc.cppm — robust Visual Studio / MSVC STL discovery
New module mcpp.toolchain.msvc with three discovery strategies:
1. vswhere.exe (Microsoft's official VS locator) — most reliable
2. Environment variables (VSINSTALLDIR, VS*COMNTOOLS)
3. Well-known paths (VS 2017-2025, all editions + BuildTools)
Replaces the hardcoded VS2022 path in clang.cppm with
msvc::find_std_module_source(). Fixes "no std module source"
error on machines with non-standard VS installations.
Also provides find_cl() for future MSVC toolchain support.
* refactor: extract platform abstraction layer into src/platform/
Create a unified platform abstraction layer that consolidates all
platform-specific code into dedicated modules under src/platform/:
- common.cppm: compile-time constants, platform detection, naming
- process.cppm: unified subprocess execution (auto-closes stdin on
POSIX — fixes macOS first-run hang where xcrun/xcode-
select would block waiting for user input)
- fs.cppm: self_exe_path(), which(), RAII FileLock
- shell.cppm: platform-aware shell argument quoting
- env.cppm: environment variable operations
- macos.cppm: Xcode CLT detection, xcrun SDK discovery
- linux.cppm: LD_LIBRARY_PATH construction, runtime lib dirs
- windows.cppm: PATH manipulation
- platform.cppm: facade that re-exports all sub-modules
Migrated consumers:
- config.cppm: use platform::fs::self_exe_path(), which()
- xlings.cppm: use platform::shell, process, env (all raw
popen/system calls removed)
- probe.cppm: use platform::fs::which(), macos::sdk_path(),
linux_::build_ld_library_path_prefix()
- bmi_cache.cppm: use platform::fs::FileLock (RAII)
- ninja_backend.cppm: use platform::fs::self_exe_path()
- clang.cppm: use platform::exe_suffix for tool paths
- cli.cppm: use platform::name constant
Deleted:
- src/platform.cppm: replaced by src/platform/common.cppm
- src/process.cppm: absorbed by src/platform/process.cppm + shell.cppm
Net result: ~550 lines of scattered #ifdef blocks removed, all
subprocess calls now go through platform::process which auto-redirects
stdin from /dev/null on POSIX.
* fix: add missing #include <cstdio> in xlings.cppm for stderr
The previous commit removed <cstdio> during cleanup but stderr is still
used in ensure_init(), ensure_patchelf(), and ensure_ninja() warning
messages.
* refactor: eliminate remaining platform macros (P0-P6)
P0: Remove all #define popen/_popen macros from 6 files — migrate
every raw popen/pclose/std::system call to platform::process APIs.
Files: cli, ninja_backend, msvc, stdmod, pack, publisher, p1689.
Add run_passthrough() and extract_exit_code() to platform::process.
P1: Replace all manual shell quoting #ifdefs in cli.cppm with
platform::shell::quote(). Covers git clone, ninja -C, cmd_run,
cmd_test (5 locations).
P2: Create platform/terminal.cppm — absorbs is_tty() and
terminal_cols() from ui.cppm. Eliminates #ifdef __unix__ blocks.
P3: Move kXpkgPlatform constant to platform::common::xpkg_platform.
resolver.cppm now uses it without #if defined blocks.
P4: Add link strategy constants (supports_full_static, supports_rpath,
needs_explicit_libcxx) to platform::common. flags.cppm now uses
if constexpr instead of #if defined blocks.
P5: Replace #if defined(_WIN32) in xlings.cppm build_command_prefix,
install_with_progress, ensure_init with if constexpr.
P6: Eliminate all #if defined blocks in ninja_backend.cppm rule
generation. Introduce constexpr $toolenv prefix variable, use
if constexpr for platform-specific rules (cp_bmi, scan_deps).
Net: ~440 lines of #ifdef removed, 315 lines of clean constexpr/
platform API code added. Zero raw popen calls remain outside
src/platform/.
* ci: trigger workflow1 parent b362894 commit 0b82803
28 files changed
Lines changed: 1370 additions & 916 deletions
File tree
- .agents/docs
- src
- build
- modgraph
- pack
- platform
- pm
- toolchain
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | 18 | | |
27 | 19 | | |
28 | 20 | | |
29 | 21 | | |
| 22 | + | |
30 | 23 | | |
31 | 24 | | |
32 | 25 | | |
| |||
188 | 181 | | |
189 | 182 | | |
190 | 183 | | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | 184 | | |
242 | 185 | | |
243 | 186 | | |
| |||
246 | 189 | | |
247 | 190 | | |
248 | 191 | | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
| 192 | + | |
| 193 | + | |
261 | 194 | | |
262 | 195 | | |
263 | 196 | | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | 197 | | |
270 | 198 | | |
271 | 199 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
| 163 | + | |
| 164 | + | |
174 | 165 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
180 | 179 | | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | 180 | | |
203 | 181 | | |
204 | 182 | | |
| |||
0 commit comments