Commit Graph

161 Commits

Author SHA1 Message Date
Andrew Kelley d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00
Andrew Kelley a98fa56ae9 std: [breaking] move errno to become an nonexhaustive enum
The primary purpose of this change is to eliminate one usage of
`usingnamespace` in the standard library - specifically the usage for
errno values in `std.os.linux`.

This is accomplished by truncating the `E` prefix from error values, and
making errno a proper enum.

A similar strategy can be used to eliminate some other `usingnamespace`
sites in the std lib.
2021-08-24 01:23:28 -04:00
Takeshi Yoneda 97560cd915 Merge remote-tracking branch 'origin' into libc-wasi-test 2021-08-09 14:39:26 +09:00
Ryan Liptak d31352ee85 Update all usages of mem.split/mem.tokenize for generic version 2021-08-06 02:01:47 -07:00
Takeshi Yoneda 1e20a62126 WASI,libc: enable tests.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-07-27 09:01:00 +09:00
Martin Wickham e2b954c273 Add support for NO_COLOR 2021-07-08 14:30:45 -04:00
Jacob G-W 9fffffb07b fix code broken from previous commit 2021-06-21 17:03:03 -07:00
Martin Wickham fc9430f567 Breaking hash map changes for 0.8.0
- hash/eql functions moved into a Context object
- *Context functions pass an explicit context
- *Adapted functions pass specialized keys and contexts
- new getPtr() function returns a pointer to value
- remove functions renamed to fetchRemove
- new remove functions return bool
- removeAssertDiscard deleted, use assert(remove(...)) instead
- Keys and values are stored in separate arrays
- Entry is now {*K, *V}, the new KV is {K, V}
- BufSet/BufMap functions renamed to match other set/map types
- fixed iterating-while-modifying bug in src/link/C.zig
2021-06-03 17:02:16 -05:00
Al Hoang db8eae65de avoid usage of execv on Haiku 2021-05-24 10:39:01 -07:00
Veikka Tuominen fd77f2cfed std: update usage of std.testing 2021-05-08 15:15:30 +03:00
Al Hoang 6b0372229d initial support for haiku continue clean up
* remove unused definitions
* setup os specific blocks
2021-02-25 16:41:42 -07:00
Al Hoang 025635c3f8 initial support for haiku past stage0 2021-02-25 16:41:42 -07:00
LemonBoy dd973fb365 std: Use {s} instead of {} when printing strings 2021-01-02 17:12:57 -07:00
Frank Denis 6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
Andrew Kelley 78dcd1b23e std.process: update arg iterator tests
These tests asserted there were no args passed to the test binary, but
now there is an arg intentionally passed to the test binary, so the test
case needed to be updated.
2020-12-28 21:09:47 -07:00
Isaac Freund 8000262e07 std: clean up sentinel handling for argv/environ 2020-12-27 14:23:59 +01:00
Andrew Kelley 3f9588ca29 std: do not call malloc() between fork() and execv()
We were violating the POSIX standard which resulted in a deadlock on
musl v1.1.24 on aarch64 alpine linux, uncovered with the new ThreadPool
usage in the stage2 compiler.

std.os execv functions that accept an Allocator parameter are removed
because they are footguns. The POSIX standard does not allow calls to
malloc() between fork() and execv() and since it is common to both
(1) call execv() after fork() and (2) use std.heap.c_allocator,
Programmers are encouraged to go through the `std.process` API
instead, causing some dissonance when combined with `std.os` APIs.

I also slapped a big warning message on all the relevant doc comments.
2020-12-26 13:50:26 -07:00
Rageoholic 0369b65082 Switch to using unicode when parsing the command line on windows (#7241)
* Switch to using unicode when parsing the command line on windows

* Apply changes by LemonBoy and *hopefully* fix tests on MIPs

Co-authored-by: LemonBoy <LemonBoy@users.noreply.github.com>

* Fix up next and skip

* Move comment to more relevant place

Co-authored-by: LemonBoy <LemonBoy@users.noreply.github.com>
2020-11-30 13:47:01 -05:00
Josh Holland c25b157dda remove deprecated uses of ArrayList.span 2020-11-07 11:15:44 +00:00
chwayne 1e13e8e817 Make argsAlloc/ArgIterator return zero-sentinel strings (#6720) 2020-10-22 17:52:48 -04:00
Sebastien Marie 35a7247a2c Merge branch 'master' into openbsd-minimal 2020-10-17 17:38:23 +02:00
Vignesh Rajagopalan 2ab0c7391a Rename .macosx to .macos 2020-10-12 18:56:25 -04:00
Sébastien Marie f33a610c84 add minimal openbsd support 2020-10-11 08:23:36 +00:00
Isaac Freund 4170f3f77f std: fix bitrot in process.posixGetUserInfo() 2020-09-10 14:30:07 -04:00
Isaac Freund e8a2aecd2f std: fix linux uid_t, use uid_t/gid_t in std.os
- correct uid_t from i32 to u32 on linux
- define uid_t and gid_t for OSes missing definitions
- use uid_t/gid_t instead of plain u32s throughout std.os
2020-09-03 15:08:37 +02:00
Andrew Kelley 4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
joachimschmidt557 0ae1157e45 std.mem.dupe is deprecated, move all references in std
Replaced all occurences of std.mem.dupe in stdlib with
Allocator.dupe/std.mem.dupeZ -> Allocator.dupeZ
2020-07-04 21:40:06 +03:00
Carter Sande 7cb41a415a ArgIteratorWindows: simplify quote state tracking 2020-06-22 03:03:30 -07:00
Carter Sande 8faa85ac19 ArgIteratorWindows: don't treat unclosed quotes like they're escaped 2020-06-22 03:03:20 -07:00
Jonathan Marler a282ac7a91 Support Reader for InStream 2020-06-09 13:36:17 -04:00
Andrew Kelley 89a97a7a27 cleanups 2020-05-29 18:30:09 -04:00
Jonathan S 0674b51453 In getCwdAlloc, geometrically allocate larger buffers to find an appropriate size. 2020-05-29 18:27:39 -04:00
Jonathan S 631633b252 Document and reduce usage of MAX_PATH_BYTES, lifting arbitrary buffer size requirements 2020-05-29 18:23:06 -04:00
Jakub Konka 6e347e6180 Fix args iterator test 2020-05-29 17:12:19 +02:00
Jakub Konka 6f48842ddb Make ArgIterator.init() a compile error in WASI
Given that the previous design would require the use of a default
allocator to have `ArgIterator.init()` work in WASI, and since in
Zig we're trying to avoid default allocators, I've changed the design
slightly in that now `init()` is a compile error in WASI, and instead
in its message it points to `initWithAllocator(*mem.Allocator)`.
The latter by virtue of requiring an allocator as an argument can
safely be used in WASI as well as on other OSes (where the allocator
argument is simply unused). When using `initWithAllocator` it is then
natural to remember to call `deinit()` after being done with the
iterator. Also, to make use of this, I've also added `argsWithAllocator`
function which is equivalent to `args` minus the requirement of supplying
an allocator and being fallible.

Finally, I've also modified the WASI only test `process.ArgWasiIterator`
to test all OSes.
2020-05-29 10:48:03 +02:00
Jakub Konka f1a4e1a70f Add ArgIteratorWasi and integrate it with ArgIterator
This commit pulls WASI specific implementation of args extraction
from the runtime from `process.argsAlloc` and `process.argsFree`
into a new iterator struct `process.ArgIteratorWasi`. It also
integrates the struct with platform-independent `process.ArgIterator`.
2020-05-29 10:48:03 +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
xackus cd20e0cc67 rename mem.separate to mem.split 2020-04-04 17:37:51 -04: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
daurnimator 5c0d6ef5ec std: use ArrayList instead of Buffer from std/process.zig 2020-03-06 18:49:12 -05:00
Andrew Kelley fd006c1c74 std.zig.system.NativeTargetInfo.detect: almost no Allocator 2020-02-28 14:51:55 -05:00
Andrew Kelley 4616af0ca4 introduce operating system version ranges as part of the target
* re-introduce `std.build.Target` which is distinct from `std.Target`.
   `std.build.Target` wraps `std.Target` so that it can be annotated as
   "the native target" or an explicitly specified target.
 * `std.Target.Os` is moved to `std.Target.Os.Tag`. The former is now a
   struct which has the tag as well as version range information.
 * `std.elf` gains some more ELF header constants.
 * `std.Target.parse` gains the ability to parse operating system
   version ranges as well as glibc version.
 * Added `std.Target.isGnuLibC()`.
 * self-hosted dynamic linker detection and glibc version detection.
   This also adds the improved logic using `/usr/bin/env` rather than
   invoking the system C compiler to find the dynamic linker when zig
   is statically linked. Related: #2084
   Note: this `/usr/bin/env` code is work-in-progress.
 * `-target-glibc` CLI option is removed in favor of the new `-target`
   syntax. Example: `-target x86_64-linux-gnu.2.27`

closes #1907
2020-02-28 14:51:53 -05:00
Andrew Kelley 1d06c82c3b Merge pull request #4516 from xackus/remove-bytes-to-slice
remove @bytesToSlice, @sliceToBytes from the language
2020-02-24 13:51:47 -05:00
Andrew Kelley 94c3dbf9e3 remove no-longer-valid defer 2020-02-23 01:07:19 -05:00
Andrew Kelley 767f041068 std.process: fix typo 2020-02-22 17:49:52 -05:00
Andrew Kelley cfffb9c5e9 improve handling of environment variables on Windows
std.os.getenv and std.os.getenvZ have nice compile errors when not linking
libc and using Windows.

std.os.getenvW is provided as a Windows-only API that does not require
an allocator. It uses the Process Environment Block.
std.process.getEnvVarOwned is improved to be a simple wrapper on top of
std.os.getenvW.

std.process.getEnvMap is improved to use the Process Environment Block
rather than calling GetEnvironmentVariableW.

std.zig.system.NativePaths uses process.getEnvVarOwned instead of
std.os.getenvZ, which works on Windows as well as POSIX.
2020-02-22 17:35:36 -05:00
Andrew Kelley 936d0b18b1 update std lib to integrate with libc for environ
closes #3511
2020-02-22 15:59:13 -05:00
xackus 783e8ad031 remove @bytesToSlice, @sliceToBytes from std lib 2020-02-21 19:46:53 +01:00
Andrew Kelley 4b91e4c91f fix dynamic linker detection on windows (where there isn't one) 2020-02-17 16:03:01 -05:00
Andrew Kelley 2f9c5c0644 self-host dynamic linker detection 2020-02-17 15:23:59 -05:00