Commit Graph

9500 Commits

Author SHA1 Message Date
Jacob Young
5e791e8e07 tls: support ed25519 signatures
Which were claimed to be supported during the handshake but were not
actually implemented.
2024-02-02 17:27:26 -08:00
Jakub Konka
92deebcd66 cli+build: handle -ObjC flag and route it to MachO linker 2024-02-02 22:00:16 +01:00
Andrew Kelley
5a3ae38f3b std: remove garbage being printed to stderr during unit tests 2024-02-01 18:05:14 -07:00
mlugg
8944935499 std: eliminate some uses of usingnamespace
This eliminates some simple usages of `usingnamespace` in the standard
library. This construct may in future be removed from the language, and
is generally an inappropriate way to formulate code. It is also
problematic for incremental compilation, which may not initially support
projects using it.

I wasn't entirely sure what the appropriate namespacing for the types in
`std.os.uefi.tables` would be, so I ofted to preserve the current
namespacing, meaning this is not a breaking change. It's possible some
of the moved types should instead be namespaced under `BootServices`
etc, but this can be a future enhancement.
2024-02-01 20:30:42 +00:00
Veikka Tuominen
a4f27e8987 remove std.io.Mode 2024-02-01 15:22:36 +02:00
Veikka Tuominen
b0bea72588 remove std.event 2024-02-01 15:22:36 +02:00
Veikka Tuominen
8d11ade6a7 std: change return type of wasiCwd
`fd_t` is not declared on freestanding so returning a `Dir` causes an error.
2024-02-01 15:22:36 +02:00
Veikka Tuominen
07dbff4f44 std.start: remove event loop integration 2024-02-01 15:22:36 +02:00
Veikka Tuominen
220d3264c9 std: make options a struct instance instead of a namespace 2024-02-01 15:22:36 +02:00
Jacob Young
c1e7d0c08f http: optimize allocations for proxy basic authorization 2024-01-31 15:00:27 +01:00
Jacob Young
a111f805cd http: avoid allocator use when encoding basic authorization 2024-01-31 15:00:27 +01:00
Jacob Young
82b37ea024 http: support basic access authentication 2024-01-31 12:05:12 +01:00
Gustavo C. Viegas
fc48bbdf90 std.Build.Step.TranslateC: fix use of outdated Module in createModule 2024-01-31 02:46:05 +02:00
Constantin Pestka
e460ba66a5
std: add docs about return value of submit() (#18721)
being misleading if used alongside with IORING_SETUP_SQPOLL
2024-01-29 21:26:52 -05:00
Krzysztof Wolicki
d8981dc493
std.os: fix chdirZ to compile on Windows (#18695) 2024-01-29 21:19:07 -05:00
Ian Johnson
cc25756b3f Eliminate generic duplication in allocPrint
Since `bufPrint` and `count` both control the writers used internally,
they can leverage type-erased writers while maintaining correct error
handling. This reduces generic instantiations when using `allocPrint`,
which calls both `count` and `bufPrint` internally.
2024-01-29 19:02:18 -05:00
Ian Johnson
e392c1a0b3 Add type-erased writer and GenericWriter
This is a companion to #17344 to apply the same change to the
`std.io.Writer` interface.
2024-01-29 19:02:18 -05:00
Jacob Young
4dfca01de4 gzip: implement compression 2024-01-29 14:30:23 -08:00
Ian Johnson
27d2d8e81f Apply cflags from pkg-config to all dependent modules
Closes #18628

This commit splits the arguments obtained from pkg-config into two
groups, cflags and libs, and consistently applies the cflags to each
individual module linking the library while applying the libs only once
for each compilation.
2024-01-29 14:08:41 -08:00
Christian Flicker
9c7fa358c1
std.Thread: fix off-by-one in PosixThreadImpl (#18711)
by removing ZST special case
2024-01-29 11:07:21 -05:00
Veikka Tuominen
c085c6ecdd std: remove meta.globalOption 2024-01-27 13:56:32 -08:00
Krzysztof Wolicki
190ea02e0d os.windows: Fix missing correction from #18657 2024-01-27 12:38:33 -08:00
Andrew Kelley
608d5e6fb7
Merge pull request #18676 from MrDmitry/feat/improve_cmake_replace_values
std.Build.Step.ConfigHeader (cmake): rewrite variable expansion
2024-01-27 12:38:02 -08:00
Pavel Verigo
87733171b6 parser: fix "else" followed by "comptime" 2024-01-27 16:20:47 +02:00
MrDmitry
c84e086a2f Get rid of direct dependency on std.fmt
Replace unnecessary panic with step error
2024-01-26 15:59:05 -05:00
MrDmitry
9ecbf53388 Minor formatting, removed duplicate test case 2024-01-26 13:33:17 -05:00
MrDmitry
3e6f07e617 Add escaped character processing 2024-01-26 13:33:17 -05:00
MrDmitry
834f8d45ba Rewrite replace_variables with CMake-specific version
Behavior matches CMake's CMP0053 policy that is the current standard for
variable expansion for `configure_file()`
2024-01-26 13:33:17 -05:00
Tobias Simetsreiter
20abf1394a align naming and fix module creation from TranslateC 2024-01-26 15:25:52 +02:00
Zachary Raineri
b36dd55af5 std.os.wasi | Fix comment links
Branch was renamed: master -> main
Preview 1 was moved to legacy
2024-01-26 15:24:07 +02:00
Jakub Konka
5226705b32 std.macho: add segment flags 2024-01-24 12:48:12 +01:00
Andrew Kelley
92211135f1
Merge pull request #17155 from winterqt/ignore-nix-ldflags-linkage-directives
std.zig.system.NativePaths: ignore linkage directives in `NIX_LDFLAGS`
2024-01-24 00:01:23 -08:00
Krzysztof Wolicki
eff58d6c18 os.windows: Fix error 258 name in Win32Error 2024-01-23 18:06:23 -08:00
Andrew Kelley
f37513aa68 NativePaths: support -L and -l arguments in NIX_LDFLAGS
A slightly more robust parsing of these flags in case of a separate
argument appearing after "-L" in the flags.
2024-01-23 18:01:59 -07:00
Winter
6f3ee587ba std.zig.system.NativePaths: ignore linkage directives in NIX_LDFLAGS
`NIX_LDFLAGS` typically contains just `-rpath` and `-L`, which we already
handle. However, at least one setup hook in Nixpkgs [0] adds a linkage
directive to it. To prevent library paths from being missed (as I've
observed myself with `NIX_LDFLAGS` being `-liconv ...`, making it so that
*all* paths are missed), let's just skip over them.

[0]: 08f615eb1b/pkgs/development/libraries/libiconv/setup-hook.sh
2024-01-23 17:49:25 -07:00
Khang Nguyen Duy
993a83081a std.fmt: fix unecessary deref on user-defined format function
When formatting a pointer to user type, currently it needs to be
dereferenced first, then call `formatType` on the child type.

Fix the problem by checking for "format" function on not only the type
itself, but also the struct it points to. Add hasMethod to std.meta.
2024-01-23 01:03:45 -08:00
Tristan Ross
c0e0bb385c std.process: return u64 in totalSystemMemory 2024-01-23 00:17:53 -08:00
Littleote
3331c5e7af Free threads in std.Thread.Pool.init only with pool.join
Free the allocated threads in the initialization of a thread pool only with pool.join instead of additionally calling allocator.free causing free to be called twice.

Resolves #18643
2024-01-22 11:24:35 -08:00
Tristan Ross
d0da3d731e std.io: replace readStructBig with readStructEndian 2024-01-22 10:53:27 -08:00
Andrew Kelley
ce7c66e2d0 langref: make more consistent
* moves some langref into std.builtin doc comments
* use the same way of referencing stuff from std.builtin

closes #16483
2024-01-21 20:39:50 -07:00
Andrew Kelley
2d9c4792ae std.fmt: clarify the use of "character"
Currently, std.fmt has a misguided, half-assed Unicode implementation
with an ambiguous definition of the word "character". This commit does
almost nothing to mitigate the problem, but it lets me close an open PR.

In the future I will revert 473cb1fd74 as
well as 279607cae5, and redo the whole
std.fmt API, breaking everyone's code and unfortunately causing nearly
every Zig user to have a bad day. std.fmt will go back to only dealing
in bytes, with zero Unicode awareness whatsoever. I suggest a third
party package provide Unicode functionality as well as a more advanced
text formatting function for when Unicode awareness is needed. I have
always suggested this, and I sincerely apologize for merging pull
requests that compromised my stance on this matter.

Most applications should, instead, strive to make their code independent
of Unicode, dealing strictly in encoded UTF-8 bytes, and never attempt
operations such as: substring manipulation, capitalization, alignment,
word replacement, or column number calculations.

Exceptions to this include web browsers, GUI toolkits, and terminals. If
you're not making one of these, any dependency on Unicode is probably a
bug or worse, a poor design decision.

closes #18536
2024-01-21 20:31:13 -07:00
Andrew Kelley
ac29303321
Merge pull request #18634 from MrDmitry/bug/ConfigHeader_cmake_neighbors
std.Build.Step.ConfigHeader (cmake): fix offset calculation for multiple substitutions on a single line
2024-01-21 12:45:21 -08:00
Christiano Haesbaert
bf7ebfa67a Handle all errors on std.net.Ipv4address.resolveIP
The following test fails since NonCanonical is not handled

test "foo" {
    std.net.Ip4Address.resolveIp("1.1.1.1", 0) catch unreachable;
}

/usr/lib/zig/std/net.zig:240:60: error: switch must handle all possibilities
        if (parse(name, port)) |ip4| return ip4 else |err| switch (err) {
                                                           ^~~~~~
/usr/lib/zig/std/net.zig:240:60: note: unhandled error value: 'error.NonCanonical'
referenced by:
    test.foo: src/dhcp.zig:383:23
2024-01-21 11:20:03 +02:00
MrDmitry
2dfec13ef0 Fix last_index after variable substitution
Iterative passes should start at the end of the previous substitution
2024-01-21 03:16:09 -05:00
Andrew Kelley
10aff67502
Merge pull request #18596 from ypsvlq/mingw
mingw-w64: add missing CRT sources
2024-01-20 12:01:33 -08:00
Andrew Kelley
5c4cb60f4f
Merge pull request #18622 from ziglang/zig-mod-edge-case
build system: better handle modules that do not have a zig root source file
2024-01-20 03:22:02 -08:00
expikr
b729a3f008
std.math: make hypot infer type from argument (#17910)
using peer type resolution
2024-01-20 01:32:07 -05:00
hdert
314533c28b std/math/pow: Fix #18553, isOddInteger: Return false if float value is greater than 1 << 53 (see comment), add test cases 2024-01-19 22:00:04 -08:00
Andrew Kelley
2dea375450 std.Build.Compile: handle modules sans root source files
Uses the new `-M[name][=src]` CLI syntax to omit the source when the
module does not have a zig root source file.

Only some kinds of link objects imply that this should happen.
2024-01-19 22:28:07 -07:00
Andrew Kelley
480a2f7f02
Merge pull request #18293 from g-cassie/array-list-replace-range-assume
Add replaceRangeAssumeCapacity method to ArrayList
2024-01-19 21:10:09 -08:00
Elaine Gibson
398ab5fcfb mingw: update build logic 2024-01-20 00:24:39 +00:00
Elaine Gibson
b126978555 mingw-w64: remove msvcrt sources 2024-01-20 00:21:34 +00:00
Elaine Gibson
bbecbaab0a mingw-w64: add missing CRT sources 2024-01-20 00:21:34 +00:00
Meghan Denny
46d592e485 do not enforce function parameters to be marked comptime if only called at comptime 2024-01-19 15:31:18 -08:00
Andrew Kelley
827e30634f std.ArrayList: pedantic fixups to previous commit
* fix and clarify incorrect doc comments
* unify the pattern of calling unmanaged methods
2024-01-19 16:24:51 -07:00
Gordon Cassie
4ddd0b1a1b std.ArrayList: add replaceRangeAssumeCapacity method 2024-01-19 16:24:51 -07:00
Andrew Kelley
d7b6d637df
Merge pull request #18615 from ziglang/langref
miscellaneous documentation changes
2024-01-19 12:14:30 -08:00
Andrew Kelley
3c16e80372
Merge pull request #18611 from erikarvstedt/array-list-overflow
ArrayList: remove unneeded overflow checks
2024-01-19 12:10:00 -08:00
Andrew Kelley
ab82132749 zig build: add doc comments for functions related to options
closes #18204
2024-01-18 22:01:09 -07:00
Erik Arvstedt
c50ba2d101 std.ArrayList.replaceRange: remove unneded overflow checks
The code asserted that the range to be replaced is within bounds of
`self.items`.
This is now reflected in the doc comment.
The old, wrong doc comment was copied from the `insert*` fns.

With this assertion holding true, `start + len` is always within the
address space and `start + new_items.len` is, at this point, always
strictly within bounds of `self.items`.
2024-01-19 00:55:17 +01:00
Erik Arvstedt
0bb6967d14 std.ArrayList: remove + 1 overflow checks 2024-01-19 00:55:17 +01:00
Sebastien Marie
7d81c952d5 openbsd: add proper support for aarch64
define openbsd specific elements in std/dwarf/abi.zig regBytes()

work from Jasper Lievisse Adriaanse, with register values from sys/signal.h
and https://github.com/ARM-software/abi-aa/blob/main/aadwarf64/aadwarf64.rst#dwarf-register-names
2024-01-18 15:45:42 -08:00
Nameless
a7dbc57a35 std.http.Client: read response messages with no length until eof 2024-01-18 15:43:58 -08:00
Andrew Kelley
22b9d8987d
Merge pull request #17499 from rootbeer/makepath-dangling-symlink
std.fs: tests for makePath and symlinks
2024-01-18 15:37:16 -08:00
Krzysztof Wolicki
14efbbfd89
std.Uri: change specifier for printing with scheme to semicolon ;
Fetch: print scheme when suggesting adding a ref to git URIs
2024-01-18 09:13:04 +02:00
Loris Cro
4ace1f5a7f Build: add namedWriteFiles to Build 2024-01-16 16:09:58 -08:00
Jay Petacat
fd43baa9ad byos: Ease GeneralPurposeAllocator integration
These changes enable me to use `GeneralPurposeAllocator` with my "Bring
Your Own OS" package. The previous checks for a freestanding target have
been expanded to `@hasDecl` checks.

- `root.os.heap.page_allocator` is used if it exists.
- `debug.isValidMemory` only calls `os.msync` if it's supported.
2024-01-16 15:05:38 -08:00
Andrew Kelley
a338c279f8
Merge pull request #15565 from xEgoist/spawnWindows
child_process: Add write and inheritable access to the null handle
2024-01-16 15:03:25 -08:00
melonedo
9b0da5ccef Fix TLS record overflow by limiting inner record length to 2^14
Per last paragraph of RFC 8446, Section 5.2, the length of the inner content of an encrypted record must not exceed 2^14 + 1, while that of the whole encrypted record must not exceed 2^14 + 256.
2024-01-16 14:58:56 -08:00
Pat Tullmann
ff5613873f std/fs/test.zig: Add statFile() tests of dangling symlink
Create a dangling symlink and check that statFile works with it.
2024-01-16 14:19:48 -08:00
Pat Tullmann
d35bdc8ee7 std/fs/test.zig: Try harder to clean up locking files 2024-01-16 14:19:48 -08:00
Pat Tullmann
c36962bb19 std/fs/test.zig: Factor out the symlink-creation wrappers
Because creation of a symlink can fail on Windows with an Access Denied
error (https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/create-symbolic-links)
any tests that need a symbolic link "skip" if they run into this problem.

This change factors out a "setupSymbolicLink()" routine to make this
clearer, a bit tighter, and easier to use in future tests.

I also collapsed the "symlink in parent directory" test into the existing
"Dir.readlink" test, because the latter uses the more comprehensive
testWithAllSupportedPathTypes wrapper.
2024-01-16 14:19:48 -08:00
Pat Tullmann
95a0e127b3 std/fs/test.zig: quote . and .. in test names
The test runner uses "." in its output between the test module and the
test name, so quote the leading '.' in these test names to make them
easier to read.
2024-01-16 13:49:00 -08:00
Purrie
c4a1b54ebe tls client interface consistency fix
Client for tls was using a function that wasn't declared on the
interface for it. The issue wasn't apparent because net stream
implemented that function.

I changed it to keep the interface promise of what's required to be
compatible with the tls client functionality.
2024-01-16 13:02:00 -08:00
Andrew Kelley
195eeed2d8 std: remove deprecated API 2024-01-16 04:20:05 -08:00
xEgoist
194ed30825 child_process: Use security attributes while creating handle.
As suggested by @matu3ba, it can be better to use Security Attributes
directly while creating the handle instead of creating the handle then
setting the handle to inherit. Doing so can prevent potentially leaking
to other parallel spawned processes which would inherit the opened `\Device\Null`
handle.

This change also allows windows.OpenFile to handle when bInheritHandle
is set.

Note that we are using the same `saAttr`, but since it's taken as a
pointer to a const in all calls, it's never mutated, and OpenFile never alters it.

This also saves 1 kernel call for setting the handle to inherit.
2024-01-16 01:25:14 -08:00
xEgoist
41bf816fa6 child_process: Add write access to the null handle
This commit allows write access to the `\\Device\\Null` Handle.
Without a write access, it's not possible for the child process to write
SdOut to Null. As a requirement `SetHandleInformation` was also changed
to mark the handle as iheritable (by adding it to Flags) by the spawned process.
This allows the child to access the NUL device that was opened.

This also makes the Windows part to behave similarly to `spawnPosix`.
2024-01-16 01:25:14 -08:00
Krzysztof Wolicki
7116b02210 Allow multiple options using the same enum type 2024-01-15 23:08:11 -08:00
Andrew Kelley
88ee323cd7
Merge pull request #18570 from gh-fork-dump/linux-6.7
Linux: Update syscall bits for 6.7
2024-01-15 23:04:02 -08:00
Andrew Kelley
d1ce8b8837
Merge pull request #18168 from cipharius/feature/zig-build-fossil-support
Adds support for Fossil SCM source tree archives as zig build dependencies
2024-01-15 23:02:50 -08:00
Andrew Kelley
f2721a4cbc std.ArrayList: pedantic rewordings of documentation and unit tests 2024-01-15 23:44:36 -07:00
notcancername
69461bcae4 std.array_list: Document and reduce illegal behavior in ArrayLists 2024-01-15 23:44:36 -07:00
cipharius
f25c499d12 Permits tar directory path without trailing slash 2024-01-15 18:31:32 +02:00
Stephen Gregoratto
3200fae9c5 Linux: Add syscall bindings, enhance documentation.
- Add syscall bindings/structures for the `futex2` family.
  The documentation is taken from the syscall definitions.
- Add documnentation for the `cachestat` bindings and structures.
  Taken from work I did in Cosmopolitian libc.
- Add binding for `map_shadow_stack`.
  No documentation for this one, since the kernel devs didn't bother to
  do it ¯\_(ツ)_/¯.
2024-01-15 20:05:03 +11:00
Stephen Gregoratto
cca021c211 Linux: Update syscalls for the 6.7 release
This release adds the rest of the futex2[1] syscalls, along with
shadow stack[2] support for more architectures.

[1]: https://lwn.net/Articles/940944/
[2]: https://lwn.net/Articles/926649/
2024-01-15 20:05:03 +11:00
Jakub Konka
3dddb881bf
Merge pull request #18560 from ziglang/elf-report-dupes
elf: report duplicate symbol definitions
2024-01-15 07:37:09 +01:00
Jakub Konka
852e7e24b5
Merge pull request #17917 from Jan200101/PR/each_lib_rpath_frontend
move rpath to frontend and remove native paths from it
2024-01-15 07:35:12 +01:00
Andrew Kelley
a5934edd48 std.os.linux.io_uring: fix compilation errors
Commit f0c42fbba1 was created before the
additional compile error for var used instead of const.
2024-01-14 19:20:41 -07:00
Andrew Kelley
f0c42fbba1
Merge pull request #18025 from ianic/io_uring_send_zc
io_uring: add send_zc and *_direct operations
2024-01-14 18:10:51 -08:00
expikr
ff23efe9fa Update pow.zig 2024-01-14 18:09:26 -08:00
expikr
0c70d9c714 use Peer Type Resolution for standalone complex fn
use peer type resolution

Update complex.zig

Revert "use peer type resolution"

This reverts commit 1bc681ca5b.

Revert "Update pow.zig"

This reverts commit 5487e8d3159f832b5a0bf29a06bd12575182464f.

Update pow.zig

Revert "Update pow.zig"

This reverts commit 521153d1ef.

Update pow.zig
2024-01-14 18:09:17 -08:00
Tristan Ross
9fce1d1ab1
mem: add byteswap array support (#17959)
also make byteswap work with enums
2024-01-14 21:06:31 -05:00
expikr
f9d8176e94
Update atan2.zig (#17840)
Co-authored-by: castholm <carl@astholm.se>
2024-01-14 21:04:30 -05:00
expikr
1a7a711964
std.math: add wrap function (#18154) 2024-01-14 20:45:39 -05:00
Jan200101
e517d5a51e std.zig.system.NativePaths: add NixOS lib dirs to the rpath 2024-01-14 15:57:45 -07:00
Jakub Konka
a8b9f0cf22 std/Build/Step/Compile: do not propagate deps of complex addObject step 2024-01-14 23:07:21 +01:00
Andrew Kelley
4debd4338c
Merge pull request #18547 from ziglang/gh-fork-dump-fchmod-fixes
Add `fchmodat` fallback on Linux when `flags` is nonzero.
2024-01-14 11:26:25 -08:00
Krzysztof Wolicki
78549d1e10 mingw: Add missing misc/mingw-access.c and misc/ucrt-access.c 2024-01-14 11:25:01 -08:00
Andrew Kelley
09074d7cd7 std.os: proper use of inline
Uses `inline` only to forward the comptime-ness of the flags parameter
to function selection.

Also fixes doc comments in std.c.versionCheck.
2024-01-13 23:56:32 -07:00
Stephen Gregoratto
01cc904fc7 Rework fchmodat tests
Based on the Linux kernel fchmodat2 test
2024-01-13 23:52:01 -07:00
Stephen Gregoratto
bc69d62669 Linux: Add fchmodat fallback when flags is nonzero
The check for determining whether to use the fallback code has been
moved into an inline function as per Andrew's comments in #17954.
2024-01-13 23:52:01 -07:00
Stephen Gregoratto
cf6751ae55 Add fchmodat2 bits to os/linux.zig 2024-01-13 23:52:01 -07:00
Stephen Gregoratto
26db31f6f6 Add fchmodat2 to the Linux syscall list
This syscall was added to simplify the the libc implementations of
fchmodat, as the original syscall does not take a `flags` argument.

Another syscall, `map_shadow_stack`, was also added for x86_64.
2024-01-13 23:52:01 -07:00
Andrew Kelley
bd46410419 Revert "Merge pull request #18410 from dweiller/by-length-slice-bug"
This reverts commit d9d840a33a, reversing
changes made to a04d433094.

This is not an adequate implementation of the missing safety check, as
evidenced by the changes to std.json that are reverted in this commit.

Reopens #18382
Closes #18510
2024-01-13 23:21:44 -07:00
Carl Åstholm
0f9345ea9a Expose -f(no-)formatted-panics to the build system (again) 2024-01-13 22:07:34 -08:00
Ryan Liptak
4dd3505e43 std.ArrayList: Clarify that ensureTotalCapacity/ensureTotalCapacityPrecise will never shrink the array
Closes #18499
2024-01-13 19:58:22 -08:00
vinnichase
279607cae5
Fix fmt UTF-8 characters as fill (#18533)
Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>
2024-01-13 22:47:03 -05:00
Nameless
b723296e1f std.http: add missing documentation and a few examples 2024-01-13 18:51:38 -08:00
Nameless
832f6d8f7f std.Uri: fix implementation of resolve with trailing slashes 2024-01-13 18:50:29 -08:00
Guillaume Wenzek
c5d359e4cd fix #17142, wrong comptime log_int computation 2024-01-13 18:46:16 -08:00
Igor Anić
7d3a31872e tar: improve diagnostic reporting
Using Python testtar file (mentioned in #14310) to test diagnostic
reporting.
Added computing checksum by using both unsigned and signed header bytes
values.
Added skipping gnu exteneded sparse headers while reporting unsupported
header in diagnostic.

Note on testing:

wget https://github.com/python/cpython/raw/3.11/Lib/test/testtar.tar -O
/tmp/testtar.tar

```
test "Python testtar.tar file" {
    const file_name = "testtar.tar";

    var file = try std.fs.cwd().openFile("/tmp/" ++ file_name, .{});
    defer file.close();

    var diag = Options.Diagnostics{ .allocator = std.testing.allocator };
    defer diag.deinit();

    var iter = iterator(file.reader(), &diag);
    while (try iter.next()) |f| {
        std.debug.print("supported: {} {s} {d}\n", .{ f.kind, f.name, f.size });
        try f.skip();
    }
    for (diag.errors.items) |e| {
        switch (e) {
            .unsupported_file_type => |u| {
                std.debug.print("unsupported: {} {s}\n", .{ u.file_type, u.file_name });
            },
            else => unreachable,
        }
    }
}
```
2024-01-13 19:37:33 -07:00
Igor Anić
7923a53996 tar: rename reader to iterator
Itarator has `next` function, iterates over tar files. When using from
outside of module with `tar.` prefix makes more sense.

var iter = tar.iterator(reader, null);
while (try iter.next()) |file| {
...
}
2024-01-13 19:37:33 -07:00
Igor Anić
e21a12e56b tar: use @embedFile in tests
Like in other tests which uses testdata files (compress). That enables
wasi testing also, was failing because file system operations in tests.
2024-01-13 19:37:33 -07:00
Igor Anić
76fe1f53d5 tar: fix tests on 32-bit platforms 2024-01-13 19:37:33 -07:00
Igor Anić
a75fd4ff15 tar: move test cases to std/tar/testdata
Create std/tar/test.zig for test which uses cases from testdata.
2024-01-13 19:37:33 -07:00
Igor Anić
f8e42d6b30 tar: add Go test case files to the project 2024-01-13 19:37:33 -07:00
Igor Anić
c07527abac tar: reorganize file, functions before tests 2024-01-13 19:37:33 -07:00
Igor Anić
c76abe0e18 tar: use file word in less places 2024-01-13 19:37:33 -07:00
Igor Anić
4a6d67ab1a tar: remove stratch from tar reader
Use explicit buffers for name, link_name instead.
It is cleaner that way.
2024-01-13 19:37:33 -07:00
Igor Anić
9f7dd32308 tar: refactor pax attribute
Make it little readable.
2024-01-13 19:37:33 -07:00
Igor Anić
dbab45cfc6 tar: replace custom buffered reader with std.io 2024-01-13 19:37:33 -07:00
Igor Anić
58e0e509c6 tar: add module comment and references 2024-01-13 19:37:33 -07:00
Igor Anić
a3cf8ec71e tar: add pax file reader tests 2024-01-13 19:37:33 -07:00
Igor Anić
7b0bbc680f tar: add file mode to result of tarbal iteration
So we have information to set executable bit on write to file system.
2024-01-13 19:37:33 -07:00
Igor Anić
2a432d3008 tar: prefix test cases with 'tar'
To make it little easier to filter from all stdlib tests.
2024-01-13 19:37:33 -07:00
Igor Anić
2ed9a276a7 tar: use Go test cases path from env variable
Skip tests if env is not set.
2024-01-13 19:37:33 -07:00
Igor Anić
6bfa7bf197 tar: use scratch buffer for file names
That makes names strings stable during the iteration. Otherwise string
buffers can be overwritten while reading file content.
2024-01-13 19:37:33 -07:00
Igor Anić
6e7a39c935 tar: refactor reading pax attributes 2024-01-13 19:37:33 -07:00
Igor Anić
c761dfc176 tar: add gnu path and link extensions handling 2024-01-13 19:37:33 -07:00
Igor Anić
48b160c1bf tar: handle pax null attrs and pax attr ending 2024-01-13 19:37:33 -07:00
Igor Anić
16c40fc471 tar: add header chksum checking 2024-01-13 19:37:33 -07:00
Igor Anić
169f28d3e6 tar: fix import path 2024-01-13 19:37:33 -07:00
Igor Anić
e1424b84b8 tar: add parsing size in gnu extended format
Reference:
https://www.gnu.org/software/tar/manual/html_node/Extensions.html#Extensions

If the leading byte is 0x80 (128), the non-leading bytes of the field
are concatenated in big-endian order, with the result being a positive
number expressed in binary form.
2024-01-13 19:37:33 -07:00
Igor Anić
6d5283e835 tar: refactor reader and iterator
Make it more readable.
2024-01-13 19:37:33 -07:00
Igor Anić
be5d04ab79 tar: add pax linkpath attribute parsing
Name of symbolic link can be also found in pax attribute.
2024-01-13 19:37:33 -07:00
Igor Anić
1817063375 tar: add initial test cases
Just adding tests, without changing functionality.
2024-01-13 19:37:33 -07:00
Igor Anić
4381241237 tar: refactor Buffer
Move reader into Buffer and make it BufferedReader. This doesn't
introduce any new functionality just grouping similar things.
2024-01-13 19:37:33 -07:00
Igor Anić
ff8544daa5 tar: refactor code to be more testable
Split reading/parsing tar file and writing results to the disk in two
separate steps. So we can later test parsing part without need to write
everyting to the disk.
2024-01-13 19:37:33 -07:00
Jacob Young
7916cf6f83 std.io.GenericReader: add missing error annotations 2024-01-13 13:16:51 -08:00
Michael Scott
e5dc9b1d09 Update styles in std docs to correct display glitch 2024-01-12 16:25:55 -08:00
Chris Boesch
d8b5831dc4 Fixed verbatim copy of trailing '%' in unescapeStr 2024-01-12 16:20:44 -08:00
Meghan Denny
f49a8c5431 std: make c.versionCheck() a comptime-known function 2024-01-12 16:17:39 -08:00
Andrew Kelley
45ec851733 zig build: handle stderr more elegantly
* Specifically recognize stderr as a different concept than an error
  message in Step results.
* Display it differently when only stderr occurs but the build proceeds
  successfully.

closes #18473
2024-01-10 17:11:26 -08:00
Andrew Kelley
854b88fda0 tsan: update rtl files to LLVM 17.0.6 2024-01-10 01:00:37 -07:00
Andrew Kelley
e025ad7b46 std.mem: fix simd.suggestVectorLength merge conflict
Commits
2f8e4347b1 and
6a32d58876 had a conflict that was
undetected by source control.
2024-01-09 18:20:53 -07:00
Veikka Tuominen
828d23956d std.heap: add runtime safety for calling stackFallback(N).get multiple times
Closes #16344
2024-01-09 17:18:20 -08:00
Andrew Kelley
6a32d58876
Merge pull request #18318 from castholm/simd-segfault
Rename `simd.suggestVectorSize` to clarify intent and fix related segfault
2024-01-09 17:13:58 -08:00
Matthew Wozniak
aaf1e0b25b
add ability to open dlls with platform-specific flags (#18370) 2024-01-09 20:11:22 -05:00
Bogdan Romanyuk
4a1a5ee47b
AstGen: add error for redundant comptime var in comptime scope (#18242) 2024-01-09 20:09:39 -05:00
Andrew Kelley
157cdaee0e
Merge pull request #18498 from castholm/cpu-cortex-m-optional-deps
Don't enable optional ARM Cortex-M series CPU features by default
2024-01-09 17:08:08 -08:00
PauloCampana
fcc0c5ddc7
Add std.math.gamma and lgamma (#18449)
See #7212
2024-01-09 14:53:47 -08:00
Carl Åstholm
0cd508b09f Re-run update_cpu_features (LLVM 17)
release/17.x branch, commit 8f4dd44097c9ae25dd203d5ac87f3b48f854bba8
(same as the previous run)
2024-01-09 17:53:43 +01:00
dhash
9bb6430318 Add support for --(no-)undefined-version
Co-authored-by: Motiejus Jakštys <motiejus@jakstys.lt>
Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
Co-authored-by: Samuel Cantero <scanterog@gmail.com>
Co-authored-by: Giorgos Georgiou <giorgos.georgiou@datadoghq.com>
Co-authored-by: Carl Åstholm <carl@astholm.se>
2024-01-09 17:24:11 +01:00
Andrew Kelley
60094cc3fc
Merge pull request #18491 from ziglang/fix-mod-link-obj-path
std.Build.Step.Compile: fix link object paths
2024-01-09 01:11:15 -08:00
joachimschmidt557
f12ec02bd7 stage2 AArch64: get empty file compiling again 2024-01-08 23:53:24 -08:00
David Rubin
2f8e4347b1
Optimized std.mem.eql with SIMD (#18389)
* optimized memeql
* add `sched_setaffinity` to `std.os.linux`

Co-authored-by: Protty <45520026+kprotty@users.noreply.github.com>
Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
2024-01-09 02:50:22 -05:00
Andrew Kelley
cf5a5dc8b5 std.Build.Step.Compile: fix link object paths
They were being resolved relative to the wrong owner.

closes #18460
2024-01-08 18:24:14 -07:00
Andrew Kelley
deed19496a
Merge pull request #16650 from wooster0/hexdump
general-use std.debug.hexdump for printing hexdumps
2024-01-08 16:25:15 -08:00
Andrew Kelley
4cf08932b5
Merge pull request #16109
Update mingw-w64 to latest git commit
2024-01-08 16:13:14 -08:00
Carl Åstholm
9c8c9b7cc8 Build: Use LazyPath for version scripts 2024-01-09 01:47:54 +02:00
Amir Alawi
4cbf74bd9b
fix std.fs.Dir.makePath silent failure (#16878)
std.fs.dir.makePath silently failed if one of the items in the path already exists. For example:

cwd.makePath("foo/bar/baz")
Silently failing is OK if "bar" is already a directory - this is the intended use of makePath (like mkdir -p). But if bar is a file then the subdirectory baz cannot be created - the end result is that makePath doesn't do anything which should be a detectable error because baz is never created.

The existing code had a TODO comment that did not specifically cover this error, but the solution for this silent failure also accomplishes the TODO task - the code now stats "foo" and returns an appropriate error. The new code also handles potential race condition if "bar" is deleted/permissions changed/etc in between the initial makeDir and statFile calls.
2024-01-08 15:58:14 -05:00
Andrew Kelley
9a4a74eb65 mingw: remove pow.c from aarch64-windows mingw builds
I observed a duplicate symbol linker error; pow was defined both by
mingwex.lib and ucrtbase.dll.
2024-01-08 11:53:06 -07:00
Andrew Kelley
9df0177f33 mingw: add the mingw stdio functions back
We would rather use the ucrt for these, but sometimes dependencies on
the mingw stdio functions creep in. 仕方ない.

The cost is only paid if they are used; otherwise the symbols are
garbage-collected at link time.
2024-01-08 11:52:38 -07:00
Andrew Kelley
6405d37d9f add config.h 2024-01-08 11:52:38 -07:00
Andrew Kelley
c26bace606 mingw-w64: update CRT files to latest git commit
Upstream commit dddccbc3ef50ac52bf00723fd2f68d98140aab80

* adds ucrtbase.def.in
* mingwex: replace mingw crt files with ucrt files
* adds missing mingw-w64 ucrt files

The rules that govern which set of files are included or excluded is
contained in the logic for tools/update_mingw.zig
2024-01-08 11:52:38 -07:00
Andrew Kelley
9346cd38e8 update mingw-w64 headers to latest git commit
Upstream commit dddccbc3ef50ac52bf00723fd2f68d98140aab80

Martin Storsjö suggested synchronizing with git snapshots rather than
waiting for tagged releases. Let's try this for a few releases of Zig
and see how we like it.

These headers were configured with `--with-default-msvcrt=ucrt`.

See related issue #18477.
2024-01-08 11:52:37 -07:00
Andrew Kelley
25d2e7fce0 fixups from previous commit
* rename the functions
* make the other function public and give it a better name
* interact with stderr_mutex
* std lib test coverage
2024-01-08 00:21:57 -07:00
Wooster
ad7a09d95a std.testing.expectEqualSlices: some improvements
This mainly replaces ChunkIterator with std.mem.window and also
prints \n, \r, \t using Unicode symbols instead of periods because
they're common non-printable characters.
This same code exists in std.debug.hexdump.
At some point maybe this code could be exposed through a public
function. Then we could reuse the code in both places.
2024-01-08 00:13:21 -07:00
Wooster
dfc4d618dd general-use std.debug.hexdump for printing hexdumps
Recently, when I've been working with structures of data that is not
directly in RAM but rather laid out in bytes somewhere else,
it was always very useful to print out maybe the next 50 bytes or the
previous 50 bytes or so to see what's ahead or before me.
I would usually do this with a quick
`std.debug.print("{any}\n", .{bytes});` or something but the output is
not as nice obviously.
2024-01-08 00:13:06 -07:00
Andrew Kelley
3176fdc0b9
Merge pull request #18470 from castholm/typeInfo-sentinels
Make `@typeInfo` return null-terminated strings
2024-01-07 22:28:24 -08:00
Eric Eastwood
2115d7d1be Add approxEqAbs support for comptime_float 2024-01-07 22:23:06 -08:00
Carl Åstholm
92458094c8 Fix failing type reifications 2024-01-07 16:27:50 +01:00
Carl Åstholm
c8fa767f08 Work around stage1 not yet returning null-terminated @typeInfo strings
These changes can be reverted the next time stage1 is updated.
2024-01-07 16:21:08 +01:00
Carl Åstholm
a02bd81760 Make @typeInfo return null-terminated strings
Changes the types of `std.builtin.Type` `name` fields from `[]const u8`
to `[:0]const u8`, which should make them easier to pass to C APIs
expecting null-terminated strings.

This will break code that reifies types using `[]const u8` strings, such
as code that uses `std.mem.tokenize()` to construct types from strings
at comptime. Luckily, the fix is simple: simply concatenate the
`[]const u8` string with an empty string literal (`name ++ ""`) to
explicitly coerce it to `[:0]const u8`.

Co-authored-by: Krzysztof Wolicki <der.teufel.mail@gmail.com>
2024-01-07 15:35:18 +01:00
Tristan Ross
22598ef35f std.Build: pass code model in various compile steps 2024-01-06 18:33:24 -08:00
Andrew Kelley
282ff8d3bd
Merge pull request #18453 from squeek502/makepath-parent-components
Add more `Dir.makePath` tests and document how `..` is handled in sub_path
2024-01-06 16:47:39 -08:00
Ryan Liptak
51946f5adc Dir.makePath: Document/test platform differences around .. component handling
Closes #18452
2024-01-05 17:56:31 -08:00
Pat Tullmann
9335529b9b std.fs: Add several more tests for makePath. 2024-01-04 23:20:35 -08:00
Pat Tullmann
04ac028a2c std.CompTimeStringMap*: support empty initialization list
Add tests for empty initialization, and some more corner cases (empty key,
very long key, duplicate keys).

Fixes #18212
2024-01-05 05:09:24 +02:00
Andrew Kelley
362460ec24 minor cosmetic fixups
* fix typos and redundancies in docs
* use Target.isGnuLibc
2024-01-04 17:26:06 -07:00
Pat Tullmann
4a5d73a34d glibc: strlcpy and strlcat arrived in glibc 2.38
So only expose these in generic-glibc/string.h if Zig is building
a v2.38 (or later) glibc stub.

Announcement of 2.38 that notes strlcpy and strlcat:
https://lists.gnu.org/archive/html/info-gnu/2023-07/msg00010.html
2024-01-04 17:12:07 -07:00
Pat Tullmann
71e809852c lib/libc/glibc/: Add README.md
Add a README with an overview of how Zig's glibc support is implemented.
2024-01-04 17:12:07 -07:00
Pat Tullmann
1564cb0ab9 std/fs/test.zig: Remove work-around for stat() failures on glibc
glibc variants now support the stat-family of calls correctly, so
this test is safe to include.
2024-01-04 17:12:07 -07:00
Pat Tullmann
2c6372a117 glibc: restore "weak_hidden_alias" macro for older glibc versions
The fstat,lstat,stat,mknod stubs used to build older (before v2.33)
glibc versions depend on the weak_hidden_alias macro.  It was removed
from the glibc libc-symbols header, so patch it back in for the older
builds.
2024-01-04 17:12:07 -07:00
Kang Seonghoon
f1bd218a88 glibc: remove unused stat-related files for 2.33+
Effectively reverts 3dcd3612dc.
2024-01-04 17:12:07 -07:00
Kang Seonghoon
7dcf7412c4 glibc: get correct files compiled into libc_nonshared.a
The scope of libc_nonshared.a was greatly changed in glibc 2.33 and
2.34, but only the change from 2.34 was reflected so far. Glibc 2.33
finally switched to versioned symbols for stat functions, meaning that
libc_nonshared.a no longer contains them since 2.33. Relevant files were
therefore reverted to 2.32 versions and renamed accordingly.

This commit also removes errno.c, which was probably added to
libc_nonshared.a based on a wrong assumption that glibc/include/errno.h
requires glibc/csu/errno.c. In reality errno.h should refer to
__libc_errno (not to be confused with the public __errno_location),
which should be imported from libc.so. The inclusion of errno.c resulted
in wrong compile options as well; this commit fixes them as well.

Fixes #16152
2024-01-04 17:12:07 -07:00
Abhinav Gupta
d3a163f868
build/LazyPath: Add dirname (#18371)
Adds a variant to the LazyPath union representing a parent directory
of a generated path.

```zig
const LazyPath = union(enum) {
    generated_dirname: struct {
        generated: *const GeneratedFile,
        up: usize,
    },
    // ...
}
```

These can be constructed with the new method:

```zig
pub fn dirname(self: LazyPath) LazyPath
```

For the cases where the LazyPath is already known
(`.path`, `.cwd_relative`, and `dependency`)
this is evaluated right away.
For dirnames of generated files and their dirnames,
this is evaluated at getPath time.

dirname calls can be chained, but for safety,
they are not allowed to escape outside a root
defined for each case:

- path: This is relative to the build root,
  so dirname can't escape outside the build root.
- generated: Can't escape the zig-cache.
- cwd_relative: This can be a relative or absolute path.
  If relative, can't escape the current directory,
  and if absolute, can't go beyond root (/).
- dependency: Can't escape the dependency's root directory.

Testing:
I've included a standalone case for many of the happy cases.
I couldn't find an easy way to test the negatives, though,
because tests cannot yet expect panics.
2024-01-04 18:47:28 -05:00
xdBronch
15f7a477d0 fallback to zigs DynLib when static linking musl 2024-01-04 18:02:45 +02:00
xdBronch
6ebeb85abd speed up sliceTo when end == sentinel 2024-01-04 17:54:56 +02:00
Anubhab Ghosh
d525c59808 Enable gnu_f16_abi on x86_64 2024-01-04 17:41:30 +02:00
Andrew Kelley
537e2808e0 build system: fix missing step dependencies on lib
When depending on a module that depends on a static library, there was a
missing step dependency on the static library, which caused a compile
error due to missing header file.

This fixes the problem by adding the proper step dependencies.

Reviewing this code, I'm starting to wonder if it might be simpler to
have Module instances create dummy Step objects to better model
dependencies and dependees, rather than trying to maintain this graph
without an actual node. That would be an improvement for a future
commit.
2024-01-04 03:44:26 -08:00
Andrew Kelley
fc79b22a98
Merge pull request #17431 from castholm/expectEqual
Update `std.testing.expectEqual` and friends to use peer type resolution
2024-01-03 23:55:59 -08:00
Krzysztof Wolicki
ecd520f661 Fix std.Build.findProgram 2024-01-03 18:18:48 -08:00
Andrew Kelley
f64205b445
Merge pull request #18262 from ziglang/fix-18259
std.Build.Step.Run: fix depfile support
2024-01-03 13:23:40 -08:00
Andrew Kelley
ce480dedbb
Merge pull request #18403 from FnControlOption/parse
std.zig: Miscellaneous cleanup
2024-01-03 13:10:26 -08:00
Andrew Kelley
a9337bef2d
Merge pull request #18431 from jacobly0/cbe-extern
cbe: fix non-msvc externs and exports
2024-01-03 12:57:01 -08:00
Carl Åstholm
85869f8225 Correct expected/actual parameter order of some assertions 2024-01-03 21:20:49 +01:00
Carl Åstholm
d7b36503ca Remove some @as coercions from assertions
These are some spurious fixes to help illustrate the improved ergonomics of the `expectEqual` change. It is by no means complete.
2024-01-03 21:20:48 +01:00
Carl Åstholm
4c1da0912a Fix compile errors from the expectEqual change 2024-01-03 21:20:48 +01:00
Carl Åstholm
e5994f5f57 Update std.testing.expectEqual and friends to use peer type resolution
This commit changes the type of the second parameter to `anytype`, which should make it easier to pass literals to these functions. This change shouldn't *silently* break existing code (the assertions themselves should retain the same behavior as before) but it may result in some new compile errors when struct/union/array literals or builtins like `@bitCast` are used for the second argument. These compile errors can be fixed by explicitly coercing these expressions to the correct type using `@as`.
2024-01-03 21:20:48 +01:00
Karl Böhlmark
9a56228c2b
doc: Fix typos in bpf docs 2024-01-03 12:34:10 +02:00
Jacob Young
047d6d996e cbe: fix non-msvc externs and exports
Closes #17817
2024-01-03 02:52:25 -05:00
Jacob Young
98b633ff17 Reapply "Merge pull request #17824 from kcbanner/fixup_msvc_fmax"
This reverts commit 2b58978360.
2024-01-03 02:41:21 -05:00
Andrew Kelley
60958d135f std.Build.Step.Compile: fix passing wrong Builder to getPath
This resulted in an error building a transitive module dependency.
2024-01-02 18:22:11 -07:00
Andrew Kelley
289ae45c1b
Merge pull request #18160 from ziglang/std-build-module
Move many settings from being per-Compilation to being per-Module
2024-01-02 14:11:27 -08:00
PanSashko
c89bb3e141 Fix std.enums.values
Current implementation fails to handle the following enum

```zig
const E = enum {
  X,
  pub const X = 1;
}
```

because `@field(type, name)` prefers declarations over enum fields.
2024-01-02 20:28:55 +02:00
Meghan Denny
e19219fa0e std.ComptimeStringMap: allow getting kv index 2024-01-02 17:40:30 +02:00
Veikka Tuominen
d9d840a33a
Merge pull request #18410 from dweiller/by-length-slice-bug
sema: add compile error for OOB by-length slice of array
2024-01-02 17:37:21 +02:00
sammy j
a04d433094 add support for lists when parsing user args 2024-01-02 17:35:11 +02:00
Loris Cro
65878c16ee std.Build.Step.Run: fix depfile support 2024-01-02 11:54:32 +01:00
Andrew Kelley
eae6d45cde CLI: introduce global -I args for C include paths
This isn't technically needed since per-module -I args can suffice, but
this can produce very long CLI invocations when several --mod args are
combined with --search-prefix args since the -I args have to be repeated
for each module.

This is a partial revert of ecbe8bbf2df2ed4d473efbc32e0b6d7091fba76f.
2024-01-01 19:49:08 -07:00
Andrew Kelley
6b2709616e frontend: ignore AccessDenied when writing builtin.zig
This issue already existed in master branch, however, the more
aggressive caching of builtin.zig in this branch made it happen more
often. I added doc comments to AtomicFile to explain when this problem
can occur.

For the compiler's use case, error.AccessDenied can be simply swallowed
because it means the destination file already exists and there is
nothing else to do besides proceed with the AtomicFile cleanup.

I never solved the mystery of why the log statements weren't printing
but those are temporary debugging instruments anyway, and I am already
too many yaks deep to whip out another razor.

closes #14978
2024-01-01 19:49:08 -07:00
Andrew Kelley
96b4eeab55 std: disable failing test on macos
See tracking issue https://github.com/ziglang/zig/issues/18395
2024-01-01 19:49:08 -07:00
Andrew Kelley
8fa4496909 std.Build.Step.Compile: fix search prefix lowering
Instead of adding -I and -L flags at the end of the CLI, they need to be
added for every module, after the module-specific flags.
2024-01-01 19:49:08 -07:00
Andrew Kelley
8babc14cdf std.Build.Module: default CSourceFile flags to empty list 2024-01-01 19:49:08 -07:00
Andrew Kelley
beed47e8c3 std.Build: add error_tracing field to addExecutable and friends
To support easily overriding error return tracing for the main module.
2024-01-01 19:49:07 -07:00
Andrew Kelley
190f6038bf zig build: reintroduce --prominent-compile-errors
This reintroduced flag makes zig build behave the same as the previous
commit. Without this flag, the default behavior is now changed to
display compilation errors inline with the rest of error messages and
the build tree context.

This behavior is essential for making sense of error logs from projects
that have two or more steps emitting compilation errors which is why it
is now the default.
2024-01-01 19:49:07 -07:00
Andrew Kelley
1ef4df9044 std.Build.Step.Compile: support modules with different args
Now that the CLI supports per-module settings, the build system takes
advantage of this when lowering a compilation to the command line.
2024-01-01 17:51:21 -07:00
Andrew Kelley
76c4781578 std.Build.Step.Options: update unit test to new API 2024-01-01 17:51:20 -07:00
Andrew Kelley
ca77c3bacc std.Build.Step.Compile: restore previous step name
Print using the target query rather than the resolved target. This makes
it print "native" when compiling for the native target.
2024-01-01 17:51:20 -07:00
Andrew Kelley
d71e6273b6 std.fs.Dir.atomicFile: provide an option for make path
It's useful for the API to support creating the parent directory.
2024-01-01 17:51:20 -07:00
Andrew Kelley
12de7e3472 WIP: move many global settings to become per-Module
Much of the logic from Compilation.create() is extracted into
Compilation.Config.resolve() which accepts many optional settings and
produces concrete settings. This separate step is needed by API users of
Compilation so that they can pass the resolved global settings to the
Module creation function, which itself needs to resolve per-Module
settings.

Since the target and other things are no longer global settings, I did
not want them stored in link.File (in the `options` field). That options
field was already a kludge; those options should be resolved into
concrete settings. This commit also starts to work on that, deleting
link.Options, moving the fields into Compilation and
ObjectFormat-specific structs instead. Some fields were ephemeral and
should not have been stored at all, such as symbol_size_hint.

The link.File object of Compilation is now a `?*link.File` and `null`
when -fno-emit-bin is passed. It is now arena-allocated along with
Compilation itself, avoiding some messy cleanup code that was there
before.

On the command line, it is now possible to configure the standard
library itself by using `--mod std` just like any other module. This
meant that the CLI needed to create the standard library module rather
than having Compilation create it.

There are a lot of changes in this commit and it's still not done. I
didn't realize how quickly this changeset was going to balloon out of
control, and there are still many lines that need to be changed before
it even compiles successfully.

* introduce std.Build.Cache.HashHelper.oneShot
* add error_tracing to std.Build.Module
* extract build.zig file generation into src/Builtin.zig
* each CSourceFile and RcSourceFile now has a Module owner, which
  determines some of the C compiler flags.
2024-01-01 17:51:18 -07:00
Andrew Kelley
b92e30ff0b std.Build.ResolvedTarget: rename target field to result
This change is seemingly insignificant but I actually agonized over this
for three days. Some other things I considered:

* (status quo in master branch) make Compile step creation functions
  accept a Target.Query and delete the ResolvedTarget struct.
  - downside: redundantly resolve target queries many times
* same as before but additionally add a hash map to cache target query
  resolutions.
  - downside: now there is a hash map that doesn't actually need to
    exist, just to make the API more ergonomic.
* add is_native_os and is_native_abi fields to std.Target and use it
  directly as the result of resolving a target query.
  - downside: they really don't belong there. They would be available
    as comptime booleans via `@import("builtin")` but they should not
    be exposed that way.

With this change the downsides are:
* the option name of addExecutable and friends is `target` instead of
  `resolved_target` matching the type name.
  - upside: this does not break compatibility with existing build
    scripts
* you likely end up seeing `target.result.cpu.arch` rather than
  `target.cpu.arch`.
  - upside: this is an improvement over `target.target.cpu.arch` which
    it was before this commit.
  - downside: `b.host.target` is now `b.host.result`.
2024-01-01 17:51:18 -07:00
Andrew Kelley
8d5da55588 std.Target.Query: fix regression with windows os version range
somebody left a landmine here without even a comment to warn about it
2024-01-01 17:51:18 -07:00
Andrew Kelley
3e52302644 std.Build: fix userInputOptionsFromArgs ResolvedTarget
it wasn't using the Target.Query like it was supposed to for the triple
2024-01-01 17:51:18 -07:00
Andrew Kelley
8c44954bc6 std.Target.Query: remove deprecated API
These functions have been doomed for a long time. Finally I figured out
what the proper relationship between this API and std.Target is.
2024-01-01 17:51:18 -07:00
Andrew Kelley
dbdb87502d std.Target: add DynamicLinker 2024-01-01 17:51:18 -07:00
Andrew Kelley
3179f58c41 rename std.zig.CrossTarget to std.Target.Query 2024-01-01 17:51:18 -07:00
Andrew Kelley
67d48b94d6 std.Target: flatten 2024-01-01 17:51:18 -07:00
Andrew Kelley
767eb5da77 fix infinite loop in Run step
Previously this relied on recursion; now it relies on the recursive
iteration which is better, but means the recursive call needs to be
deleted.
2024-01-01 17:51:18 -07:00
Andrew Kelley
3963be03ec std.Build: handle ResolvedTarget in userInputOptionsFromArgs 2024-01-01 17:51:18 -07:00
Andrew Kelley
04480f72d8 fix linker test regressions
Caused by problems with transitive dependencies
2024-01-01 17:51:18 -07:00
Andrew Kelley
0ee8fbb15d build runner: print subtree of failed nodes context
Previously when an error message is printed, it is sometimes not
possible to know which build step it corresponds to. With the subtree
printed in this commit, the context is always clear.
2024-01-01 17:51:18 -07:00
Andrew Kelley
ad385649b9 fix std lib tests 2024-01-01 17:51:18 -07:00
Andrew Kelley
dd45095ba1 spelling fixes 2024-01-01 17:51:18 -07:00
Andrew Kelley
142471fcc4 zig build system: change target, compilation, and module APIs
Introduce the concept of "target query" and "resolved target". A target
query is what the user specifies, with some things left to default. A
resolved target has the default things discovered and populated.
In the future, std.zig.CrossTarget will be rename to std.Target.Query.
Introduces `std.Build.resolveTargetQuery` to get from one to the other.

The concept of `main_mod_path` is gone, no longer supported. You have to
put the root source file at the module root now.

* remove deprecated API
* update build.zig for the breaking API changes in this branch
* move std.Build.Step.Compile.BuildId to std.zig.BuildId
* add more options to std.Build.ExecutableOptions, std.Build.ObjectOptions,
  std.Build.SharedLibraryOptions, std.Build.StaticLibraryOptions, and
  std.Build.TestOptions.
* remove `std.Build.constructCMacro`. There is no use for this API.
* deprecate `std.Build.Step.Compile.defineCMacro`. Instead,
  `std.Build.Module.addCMacro` is provided.
  - remove `std.Build.Step.Compile.defineCMacroRaw`.
* deprecate `std.Build.Step.Compile.linkFrameworkNeeded`
  - use `std.Build.Module.linkFramework`
* deprecate `std.Build.Step.Compile.linkFrameworkWeak`
  - use `std.Build.Module.linkFramework`
* move more logic into `std.Build.Module`
* allow `target` and `optimize` to be `null` when creating a Module.
  Along with other fields, those unspecified options will be inherited
  from parent `Module` when inserted into an import table.
* the `target` field of `addExecutable` is now required. pass `b.host`
  to get the host target.
2024-01-01 17:51:18 -07:00
Andrew Kelley
579f572cf2 zig build system: remove vcpkg integration
Instead of vcpkg, users are encouraged to use the Zig package manager to
fulfill dependencies on Windows.
2024-01-01 17:51:18 -07:00
Andrew Kelley
c20ad51c62 introduce std.Build.Module and extract some logic into it
This moves many settings from `std.Build.Step.Compile` and into
`std.Build.Module`, and then makes them transitive.

In other words, it adds support for exposing Zig modules in packages,
which are configured in various ways, such as depending on other link
objects, include paths, or even a different optimization mode.

Now, transitive dependencies will be included in the compilation, so you
can, for example, make a Zig module depend on some C source code, and
expose that Zig module in a package.

Currently, the compiler frontend autogenerates only one
`@import("builtin")` module for the entire compilation, however, a
future enhancement will be to make it honor the differences in modules,
so that modules can be compiled with different optimization modes, code
model, valgrind integration, or even target CPU feature set.

closes #14719
2024-01-01 17:51:18 -07:00
Andrew Kelley
134e8cf76a move is_libcpp_lib_name and is_libc_lib_name to std.Target 2024-01-01 17:51:18 -07:00
Andrew Kelley
1a3e0d6709 std.Uri: default some fields to null
so that it becomes practical to initialize Uri objects directly rather
than relying on unnecessary text parsing.
2024-01-01 17:51:18 -07:00
Andrew Kelley
2b58978360 Revert "Merge pull request #17824 from kcbanner/fixup_msvc_fmax"
This reverts commit 7161ed79c4, reversing
changes made to 3f2a65594e.

Unfortunately, this sat in the PR queue too long and the merge broke the
zig1.wasm bootstrap process.
2024-01-01 17:49:57 -07:00
davideger
e426ae43ae
Updated Utf8View example to format the single codepoint UTF-8 slice with {s} (#18288) 2024-01-01 18:47:27 -05:00
Andrew Kelley
7161ed79c4
Merge pull request #17824 from kcbanner/fixup_msvc_fmax
cbe: add a system for avoiding collisions with C compiler intrinsics
2024-01-01 15:36:16 -08:00
Carl Åstholm
564b1da214 Change < to <= in indexOfSentinel SIMD path 2024-01-01 16:25:17 +01:00
Carl Åstholm
59ac0d1eed Deprecate suggestVectorSize in favor of suggestVectorLength
The function returns the vector length, not the byte size of the vector or the bit size of individual elements. This distinction is very important and some usages of this function in the stdlib operated under these incorrect assumptions.
2024-01-01 16:18:57 +01:00
Carl Åstholm
781c3a985c Prevent reading over a page boundary in mem.indexOfSentinel
The size of the slice element was not correctly taken into account when determining whether a read would cross a page boundary.
2024-01-01 16:18:57 +01:00
dweiller
41d5aa1b36 prevent by-length slice compile error in static json parsing 2023-12-31 15:36:58 +11:00
Leonardo Gatti
4129996211 doc: possible typo at std.Thread.spawn comment 2023-12-30 14:17:36 +02:00
Mason Remaley
19ea7ca63c
Update formatFloat* docs to reflect limitation w/ large floats 2023-12-30 14:14:54 +02:00
fn ⌃ ⌥
75b3feee05 std.zig.Ast: Reorder fields to reflect position in source 2023-12-29 08:07:37 -08:00
fn ⌃ ⌥
20cde3f480 std.zig.Parse: Add parseFor helper method 2023-12-29 07:59:55 -08:00
fn ⌃ ⌥
2091ee2e61 std.zig.Parse: Miscellaneous cleanup 2023-12-29 07:58:19 -08:00
fn ⌃ ⌥
04dad64dbe std.zig.Ast: Fix docs for FnProto and FnProtoOne 2023-12-29 07:52:11 -08:00
Marcius
ff17b11692 refact: rectifified a typo in docs of stringify.zig 2023-12-28 00:06:30 +02:00
Veikka Tuominen
94c63f31f2
Merge pull request #18328 from ExpidusOS/feat/uefi-time
std: add support for getting the time in UEFI
2023-12-26 01:03:10 +02:00
Veikka Tuominen
cd30277142
Merge pull request #18309 from castholm/windows-argv
More accurate argv parsing/serialization on Windows
2023-12-26 00:54:13 +02:00
AlliedEnvy
1b0e913e0f std.hash_map: clarify error when Context is missing pub hash/eql 2023-12-23 16:15:19 +02:00
Frank Denis
21ae64852a
std.crypto.kem.kyber: mitigate KyberSlash (#18316)
On some architectures, including AMD Zen CPUs, dividing a secret
by a constant denominator may not be a constant-time operation.

And most Kyber implementations, including ours, could leak the
hamming weight of the shared secret because of this. See:

https://kyberslash.cr.yp.to

Multiplications aren't guaranteed to be constant-time either, but
at least on the CPUs we currently support, it is.
2023-12-22 15:57:16 +00:00
Vitalijus Valantiejus
fd98fc1c5f std.fmt: fix formatting of array pointers
- Clean up array formatting code. Remove buggy formatting of array
pointers, deference pointer to reuse existing array formatting logic.
- Change default specifier for array pointers to be "{any}", to be
consistent with slices.
- Allow using "{x}" and "{e}" for arrays and slices for all number
types, including u8.

Fixes #18185
2023-12-22 16:35:28 +02:00
Ryan Liptak
70b248497a fs: Add tests for deleteTree not following symlinks
In theory this is part of https://github.com/ziglang/zig/issues/18335, but these tests already pass since deleteTree does not depend on `OpenDirOptions.no_follow` behavior for these test cases:

- `deleteTree` always tries to delete the initial path as a file first, which will succeed on symlinks because `deleteFile` doesn't follow symlinks
- `deleteTree` when iterating a directory will get the type of symlinks as .sym_link, not as .directory (even if the symlink points to a directory), meaning it will never try to open a symlink as a directory.
2023-12-22 13:47:19 +02:00
Carl Åstholm
60982ea5bd Correct CreateProcessW parameter types 2023-12-22 12:23:27 +02:00
Veikka Tuominen
d787b78d2c
Merge pull request #18326 from squeek502/stat-symlink
`File.stat`: Support detection of `Kind.sym_link` on Windows
2023-12-22 12:06:10 +02:00
Ryan Liptak
f5d0664e78 Make 'stat of a symlink' test case not rely on OpenDirOptions.no_follow behavior
The `no_follow` behavior happened to allow opening a file descriptor of a symlink itself on Windows, but that behavior may change in the future. Instead, we implement the opening of the symlink as a file descriptor manually (and per-platform) in the test case.
2023-12-21 17:47:32 -08:00
Tristan Ross
97fd100471
os.uefi: add ns to epoch 2023-12-20 20:05:16 -08:00
Ryan Liptak
dd189a354b Fix Stat.ctime docs, and correct its value on Windows
ctime is last file status/metadata change, not creation time. Note that this mistake was not made in the `File.metadata`/`File.Metadata` implementation, which allows getting the actual creation time.

Closes #18290
2023-12-20 19:43:28 +02:00
Tristan Ross
23adf09579
time: add uefi support 2023-12-20 09:24:10 -08:00
Maximilian
697b8f7d2f
Grammar fixes (#18320)
* Grammar fixes

Just a couple things I noticed

* Update build.zig.zon.md

Fix a/an usage for zon doc
2023-12-20 13:17:15 +02:00
Tristan Ross
a86cd91389
os.uefi: add time to epoch conversion 2023-12-19 23:42:47 -08:00
Ryan Liptak
11a398af3e File.stat: Support detection of Kind.sym_link on Windows
Requires an extra NtQueryInformationFile call when FILE_ATTRIBUTE_REPARSE_POINT is set to determine if it's actually a symlink or some other kind of reparse point (https://learn.microsoft.com/en-us/windows/win32/fileio/reparse-point-tags). This is something that `File.Metadata.kind` was already doing, so the same technique is used in `stat`.

Also, replace the std.os.windows.DeviceIoControl call in `metadata` with NtQueryInformationFile (NtQueryInformationFile is what gets called during kernel32.GetFileInformationByHandleEx with FileAttributeTagInfo, verified using NtTrace).
2023-12-19 23:36:23 -08:00
Andrew Kelley
cd7960ea75 std: disable flaky tcp server test
Tracking issue: #18315
2023-12-19 12:01:09 -07:00
Carl Åstholm
4d9c4ab82c More accurate argv-to-command-line serialization when spawning child processes on Windows
The old implementation had a bug in it in that it didn't quote empty strings, but it also didn't properly follow the special quoting rules required for the first argument (the executable name). This new implementation serializes the argv correctly such that it can be parsed by the `CommandLineToArgvW` algorithm.
2023-12-18 23:58:26 +01:00
Carl Åstholm
13f78e24b8 Update ArgIterator on Windows to follow standard Windows parsing rules
This adds `ArgIteratorWindows`, which faithfully replicates the quoting and escaping behavior observed in `CommandLineToArgvW` and should make Zig applications play better with processes that abuse these quirks.
2023-12-18 22:55:46 +01:00
Artem Kolichenkov
90a19f7411
std.net: add explicit error sets for IP parsing
Inferred errors in switch statements prevented IP address parsing at comptime.
Adding explicit error sets fixes it.

Closes #18276
2023-12-16 16:15:51 +00:00
Carl Åstholm
779b8e2598 Expose -f(no-)formatted-panics to the build system 2023-12-16 04:08:05 +02:00
Jan Philipp Hafer
70664547ce std.net.test: cleanup socket stream 2023-12-15 21:15:35 +02:00
Jakub Konka
5d12622469 lib/std/Build/CheckObject: split dyld info into subsections for easier scoped testing 2023-12-13 13:53:05 +01:00
Jakub Konka
f26459e594 lib/std/Build/CheckObject: update all tests to new API 2023-12-13 12:06:25 +01:00
Jakub Konka
c4519d6bba lib/std/Build/CheckObject: implement for Wasm 2023-12-13 11:41:51 +01:00
Jakub Konka
92cca7fbf1 lib/std/Build/CheckObject: implement for ELF 2023-12-13 11:38:57 +01:00
Jakub Konka
2492488501 lib/std/Build/CheckObject: introduce scoped checks; implement for MachO 2023-12-13 11:22:46 +01:00
Jakub Konka
a38af5f542 lib/std/Build/CheckObject: fix parsing and dumping special dylib lookup values 2023-12-13 01:29:01 +01:00
loris
37458cc886 allow sqe entries up to 32768 2023-12-12 06:49:19 +02:00
Loris Cro
26e27f5f64 std.Build.Cache: add HexDigest type 2023-12-11 23:08:03 +01:00
Eric Eastwood
5c1428ea9d
Add getPtrConstAssertContains(...) for compatibility with a const std.EnumMap
This way people can use `const` with a `std.EnumMap`
and be able to `getPtrAssertContains(...)` like the
would with a mutable `var` instance.

Aligns with the existing `getPtr(...)`/`getPtrConst(...)`
methods.
2023-12-11 22:04:43 +00:00
Travis Staloch
5bbacb0c8c fmt.parseWithSign(): prevent edge case overflows
previously when T was smaller than 8 bits, it was possible for base
to overflow T (because base is a u8).  this patch prevents this by
accumulating into a U rather than T which is at least 8 bits wide.

this is the best way i could think of to maintain performance.  this
will only affect parsing of integers less than 8 bits by adding one
additional cast at return.  additionally, this patch may be slightly
slower to return an error for integers less than 8 bits which overflow
because it will accumulate a few more digits before the overflow check
at return.

* add tests which previously overflowed when they shouldn't have

closes #18157
2023-12-11 17:49:22 +02:00
xdBronch
a817e27c7d use linux.perf_event_open directly 2023-12-11 17:48:18 +02:00
Jakub Konka
5c0d58b71f
Merge pull request #18243 from ziglang/check-macho-more
lib/std/Build/CheckObject: dump more Mach-O info
2023-12-10 09:48:50 +01:00
Jakub Konka
a2d8e03931 lib/std/Build/CheckObject: dump Mach-O dyld_info_only bind, weak-bind and lazy-bind data 2023-12-10 00:50:52 +01:00
Jakub Konka
5bda88f9a3 lib/std/Build/CheckObject: dump Mach-O dyld_info_only rebase data 2023-12-10 00:14:53 +01:00
Jakub Konka
40952b4cdb lib/std/Build/CheckObject: dump Mach-O dyld_info_only exports data 2023-12-09 10:57:12 +01:00
Jakub Konka
eb70c8801e lib/std/Build/CheckObject: dump Mach-O symbol attributes 2023-12-09 09:38:23 +01:00
Veikka Tuominen
69195d0cd4 AstGen: add error for using inline loops in comptime only scopes 2023-12-08 16:54:32 -08:00
Jakub Konka
36981d46a3 lib/std/Build/CheckObject: dump Mach-O header 2023-12-08 20:31:45 +01:00
Carter Snook
d270020114
std.os.dl_iterate_phdr: remove u16 error cast 2023-12-08 16:10:33 +02:00
yunsh1
7e4177a4b1 fmt: Skip extra newline if doc_comment exists 2023-12-08 16:05:46 +02:00
Meghan Denny
6a12fd62c1 std: make std.unicode.initComptime() a comptime-known function
resolved a TODO :)
2023-12-08 15:59:17 +02:00
xdBronch
7a46c20a79 switch to mem.span
Co-authored-by: erikarvstedt <36110478+erikarvstedt@users.noreply.github.com>
2023-12-08 15:58:08 +02:00
xdBronch
e9bd10cfda add getName helper to inotify_event 2023-12-08 15:58:08 +02:00
Jakub Konka
56deb5b054 macho: rename flag to EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 2023-12-06 23:29:08 +01:00
Jakub Konka
79316ee10b lib/std/macho: add missing LC defs and missing N_NO_DEAD_STRIP desc for nlists 2023-12-06 22:25:44 +01:00
Frank Denis
f276bb107e verify_buffer is not expected to be sentinel-terminated 2023-12-01 20:04:52 +01:00
Frank Denis
9831dc9e0c TLS: The 0x1306 TLS identifier was updated to TLS_AEGIS_256_SHA512
Following the recommendations from [1], the AEGIS specification
and the TLS registry [2] were updated to recommend SHA512 for the
traffic secrets.

[1] https://eprint.iacr.org/2023/913.pdf
[2] https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-4
2023-12-01 18:00:15 +01:00
Jacob Young
bf5ab54510 test: test with -fstrip and fix failures
Closes #17513
2023-12-01 04:34:50 +00:00
David Rubin
1e42a3de89
Remove all usages of std.mem.copy and remove std.mem.set (#18143) 2023-11-29 16:03:02 -05:00
tjog
22d7c7d295
std.debug: optimized printLineFromFileAnyOs (#18142)
* std.debug: optimized printLineFromFileAnyOs

Uses mem.indexOfScalar to speed line iteration instead of byte for byte.
Also prints the whole line in a single write (or up to a page size at a
time)

Closes #18099

* add test cases for printLineFromFileAnyOs
2023-11-29 14:58:56 -05:00
Carter Snook
a98d4a66e9 std.net: replace @ptrCast with slice syntax 2023-11-27 23:14:07 -05:00
Carter Snook
a0fbc6815c std.zig.system: remove explicit usize cast
The cast seems to no longer be necessary after changes in interactions
between `u64` and `usize`.
2023-11-27 23:13:30 -05:00
Andrew Kelley
0c0b69891a zig fetch: add --save flag
```
--save        Add the fetched package to build.zig.zon
--save=[name] Add the fetched package to build.zig.zon as name
```
2023-11-26 19:41:00 -07:00
Andrew Kelley
70d51be3a2 std.zig.render: add ability to append strings after nodes 2023-11-26 19:41:00 -07:00
Lauri Tirkkonen
19af8aac82 os: expect ETIMEDOUT, ECONNRESET, ENOTCONN from recvfrom & read family
reads on eg. connected TCP sockets can fail with ETIMEDOUT, and ENOTCONN
happens eg. if you try to read a TCP socket that has not been connected
yet.

interestingly read() was already handling CONNRESET & TIMEDOUT, but
readv(), pread(), and preadv() were somewhat inconsistent.
2023-11-26 21:35:36 -05:00
Daniel A.C. Martin
280140595f fix: Prevent segfault when using add.Module()
This duplicates the source file string (as is done in other places such
as `addAssemblyFile()`) in order to prevent a segfault when the supplied
string is freed by the caller. This is still seen when the caller makes
use of a defer statement.
2023-11-26 21:33:28 -05:00
Michael Dusan
50bbb9d960 bsd: debitrot atomic and debug
closes #18119
2023-11-26 14:28:22 -05:00
David Rubin
069a079ddc complete todo 2023-11-26 14:27:39 -05:00
Andrew Kelley
7103088e4a
Merge pull request #18105 from Vexu/translate-c
Use Aro's tokenizer in `translate-c`
2023-11-26 02:22:51 -05:00
Bogdan Romanyuk
2ff707be78
AstGen: check allowed non-function builtins with declarative field (#18120) 2023-11-26 02:21:58 -05:00
Veikka Tuominen
74010fecc7 translate-c: use Aro's tokenizer 2023-11-25 12:28:19 +02:00
Andrew Kelley
648f592db1
Merge pull request #18109 from nektro/std-compiler
compiler: move BuiltinFn and AstRlAnnotate to std.zig namespace
2023-11-25 04:11:46 -05:00
Andrew Kelley
e834e95d71 Revert "std.SinglyLinkedList: add sort function"
This reverts commit 8b10970836.

This implementation has the following problems:

* It does not provide context to the less than function. This will be an
  API break in order to fix.
* It uses recursion, causing unbounded stack memory usage - likely
  depending on user input, which is extra problematic.
* Sorting linked lists is generally an inefficient operation;
  encouraging it by having a standard library function for it may
  lead to suboptimal software being written in Zig.

Furthermore, there is almost no benefit to providing a sort function as
a method, when a third party implementation can easily be passed a
linked list to then be sorted.
2023-11-24 22:33:50 -07:00
Meghan Denny
121d995fcb frontend: move AstRlAnnotate to std.zig namespace 2023-11-24 17:09:08 -08:00
Meghan Denny
84d58aaa1f frontend: move BuiltinFn to std.zig namespace 2023-11-24 17:04:52 -08:00
Justus Klausecker
8b10970836
std.SinglyLinkedList: add sort function 2023-11-24 23:49:12 +00:00
Luca Ivaldi
3acb0e30a0
std.fmt: fix overflow when formatting comptime_float 2023-11-24 18:31:12 +02:00
John Benediktsson
54f4abae2f
Deprecate math.doNotOptimizeAway, use mem.doNotOptimizeAway (#18011) 2023-11-23 15:06:32 -05:00
Andrew Kelley
464ce8ac67
Merge pull request #18091 from squeek502/no-shell32-no-ole32
Remove Zig's internal depedency on `shell32.dll` and `ole32.dll`
2023-11-23 14:49:56 -05:00
Ryan Liptak
0bc4ee1792 Remove std.os.windows.ole32/shell32 2023-11-23 03:06:47 -08:00
Andrew Kelley
2bffd81015
Merge pull request #18085 from ziglang/std-atomics
rework std.atomic
2023-11-23 04:55:28 -05:00
Ryan Liptak
2c326d4390 std.os.windows: Add HKEY_CLASSES_ROOT 2023-11-23 01:11:53 -08:00
Ryan Liptak
d42418d614 Replace shell32.SHGetKnownFolderPath usage with LOCALAPPDATA env var
Removes the dependency on shell32.dll. This is a stop gap solution until a proper SHGetKnownFolderPath Zig implementation is written
2023-11-23 01:11:53 -08:00
Ryan Liptak
fcc071c9bd Remove unnecessary branch on absolute path
Also remove the TODO--it was added in fd067fbe8b, but the current code no longer used that workaround, so this TODO didn't seem relevant anymore.
2023-11-23 03:45:17 -05:00
Andrew Kelley
f4e426a06c
Merge pull request #18076 from ziglang/revert-iterable-dir
std.fs: Absorb `IterableDir` into `Dir`
2023-11-23 01:44:07 -05:00
Andrew Kelley
6fc20b3b09 std.os.windows: remove volatile from inline asm
This inline assembly has no side effects.
2023-11-23 00:52:35 -05:00
Andrew Kelley
70931dbdea rework std.atomic
* move std.atomic.Atomic to std.atomic.Value
* fix incorrect argument order passed to testing.expectEqual
* make the functions be a thin wrapper over the atomic builtins and
  stick to the naming conventions.
* remove pointless functions loadUnchecked and storeUnchecked. Instead,
  name the field `raw` instead of `value` (which is redundant with the
  type name).
* simplify the tests by not passing every possible combination. Many
  cases were iterating over every possible combinations but then not
  even using the for loop element value!
* remove the redundant compile errors which are already implemented by
  the language itself.
* remove dead x86 inline assembly. this should be implemented in the
  language if at all.
2023-11-22 19:08:55 -07:00
Andrew Kelley
edb2f72988 std: remove atomic.Queue
This was originally supposed to be a lock-free queue, but I gave up on
that and made it be a thread-safe queue instead.

Putting the mutex directly inside the queue data structure makes it
non-composeable. Instead, the recommendation is to use a normal queue
protected by an external mutex.
2023-11-22 16:39:37 -07:00
Andrew Kelley
6bd97ab640 std: remove atomic.Stack
This was originally supposed to be a lock-free stack, but I gave up on
that and made it be a thread-safe stack which is implemented poorly
using spin locks. Nobody should use this data structure.

The alternative is a normal stack protected by a mutex.
2023-11-22 16:38:26 -07:00
Andrew Kelley
0a536a7c90 std.fs.File: flatten struct 2023-11-22 15:24:57 -07:00
Andrew Kelley
e00e9c0fbf std.fs: extract AtomicFile to separate file 2023-11-22 15:24:57 -07:00
Andrew Kelley
c95e2e65fa std.fs: extract Dir into separate file 2023-11-22 15:24:57 -07:00
Andrew Kelley
e357550610 update for the std.fs.Dir changes 2023-11-22 15:24:57 -07:00
Andrew Kelley
1fa2e911d9 std.atomic: remove some APIs
* remove `std.atomic.Ordering`
  - it is provided by the language with `std.builtin.AtomicOrder`.
* remove `std.atomic.fence`
  - it is provided by the language with `@fence`.
* remove `std.atomic.compilerFence`
  - if this is desired, it should be a language feature, not a standard
    library function with inline asm.
2023-11-22 14:27:49 -07:00
Andrew Kelley
519ba9bb65 Revert "Merge pull request #12060 from Vexu/IterableDir"
This reverts commit da94227f78, reversing
changes made to 8f943b3d33.

I was against this change originally, but decided to approve it to keep
an open mind. After a year of trying it in practice, I firmly believe
that the previous way of doing it was better.
2023-11-22 12:35:33 -07:00
Andrew Kelley
49d6dd3ecb std.crypto.ff: simplify implementation
* Take advantage of multi-object for loops.
* Remove use of BoundedArray since it had no meaningful impact on safety
  or readability.
* Simplify some complex expressions, such as using `!` to invert a
  boolean value.
2023-11-22 11:32:14 -07:00
Andrew Kelley
7b3556a8cf std.fs: make deleteTree use ArrayList instead of BoundedArray
We definitely want ArrayList in the standard library. Do we want
BoundedArray? Maybe, maybe not. But that makes ArrayList a more stable
dependency for std.fs.
2023-11-22 11:32:14 -07:00
Andrew Kelley
f6549a956d std.ArrayList: add initBuffer to the unmanaged array list
This is useful when you want to have an array list backed by a fixed
slice of memory and no Allocator will be used.

It's an alternative to BoundedArray as you will see in the following
commit.
2023-11-22 11:32:14 -07:00
Andrew Kelley
d5e21a4f1a std: remove meta.trait
In general, I don't like the idea of std.meta.trait, and so I am
providing some guidance by deleting the entire namespace from the
standard library and compiler codebase.

My main criticism is that it's overcomplicated machinery that bloats
compile times and is ultimately unnecessary given the existence of Zig's
strong type system and reference traces.

Users who want this can create a third party package that provides this
functionality.

closes #18051
2023-11-22 13:24:27 -05:00
Hong Shick Pak
994e191643
std.Uri: fix parsing edge case panic 2023-11-22 07:40:30 +00:00
Mikko Kaihlavirta
ea4a07701e add missing timeval struct 2023-11-22 01:15:11 +02:00
Andrew Kelley
be6f76655f
Merge pull request #18055 from ziglang/zig-init 2023-11-21 11:59:24 -05:00
Jan Philipp Hafer
27b34a5b77 std.net: enable forcing non-blocking mode for accept
Justification: It is common for non-CPU bound short routines to do
non-blocking accept to eliminate unnecessary delays before subscribing
to data, for example in hardware integration tests.
2023-11-21 18:04:33 +02:00
Michael Pfaff
478c89b46f
std.heap: Use @alignOf(T) rather than 0 if not manually overridden for alignment of MemoryPool items 2023-11-21 13:23:53 +00:00
salo-dea
a58ecf7b09 Do not assume that FILE_BOTH_DIR_INFORMATION is correctly aligned 2023-11-21 15:21:41 +02:00