Commit Graph

787 Commits

Author SHA1 Message Date
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
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
f545fc28b3 build: pass --abbrev to git rather than relying on global config
For computing the zig version number, pass --abbrev=9 rather than
requiring the user to set their git configuration in order to make zig
versions match the standard.
2023-12-19 00:54:48 -08: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
Veikka Tuominen
74010fecc7 translate-c: use Aro's tokenizer 2023-11-25 12:28:19 +02:00
Meghan Denny
c6e02044da cmake: fix location of AstRlAnnotate.zig 2023-11-24 18:17:28 -08:00
Andrew Kelley
2bffd81015
Merge pull request #18085 from ziglang/std-atomics
rework std.atomic
2023-11-23 04:55:28 -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
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
Veikka Tuominen
acebf05be9 aro-translate-c: update to upstream changes 2023-11-17 09:01:25 +02:00
Andrew Kelley
77bc8e7b67
Merge pull request #17771 from ehaas/mingw-aro
mingw: Use aro instead of clang for preprocessing import libs
2023-11-07 14:47:05 -05:00
Jakub Konka
25c53f08a6 elf: redo strings management in the linker
* atom names - are stored locally and pulled from defining object's
  strtab
* local symbols - same
* global symbols - in principle, we could store them locally, but
  for better debugging experience - when things go wrong - we
  store the offsets in a global strtab used by the symbol resolver
2023-11-04 09:08:16 +01:00
Evan Haas
e6b9312bd0 aro: Add stub definitions to enable bootstrapping
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2023-11-03 22:18:40 +02:00
Jakub Konka
b2e847a41a elf: rename ZigModule to ZigObject 2023-10-30 19:09:13 +01:00
Jakub Konka
52e0ca1312 elf: parse GNU ld script as system lib indirection 2023-10-18 13:54:43 +02:00
Jakub Konka
d1446565a1 elf: re-enable dynamic linking codepaths 2023-10-16 19:33:04 +02:00
Jakub Konka
9a80ac0429 elf: add garbage collection of sections 2023-10-16 19:33:04 +02:00
Andrew Kelley
88bbec8f9b rework package manager
Organize everything around a Fetch task which does a bunch of stuff in a
worker thread without touching any shared state, and then queues up
Fetch tasks for its dependencies.

This isn't the theoretical optimal package fetching performance because
CPU cores don't necessarily map 1:1 with I/O tasks, and each fetch task
contains a mixture of computations and I/O. However, it is expected for
this to significantly outperform master branch, which fetches everything
recursively with only one thread.

The logic is now a lot more linear and easy to follow. Everything that
is embarassingly parallel is done on the thread pool, and then after
everything is fetched, the worker threads are joined and the main thread
does the finishing touches of stitching together the dependencies.zig
import files. There is only one tiny little critical section and it does
not even have any error handling in it.

This also lays the groundwork for #14281 because in system mode, all
this fetching logic will be skipped, but the "finishing touches"
mentioned above still need to be done. With this branch, that logic is
separated out and no longer recursively tangled with fetching stuff.

Additionally, this branch:
 * Implements inclusion directives in `build.zig.zon` for deciding which
   files belong the package (#14311).
 * Adds basic documentation for `build.zig.zon` files.
 * Adds support for fetching dependencies with the `file://` protocol
   scheme (#17364).
 * Adds a workaround for a Linux/btrfs file system bug (#17282).

This commit is a work-in-progress. Still todo:

1. Hook up the CLI to the new system.
2. Restore the module table creation logic after all the fetching is
   done.
3. Fix compilation errors, get the tests passing, and regression test
   against real world projects.
2023-10-08 16:54:31 -07:00
Andrew Kelley
d8540dd708 std: add type-erased reader; base GenericReader on it
The idea here is to avoid code bloat by having only one actual io.Reader
implementation, which is type erased, and then implement a GenericReader
that preserves type information on top of that as thin glue code.

The strategy here is for that glue code to `@errSetCast` the result of
the type-erased reader functions, however, while trying to do that I
ran into #17343.
2023-10-03 14:55:17 -07:00
Krzysztof Wolicki
4df7f7c86a Add -fno-stack-protector to flags when building libzigcpp
This allows both debug and release builds to link to it
without forcing release builds to link to libssp
2023-10-03 11:21:21 -07:00
Andrew Kelley
7733894761
Merge pull request #17341 from rzezeski/illumos-updates
Illumos/Solaris updates
2023-10-03 11:04:41 -07:00
Andrew Kelley
a4352982b3 compiler: extract package hashing logic to separate file
There are no functional changes in this commit.
2023-10-02 17:02:24 -07:00
Stephen Gregoratto
285970982a Add illumos OS tag
- Adds `illumos` to the `Target.Os.Tag` enum. A new function,
  `isSolarish` has been added that returns true if the tag is either
  Solaris or Illumos. This matches the naming convention found in Rust's
  `libc` crate[1].
- Add the tag wherever `.solaris` is being checked against.
- Check for the C pre-processor macro `__illumos__` in CMake to set the
  proper target tuple. Illumos distros patch their compilers to have
  this in the "built-in" set (verified with `echo | cc -dM -E -`).

  Alternatively you could check the output of `uname -o`.

Right now, both Solaris and Illumos import from `c/solaris.zig`. In the
future it may be worth putting the shared ABI bits in a base file, and
mixing that in with specific `c/solaris.zig`/`c/illumos.zig` files.

[1]: 6e02a329a2/src/unix/solarish
2023-10-02 15:31:49 -06:00
Stephen Gregoratto
51fa7ef1c4 solaris: set correct target tuple in CMake 2023-10-02 15:31:32 -06:00
Veikka Tuominen
5792570197 add Aro sources as a dependency
ref: 5688dbccfb58216468267a0f46b96bed7013715a
2023-10-01 23:51:54 +03:00
Ryan Zezeski
ea92789c62 solaris: ld does not have stack-size option 2023-09-30 11:38:56 -06:00
Andrew Kelley
3882ce4f4b update cmake files to LLVM 17 2023-09-19 09:37:26 -07:00
Jakub Konka
59a586a878 cmake: add new zig source files 2023-09-13 22:40:01 +02:00
Jakub Konka
4d29b39678
Merge pull request #17113 from ziglang/elf-linker
elf: upstream zld/ELF functionality, part 1
2023-09-13 10:07:07 +02:00
Jakub Konka
8142349d69 elf: add missing input zig source files to cmake 2023-09-13 00:40:08 +02:00
Michael Dusan
3cf71580c4 build stage3: detect system libcxx
Detect system libcxx name with the CMake build system and convey that
information to build.zig via config.h so that the same system libcxx is
used for stage3.

This undoes the hacky search 901457d173 .

closes #17018
2023-09-03 08:38:03 +02:00
Jakub Konka
da9e7e498a macho: unify Atom concept between drivers 2023-08-29 11:39:34 +02:00
mlugg
321961d860 AstGen: add result location analysis pass
The main motivation for this change is eliminating the `block_ptr`
result location and corresponding `store_to_block_ptr` ZIR instruction.
This is achieved through a simple pass over the AST before AstGen which
determines, for AST nodes which have a choice on whether to provide a
result location, which choice to make, based on whether the result
pointer is consumed non-trivially.

This eliminates so much logic from AstGen that we almost break even on
line count! AstGen no longer has to worry about instruction rewriting
based on whether or not a result location was consumed: it always knows
what to do ahead of time, which simplifies a *lot* of logic. This also
incidentally fixes a few random AstGen bugs related to result location
handling, leading to the changes in `test/` and `lib/std/`.

This opens the door to future RLS improvements by making them much
easier to implement correctly, and fixes many bugs. Most ZIR is made
more compact after this commit, mainly due to not having redundant
`store_to_block_ptr` instructions lying around, but also due to a few
bugs in the old system which are implicitly fixed here.
2023-08-20 11:58:14 -07:00
Lewis Gaul
387b0ac4f1
Make NaNs quiet by default and other NaN tidy-up (#16826)
* Generalise NaN handling and make std.math.nan() give quiet NaNs

* Address uses of std.math.qnan_* and std.math.nan_* consts

* Comment out failing test due to issues with signalling NaN

* Fix issue in c_builtins.zig where we need qnan_u32
2023-08-18 02:07:49 -04:00
Jacob Young
1c5c3f499a cmake: fix auto-detection of various host targets
Closes #16800
2023-08-13 11:26:10 -07:00
Prcuvu
fc6e575684 cmake: Fix typo: elif → elseif 2023-08-04 15:24:07 -07:00
Andrew Kelley
a327d8b995 start the 0.12.0 release cycle 2023-08-03 11:22:40 -07:00
Jacob Young
a61495a988 cmake: fix early issues when bootstrapping on mingw
This gets all the way to the final link, where `libssp` symbols are
undefined, referenced by `libzstd.a`.
2023-08-02 22:13:04 -07:00
Adam Goertz
9e19969e09 Remove math.ln in favor of @log 2023-08-02 12:00:14 -07:00
zhaozg
47388feec6 build: update cmake_minimum_required to 3.5
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.
2023-07-26 22:41:43 -07:00
Eric Joldasov
38d10ee4d0
src/windows_sdk.cpp: port to Zig
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-07-23 17:10:57 +06:00
Andrew Kelley
32a175740c cmake: don't ask zig2 to do hard things
Apparently hard things:
 * run autodoc on the std lib
 * build the langref

If any zig distros want these documentation, they'll need to get them
from a stage3 `zig build` instead of stage2 (LLVM backend instead of C
backend).
2023-07-22 11:04:38 -07:00
Josh Wolfe
8924f81d8c
std.json: Unify stringify and writeStream (#16405) 2023-07-21 19:56:46 -04:00