Commit Graph

98 Commits

Author SHA1 Message Date
Andrew Kelley
d87cd06296 rework zig fmt to use less syscalls and open fds
* `std.fs.Dir.Entry.Kind` is moved to `std.fs.File.Kind`
 * `std.fs.File.Stat` gains the `kind` field, so performing a stat() on
   a File now tells what kind of file it is. On Windows this only will
   distinguish between directories and files.
 * rework zig fmt logic so that in the case of opening a file and
   discovering it to be a directory, it closes the file descriptor
   before re-opening it with O_DIRECTORY, using fewer simultaneous open
   file descriptors when walking a directory tree.
 * rework zig fmt logic so that it pays attention to the kind of
   directory entries, and when it sees a sub-directory it attempts to
   open it as a directory rather than a file, reducing the number of
   open() syscalls when walking a directory tree.
2020-06-20 18:27:37 -04:00
Andrew Kelley
f7bcc8e040 rework zig fmt to only make one allocation
taking advantage of the fstat size
2020-06-18 21:08:30 -04:00
Cassidy Dingenskirchen
8b49487c33 Fix fs.File.mode() not returning mode_t on windows 2020-06-18 20:41:40 -04:00
Jakub Konka
200f9ea6fb Add unit test for std.fs.wasi.PreopenList 2020-06-11 23:00:02 +02:00
Jakub Konka
c7721bb368 Add custom format method for Preopen struct 2020-06-11 22:31:08 +02:00
Jonathan Marler
a282ac7a91 Support Reader for InStream 2020-06-09 13:36:17 -04:00
Jonathan Marler
12051b02f1 fix memory errors 2020-06-09 00:17:22 -04:00
Jonathan Marler
7481582774 support Writer instead of OutStream
Start implementing https://github.com/ziglang/zig/issues/4917 which is to rename instream/outstream to reader/writer.  This first change allows code to use Writer/writer instead of OutStream/outStream, but still maintains the old outstream names with "Deprecated" comments.
2020-06-08 22:59:28 -04:00
Jonathan S
ab3931fa95 Prefer Files to paths in std.debug. Additionally [breaking] add a flags parameter to openSelfExe and stop exporting openElfDebugInfo.
This should save a call to readlink in openSelfDebugInfo and support executables in overlong paths on Linux.
2020-05-29 18:27:39 -04:00
Andrew Kelley
cda102be02 improvements to self-hosted cache hash system
* change miscellaneous things to more idiomatic zig style
 * change the digest length to 24 bytes instead of 48. This is
   still 70  more bits than UUIDs. For an analysis of probability of
   collisions, see:
   https://en.wikipedia.org/wiki/Universally_unique_identifier#Collisions
 * fix the API having the possibility of mismatched allocators
 * fix some error paths to behave properly
 * modify the guarantees about when file contents are loaded for input files
 * pwrite instead of seek + write
 * implement isProblematicTimestamp
 * fix tests with regards to a working isProblematicTimestamp function.
   this requires sleeping until the current timestamp becomes
   unproblematic.
 * introduce std.fs.File.INode, a cross platform type abstraction
   so that cache hash implementation does not need to reach into std.os.
2020-05-25 19:29:03 -04:00
Andrew Kelley
53d011fa1a (breaking) std.time fixups and API changes
Remove the constants that assume a base unit in favor of explicit
x_per_y constants.

nanosecond calendar timestamps now use i128 for the type. This affects
fs.File.Stat, std.time.nanoTimestamp, and fs.File.updateTimes.

calendar timestamps are now signed, because the value can be less than
the epoch (the user can set their computer time to whatever they wish).

implement std.os.clock_gettime for Windows when clock id is
CLOCK_CALENDAR.
2020-05-24 21:40:08 -04:00
Jakub Konka
cd8daa533a Undo accidentally checked-in changes to fs/test.zig 2020-05-18 22:22:27 +02:00
Jakub Konka
57719006bb Always return false for ANSI escape codes compat in WASI 2020-05-18 21:17:49 +02:00
Jakub Konka
3d267bab71 Re-enable refAllDecls gen and check in std.zig 2020-05-18 21:05:29 +02:00
Jakub Konka
5186711a96 Change to Self from *const Self/*Self where possible 2020-05-18 17:10:06 +02:00
Jakub Konka
fae4af9e1c Make mode_t a 0-byte type in WASI 2020-05-18 17:09:52 +02:00
Jakub Konka
d43c08a3e5 Add/fix missing WASI functionality to pass libstd tests
This rather large commit adds/fixes missing WASI functionality
in `libstd` needed to pass the `libstd` tests. As such, now by
default tests targeting `wasm32-wasi` target are enabled in
`test/tests.zig` module. However, they can be disabled by passing
the `-Dskip-wasi=true` flag when invoking the `zig build test`
command. When the flag is set to `false`, i.e., when WASI tests are
included, `wasmtime` with `--dir=.` is used as the default testing
command.

Since the majority of `libstd` tests were relying on `fs.cwd()`
call to get current working directory handle wrapped in `Dir`
struct, in order to make the tests WASI-friendly, `fs.cwd()`
call was replaced with `testing.getTestDir()` function which
resolved to either `fs.cwd()` for non-WASI targets, or tries to
fetch the preopen list from the WASI runtime and extract a
preopen for '.' path.

The summary of changes introduced by this commit:
* implement `Dir.makeDir` and `Dir.openDir` targeting WASI
* implement `Dir.deleteFile` and `Dir.deleteDir` targeting WASI
* fix `os.close` and map errors in `unlinkat`
* move WASI-specific `mkdirat` and `unlinkat` from `std.fs.wasi`
  to `std.os` module
* implement `lseek_{SET, CUR, END}` targeting WASI
* implement `futimens` targeting WASI
* implement `ftruncate` targeting WASI
* implement `readv`, `writev`, `pread{v}`, `pwrite{v}` targeting WASI
* make sure ANSI escape codes are _not_ used in stderr or stdout
  in WASI, as WASI always sanitizes stderr, and sanitizes stdout if
  fd is a TTY
* fix specifying WASI rights when opening/creating files/dirs
* tweak `AtomicFile` to be WASI-compatible
* implement `os.renameatWasi` for WASI-compliant `os.renameat` function
* implement sleep() targeting WASI
* fix `process.getEnvMap` targeting WASI
2020-05-18 16:09:49 +02:00
Andrew Kelley
16f100b82e
Merge pull request #5307 from ziglang/self-hosted-incremental-compilation
rework self-hosted compiler for incremental builds
2020-05-17 13:53:27 -04:00
Andrew Kelley
cf34480f2a
Merge pull request #5231 from kubkon/wasi-preopens
Add mechanism for extracting preopens from the runtime
2020-05-16 12:49:08 -04:00
Andrew Kelley
69a5f0d797 Merge remote-tracking branch 'origin/master' into self-hosted-incremental-compilation 2020-05-16 01:26:18 -04:00
Andrew Kelley
6a2425c38c self-hosted: fix the rest of the compile errors 2020-05-13 22:12:38 -04:00
Andrew Kelley
619159cf48 self-hosted: rework the memory layout of ir.Module and related types
* add TypedValue.Managed which represents a Type, a Value, and some
   kind of memory management strategy.
 * introduce an analysis queue
 * flesh out how incremental compilation works with respect to exports
 * ir.text.Module is only capable of one error message during parsing
 * link.zig no longer has a decl table map and instead has structs that
   exist directly on ir.Module.Decl and ir.Module.Export
 * implement primitive .text block allocation
 * implement linker code for updating Decls and Exports
 * implement null Type

Some supporting std lib changes:
 * add std.ArrayList.appendSliceAssumeCapacity
 * add std.fs.File.copyRange and copyRangeAll
 * fix std.HashMap having modification safety on in ReleaseSmall builds
 * add std.HashMap.putAssumeCapacityNoClobber
2020-05-12 01:02:48 -04:00
Jakub Konka
81d824bf80 Clear PreopenList on every populate call 2020-05-05 17:23:49 +02:00
Jakub Konka
07a968b344 Add docs 2020-05-05 17:05:30 +02:00
Jakub Konka
558bb24601 Move preopen and path wasi helpers to std.fs.wasi module
Previously, the path and preopens helpers were prototyped in `std.os.wasi`
module, but since they are higher-level abstraction over wasi, they belong in
`std.fs.wasi` module.
2020-05-05 15:08:52 +02:00
Tadeo Kondrak
fdfdac4939
update comments for nosuspend 2020-05-05 05:55:27 -06:00
Andrew Kelley
7998e2b0f4 Merge remote-tracking branch 'origin/master' into FireFox317-windows-evented-io 2020-05-02 14:16:59 -04:00
Andrew Kelley
5656f5090d fs.File: improve handling async I/O on Windows
Before it was possible for .intended_io_mode = .blocking,
.capable_io_mode = .evented, and then the implementation would put a
request on the fs thread, which is the wrong behavior. Now it always
calls the appropriate WriteFile/ReadFile function, passing the intended
io mode directly as a parameter.

This makes the behavior tests pass on Windows with --test-evented-io.
2020-05-02 14:09:17 -04:00
nycex
77376a54bf
correct usages of std.fs.dir.DeleteFileError (#5058)
* correct usages of std.fs.dir.DeleteFileError

* test std.fs.createFileAbsolute() and std.fs.deleteFileAbsolute()
2020-05-02 04:19:07 -04:00
Andrew Kelley
45bce27b8f cleanup and fixes. behavior tests passing with evented I/O 2020-05-01 23:17:28 -04:00
Andrew Kelley
988031c07c Merge branch 'windows-evented-io' of https://github.com/FireFox317/zig into FireFox317-windows-evented-io 2020-05-01 19:02:16 -04:00
Andrew Kelley
2bae942800 add ZIR compare output test case to test suite 2020-05-01 06:47:20 -04:00
Andrew Kelley
a3dfe36ca1 zir-to-elf skeleton 2020-04-22 23:42:58 -04:00
xackus
dbc00e2424 ArrayList: remove old (before span) API 2020-04-11 20:40:34 -04:00
Andrew Kelley
4ceaa0595a move fs tests to separate file; disable flaky test
See #5006
2020-04-11 17:50:38 -04:00
LeRoyce Pearson
317f06dc77 Add lock_nonblocking flag for creating or opening files
Also, make windows share delete access. Rationale: this is how it works
on Unix systems, mostly because locks are (usually) advisory on Unix.
2020-04-07 18:00:12 -06:00
LeRoyce Pearson
71c5aab3e7 Make lock option an enum
For some reason, this breaks file locking on windows. Not sure if this is
a problem with wine.
2020-04-07 16:49:30 -06:00
LeRoyce Pearson
ea6525797d Use flock instead of fcntl to lock files
`flock` locks based on the file handle, instead of the process id.
This brings the file locking on unix based systems closer to file
locking on Windows.
2020-04-02 22:57:02 -06:00
LeRoyce Pearson
35c462caf0 Merge branch 'master' into feature-file-locks 2020-04-02 21:46:48 -06:00
Andrew Kelley
9e7ae06249
std lib API deprecations for the upcoming 0.6.0 release
See #3811
2020-03-30 14:23:22 -04:00
Timon Kruiper
67e51311c3 fix behavior test with --test-evented-io on windows
also make simple file operations work asynchronously on windows
2020-03-27 17:03:06 +01:00
LeRoyce Pearson
113b217593 Merge branch 'master' into feature-file-locks 2020-03-23 21:39:16 -06:00
Andrew Kelley
46ffc798b6
fix swapped logic for Windows
Remove `std.fs.deleteTree`. Callers instead should use
`std.fs.cwd().deleteTree`.

Add `std.fs.deleteTreeAbsolute` for when the caller has an absolute
path.
2020-03-18 16:42:47 -04:00
LeRoyce Pearson
b773a8b175 Make fcntlFlock follow conventions of os.zig 2020-03-17 20:53:43 -06:00
LeRoyce Pearson
43ccc2d81e Add note about mandatory locks on linux 2020-03-14 10:12:46 -06:00
LeRoyce Pearson
a636b59cb5 Add lock option to CreateFlags 2020-03-14 10:12:46 -06:00
LeRoyce Pearson
3110060351 Add lock to fs.File.OpenFlags 2020-03-14 10:12:46 -06:00
LemonBoy
de53537f10 Add NtDll-based ftruncate implementation 2020-03-13 08:45:37 +01:00
LemonBoy
bd0b51477a Address review comments 2020-03-12 19:40:42 +01:00
LemonBoy
11df0d0cf8 std: Add setEndPos to fs.file
Allow the user to shrink/grow the file size as needed.
2020-03-12 09:43:45 +01:00