-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
I'm new to zig so this may be doing something stupid, but it appears that zig fmt has an issue when running within WSL.
System Config:
Windows 10 Version 10.0.17134 Build 17134
Running Ubuntu 18.04.1 via WSL
with a basic hello-world file:
V 0.4.0
carter@Carter-Desktop:~/zig-test/src$ zig fmt hello.zig
hello.zig
error: Unexpected
/home/carter/zig-linux-x86_64-0.4.0/lib/zig/std/os.zig:2248:5: 0x24a541 in ??? (fmt)
return error.Unexpected;
^
/home/carter/zig-linux-x86_64-0.4.0/lib/zig/std/os.zig:1221:21: 0x29323d in ??? (fmt)
else => return unexpectedErrorPosix(err),
^
/home/carter/zig-linux-x86_64-0.4.0/lib/zig/std/os.zig:1183:13: 0x2931bb in ??? (fmt)
return renameC(&self.tmp_path_buf, &dest_path_c);
^
/home/carter/zig-linux-x86_64-0.4.0/lib/zig/std/io.zig:1012:9: 0x279f2d in ??? (fmt)
try self.atomic_file.finish();
^
/home/carter/zig-linux-x86_64-0.4.0/lib/zig/std/special/fmt_runner.zig:199:13: 0x257429 in ???
(fmt)
try baf.finish();
^
/home/carter/zig-linux-x86_64-0.4.0/lib/zig/std/special/fmt_runner.zig:112:9: 0x253df5 in ??? (fmt)
try fmtPath(&fmt, file_path, check_mode); V latest
carter@Carter-Desktop:~/zig-test/src$ zig fmt ./hello.zig
./hello.zig
error: Unexpected
/home/carter/zig-linux-x86_64-0.4.0/lib/zig/std/os.zig:2248:5: 0x24a541 in ??? (fmt)
return error.Unexpected;
^
/home/carter/zig-linux-x86_64-0.4.0/lib/zig/std/os.zig:1221:21: 0x29323d in ??? (fmt)
else => return unexpectedErrorPosix(err),
^
/home/carter/zig-linux-x86_64-0.4.0/lib/zig/std/os.zig:1183:13: 0x2931bb in ??? (fmt)
return renameC(&self.tmp_path_buf, &dest_path_c);
^
/home/carter/zig-linux-x86_64-0.4.0/lib/zig/std/io.zig:1012:9: 0x279f2d in ??? (fmt)
try self.atomic_file.finish();
^
/home/carter/zig-linux-x86_64-0.4.0/lib/zig/std/special/fmt_runner.zig:199:13: 0x257429 in ???
(fmt)
try baf.finish();
^
/home/carter/zig-linux-x86_64-0.4.0/lib/zig/std/special/fmt_runner.zig:112:9: 0x253df5 in ?? (fmt)
try fmtPath(&fmt, file_path, check_mode);
^ Zig fmt is producing a cache file which appears to contain the desired contents alongside the file:
carter@Carter-Desktop:~/zig-test/src$ ls
K-IIxPOeJ_t0r6Rp hello.zig
carter@Carter-Desktop:~/zig-test/src$ cat K-IIxPOeJ_t0r6Rp
const std = @import("std");
/// I'm writing a doc comment in zig
//I'm writing a regular comment in zig
pub fn main() void {
std.debug.warn("Hello, world!\n");
} I've done some initial debugging by adding the following snippet in os.zig:
1219 posix.ENOTEMPTY => return error.PathAlreadyExists,
1220 posix.EROFS => return error.ReadOnlyFileSystem,
1221 posix.EXDEV => return error.RenameAcrossMountPoints,
1222 else => {
1223 std.debug.warn("Err: val {}", err);
1224 return unexpectedErrorPosix(err);
1225 },
1226 }
1227 }
which tells me that the error number is 38.
Which is apparently:
#define ENOSYS 38 /* Function not implemented */
After some digging it appears that os/linux.zig is using renameat(2) which is not implemented on WSL. According to this other issue yuk7/ArchWSL#5
I do not know enough about the POSIX standards to tell if Zig is using a syscall which should not be expected to be universal across all Linux instances, or if WSL is out of spec (I suspect that latter).
I'm new to Zig, but it seems reasonable that following changes could be made:
- ENOSYS should be added to the renameC switch statement so that the error message is clearer about the source, and nobody has to add a print statement to see the posix errno.
- It is strange to me that this crash left fragment files in my workspace. I would expect Zig to cleanup the fragment file if an error were encountered here
- It appears that using a more basic rename syscall may be supported on WSL? May be a performance degradation, but would improve compatibility. Is there a way would could check if the syscall is available and gracefully fallback?