Commit b1d3d4f
fix: Gate POSIX filesystem calls on LinktimeInfo.isWindows in Scala Native impl (#629)
## Summary
- `FileSystemNative` in `uni-core` unconditionally references POSIX-only
symbols
(`readlink`, `symlink`, `stat`/`lstat`, `chmod`, `getpwuid`, `getgrgid`)
that
MSVC's CRT does not export. Downstream Scala Native + Windows consumers
(wvlet's `wvc-lib/wvlet.dll`) fail to link once they exercise this code
path.
See wvlet run
[25527054437](https://github.com/wvlet/wvlet/actions/runs/25527054437/job/74540961637):
`LNK2019: unresolved external symbol readlink / scalanative_stat /
_lstat / _getpwuid / _getgrgid`.
- Gate each POSIX path on
`scala.scalanative.meta.LinktimeInfo.isWindows` — a
link-time constant, so DCE removes the POSIX branch on Windows binaries
and
those symbols are never referenced.
- Same pattern as #519 (`localtime_r` fix), whose downstream Windows CI
confirmed the DCE works end-to-end.
## Windows behavior
| Operation | Non-Windows | Windows |
|---|---|---|
| `isSymlinkPath` | `unistd.readlink` probe | returns `false` (path
treated as regular file) |
| `doStatFileInfo` | `stat`/`lstat` + `getpwuid`/`getgrgid` | returns
`(None, None, None)` |
| `createSymlink` / `readSymlink` | `unistd.symlink`/`readlink` | throws
`UnsupportedOperationException` |
| `setPermissions` | `stat.chmod` | throws
`UnsupportedOperationException` |
| `permissions` / `owner` / `group` | POSIX values | throws
`IOException` (via existing `getOrElse`) |
`info(path)` still returns a useful `FileInfo` on Windows: `size`,
`lastModified`, `isReadable/Writable/Executable`, `isHidden` all come
from
`java.io.File` which is supported by Scala Native's javalib on Windows.
Symlink detection is skipped (a Windows symlink appears as a regular
file),
and `permissions`/`owner`/`group` are `None`.
## Test plan
- [x] `./sbt coreNative/Compile/compile` — clean
- [x] `./sbt uniJVM/testOnly wvlet.uni.io.*` — 140 tests passed
- [x] `./sbt uniNative/testOnly wvlet.uni.io.*` — 88 tests passed (POSIX
branch)
- [x] `./sbt scalafmtCheckAll` — clean
- [ ] End-to-end Windows verification: bump `UNI_VERSION` in wvlet after
this
lands and is published; re-run wvlet's `Build native on Windows
(x64/arm64)` job.
## Follow-up
wvlet's `native.yml` still needs a separate rename step for `libcurl.lib
→
curl.lib` (vcpkg's curl port names its import lib `libcurl.lib`, but
`@link("curl")` sends `curl.lib` to the linker). Tracked in a wvlet-side
PR.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent c7e5cd1 commit b1d3d4f
1 file changed
Lines changed: 82 additions & 50 deletions
Lines changed: 82 additions & 50 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
68 | 77 | | |
69 | 78 | | |
70 | 79 | | |
| |||
373 | 382 | | |
374 | 383 | | |
375 | 384 | | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
396 | 415 | | |
397 | 416 | | |
398 | 417 | | |
399 | 418 | | |
400 | 419 | | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
405 | 430 | | |
406 | 431 | | |
407 | 432 | | |
| |||
421 | 446 | | |
422 | 447 | | |
423 | 448 | | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
432 | 454 | | |
433 | 455 | | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
445 | 465 | | |
446 | | - | |
447 | | - | |
448 | | - | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
449 | 481 | | |
450 | 482 | | |
451 | 483 | | |
| |||
0 commit comments