726 Commits

Author SHA1 Message Date
Jan200101
8707555c0b compiler: move each_lib_rpath to frontend
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2024-01-14 16:16:00 -07: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
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
e22102dfc6 Compilation: make create() take an arena allocator
Instead of making its own inside create. 10 out of 10 calls to create()
had already an arena in scope, so this commit means that 10 instances of
Compilation now reuse an existing arena with the same lifetime rather
than creating a redundant one.

In other words, this very slightly optimizes initialization of the
frontend in terms of memory allocation.
2024-01-01 19:49:08 -07:00
Andrew Kelley
92cc2f41e6 CLI: fix compilation on Windows 2024-01-01 19:49:08 -07:00
Andrew Kelley
791e83c223 frontend: make dll_export_fns=false on non-windows
Fixes a regression introduced in this branch.
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
57562c8d50 compiler: push entry symbol name resolution into the linker
This is necessary because on COFF, the entry symbol name is not known
until the linker has looked at the set of global symbol names to
determine which of the four possible main entry points is present.
2024-01-01 17:51:21 -07:00
Andrew Kelley
c9fe43679f frontend: remove deprecated field from Compilation 2024-01-01 17:51:21 -07:00
Andrew Kelley
4c07d41b52 CLI: fix logic for zig test error message
When using the build system to do unit testing, it lowers to --mod
arguments which were incorrectly tripping a "zig test requires a source
file argument" error.
2024-01-01 17:51:21 -07:00
Andrew Kelley
41ab64c3eb Compilation.Config.resolve: explicit error set
Some logic has comptime-known conditions, causing the inferred error set
to be different on different compiler build configurations.
2024-01-01 17:51:21 -07:00
Andrew Kelley
24eec48f60 CLI: update main usage text
* Organize and reword some stuff
* Add missing usage for `zig reduce`
2024-01-01 17:51:21 -07:00
Andrew Kelley
9141e1a29c CLI: fix logic for sending output file path
via the compiler protocol
2024-01-01 17:51:21 -07:00
Andrew Kelley
e12e296306 CLI: fix not respecting module remappings 2024-01-01 17:51:21 -07:00
Andrew Kelley
3262e9ccee zig build: fix logic for extracting executable file from Compilation 2024-01-01 17:51:21 -07:00
Andrew Kelley
3b36c4d0b3 zig build: pass resolved_target to Module.create
it's now required to pass this for the root module
2024-01-01 17:51:21 -07:00
Andrew Kelley
056f04c1ff CLI: rename clang_argv to cc_argv
The args apply to Aro as well.
2024-01-01 17:51:21 -07:00
Andrew Kelley
fad35835aa CLI: better error messages for bad args 2024-01-01 17:51:20 -07:00
Andrew Kelley
8944dea23f CLI: fix regressed logic for any_dyn_libs
This value needs access to the fully resolved set of system libraries,
which required restructuring a bunch of CLI logic.
2024-01-01 17:51:20 -07:00
Andrew Kelley
db2ca2ca00 CLI: mark any_dyn_libs=true when encountering a shared object 2024-01-01 17:51:20 -07:00
Andrew Kelley
4b667e7362 fix compilations without zig compilation units 2024-01-01 17:51:20 -07:00
Andrew Kelley
fe87bae7e3 frontend: fix handling of special builtin module
it's allocated differently and imported differently
2024-01-01 17:51:20 -07:00
Andrew Kelley
90cc408c14 fix --show-builtin when no positional argument is provided 2024-01-01 17:51:20 -07:00
Andrew Kelley
f256431838 fix compilation errors when enabling llvm 2024-01-01 17:51:20 -07:00
Andrew Kelley
2047a6b82d fix remaining compile errors except one 2024-01-01 17:51:20 -07:00
Andrew Kelley
48d5861f92 fix more compilation errors introduced by this branch 2024-01-01 17:51:20 -07:00
Andrew Kelley
638db680f4 move dll_export_fns and rdynamic to Compilation.Config 2024-01-01 17:51:20 -07:00
Andrew Kelley
2596f5d925 update bin_file.options references in Sema
mainly pertaining to error return tracing
2024-01-01 17:51:19 -07:00
Andrew Kelley
f54471b54c compiler: miscellaneous branch progress
implement builtin.zig file population for all modules rather than
assuming there is only one global builtin.zig module.

move some fields from link.File to Compilation
move some fields from Module to Compilation

compute debug_format in global Compilation config resolution

wire up C compilation to the concept of owner modules

make whole cache mode call link.File.createEmpty() instead of
link.File.open()
2024-01-01 17:51:19 -07:00
Andrew Kelley
33cdf33b95 compiler: update many references to bin_file.options 2024-01-01 17:51:19 -07:00
Andrew Kelley
1642c003b4 update libunwind references to bin_file.options 2024-01-01 17:51:19 -07:00
Andrew Kelley
3b6cb257df update image_base references 2024-01-01 17:51:19 -07:00
Andrew Kelley
43720be04a frontend: fix stack protector option logic
Commit 97e23896a9168132b6d36ca22ae1af10dd53d80d regressed this behavior
because it made target_util.supportsStackProtector *correctly*
notice which zig backend is being used to generate code, while the
logic calling that function *incorrectly assumed* that .zig code is being
compiled, when in reality it might be only C code being compiled.

This commit adjusts the option resolution logic for stack protector so
that it takes into account the zig backend only if there is a zig
compilation unit. A separate piece of logic checks whether clang
supports stack protector for a given target.

closes #18009
closes #18114
closes #18254
2024-01-01 17:51:19 -07:00
Andrew Kelley
2bef0715c7 move a large chunk of linker logic away from "options"
These options are only supposed to be provided to the initialization
functions, resolved, and then computed values stored in the appropriate
place (base struct or the object-format-specific structs).

Many more to go...
2024-01-01 17:51:18 -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
77420af9d0 compiler: get the dynamic linker from the target
instead of passing it to Compilation separately and storing it
separately in the linker options.
2024-01-01 17:51:18 -07:00
Andrew Kelley
ce94c28e53 resinator: update std.Target.Query usage 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
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
134e8cf76a move is_libcpp_lib_name and is_libc_lib_name to std.Target 2024-01-01 17:51:18 -07: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
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
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
Robin Voetter
b4b1c4df64
spirv: add -fstructured-cfg option
This enables the compiler to generate a structured cfg even in opencl,
even if it is not strictly required by the SPIR-V Kernel specification.
2023-11-24 11:40:18 +01:00
Andrew Kelley
519ba9bb65 Revert "Merge pull request #12060 from Vexu/IterableDir"
This reverts commit da94227f783ec3c92859c4713b80a668f1183f96, reversing
changes made to 8f943b3d33432a26b7e242c1181e4220ed400501.

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
9f363cd679 zig init: also create a build.zig.zon 2023-11-20 23:30:51 -07:00
Andrew Kelley
f645022d16 merge zig init-exe and zig init-lib into zig init
Instead of `zig init-lib` and `zig init-exe`, now there is only
`zig init`, which initializes any of the template files that do not
already exist, and makes a package that contains both an executable and
a static library. The idea is that the user can delete whatever they
don't want. In fact, I think even more things should be added to the
build.zig template.
2023-11-20 23:01:45 -07:00