diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2022-04-18 23:53:41 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-18 23:53:41 +0200 |
| commit | b03345f32a5ba2849ddbeeae0e31e0e77ca01b01 (patch) | |
| tree | 4100326d0b400a38525d980739214feaf48508b8 /src/introspect.zig | |
| parent | 5195b87639a1dc56b90751d0aecc4fcf4f2a1bb0 (diff) | |
| parent | 3a63fa6b7f56a2f384ebd460e80c00e6bbd2efee (diff) | |
| download | zig-b03345f32a5ba2849ddbeeae0e31e0e77ca01b01.tar.gz zig-b03345f32a5ba2849ddbeeae0e31e0e77ca01b01.zip | |
Merge pull request #11024 from topolarity/wasi-stage2
stage2: Add limited WASI support for selfExePath and globalCacheDir
Diffstat (limited to 'src/introspect.zig')
| -rw-r--r-- | src/introspect.zig | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/introspect.zig b/src/introspect.zig index 562d6b04f4..c0de4dc7f5 100644 --- a/src/introspect.zig +++ b/src/introspect.zig @@ -1,6 +1,7 @@ const std = @import("std"); const builtin = @import("builtin"); const mem = std.mem; +const os = std.os; const fs = std.fs; const Compilation = @import("Compilation.zig"); @@ -80,5 +81,15 @@ pub fn resolveGlobalCacheDir(allocator: mem.Allocator) ![]u8 { } } - return fs.getAppDataDir(allocator, appname); + if (builtin.os.tag == .wasi) { + // On WASI, we have no way to get an App data dir, so we try to use a fixed + // Preopen path "/cache" as a last resort + const path = "/cache"; + + const file = os.fstatat(os.wasi.AT.FDCWD, path, 0) catch return error.CacheDirUnavailable; + if (file.filetype != .DIRECTORY) return error.CacheDirUnavailable; + return allocator.dupe(u8, path); + } else { + return fs.getAppDataDir(allocator, appname); + } } |
