609 Commits

Author SHA1 Message Date
Jakub Konka
b73ef34289 frontend: directly pass resolved frameworks container to the linker
We can infer the framework name from the included resolved framework
path.

Fix hash implementation, and bump linker hash value from 9 to 10.
2023-08-21 08:07:44 +02:00
Jakub Konka
4793dafa04 frontend: move framework path resolution from the linker to frontend 2023-08-20 10:43:20 +02:00
Jakub Konka
e687c87d69 macho: we no longer need to resolve framework dirs against sysroot 2023-08-20 08:37:44 +02:00
Jakub Konka
510802d25e comp: forward -iframework/-iframeworkwithsysroot paths to the backend 2023-08-18 08:00:40 +02:00
Jakub Konka
6a9fd55809 cc: disambiguate includes with sysroot in ClangSearchSanitizer
This noninvasive change improves warning messages for mixing up
paths between `-iwithsysroot` and `-iframeworkwithsysroot`.
2023-08-18 08:00:40 +02:00
Zachary Raineri
0461a64a93
change uses of std.builtin.Mode to OptimizeMode (#16745)
std.builtin.Mode is deprecated.
2023-08-09 14:39:34 -04:00
Jeremy Volkman
516eb33442 Fix typo: headerpat -> headerpad 2023-08-04 09:20:45 +02:00
Andrew Kelley
72fb58f107 CLI: fix a typo that made static/dynamic do the opposite 2023-08-03 09:52:15 -07:00
Andrew Kelley
4089f96def darwin: pass -iframework to clang for system frameworks 2023-08-03 09:52:15 -07:00
Andrew Kelley
7360927afe CLI: add native paths only if ABI is also native 2023-08-03 09:52:15 -07:00
Andrew Kelley
e582a3642b std.zig.system.darwin: fix redundant names 2023-08-03 09:52:15 -07:00
Andrew Kelley
da91ef5c28 zig libc: restore functionality on macOS
Regressed in 2006add8496c47804ee3b6c562f420871cb4ea0a.

References to native_darwin_sdk are no longer kept in the frontend.
Instead the darwin SDK is detected as part of NativePaths and as part of
LibCInstallation.
2023-08-03 09:52:15 -07:00
Andrew Kelley
c94bbebb91 std.zig.system.NativePaths: simplify and integrate with Darwin SDK 2023-08-03 09:52:15 -07:00
Andrew Kelley
ea0e6e737b CLI: reduce code size bloat
Make a bunch of ArrayList objects use arena instead of gpa, eliminating
the `defer` expressions, which reduces code size of zig1.wasm by 1%
2023-08-03 09:52:15 -07:00
Andrew Kelley
469af67804 CLI: delete redundant logic and use null instead of undef
The `null` value here was missed in
0a4d4eb252a73555a568a532902951a13284d2ef. I hope it is the cause of the
CI failures on Windows.

The fact that libc++ depends on libc is not important for the CLI and
Compilation.create already handles that logic.
2023-08-03 09:52:15 -07:00
Andrew Kelley
a0e94ec576 CLI: add -search_paths_first_static to complete the API
There was no previous way to set preferred mode static, search strategy
paths_first.
2023-08-03 09:52:15 -07:00
Andrew Kelley
e565ff305a CLI: revert -l behavior
chicken out and make -l match the status quo behavior, where it looks
for dynamic libraries and then falls back to static libraries.

library resolution is still done in the CLI now though, and these
options are added:

-search_static_first           Search for static libs in all library search
                               paths, then dynamic libs.
-search_dylibs_only            Only search for dynamic libs.
-search_static_only            Only search for static libs.

this matches the already existing options below:

-search_paths_first            For each library search path, check for dynamic
                               lib then static lib before proceeding to next path.
-search_dylibs_first           Search for dynamic libs in all library search

So, it is still possible to get the strict behavior by passing
`-search_dylibs_only` or `-search_static_only`.

This commit also makes -dynamic and -static affect the preferred link
mode and search strategy.
2023-08-03 09:52:14 -07:00
Andrew Kelley
e477352af3 CLI: Windows: system DLLs no longer trigger native paths detection 2023-08-03 09:52:14 -07:00
Andrew Kelley
c65a061881 CLI: adjust order of operations of system libraries
First, system_libs are collected into a list. This is the same as
before.

Next, system_libs are filtered into external_system_libs, which is the
same list but without any libc, compiler_rt, etc.

At this point, if there are any external system libs, native library
directory paths are detected and added to lib_dirs.

Finally, extern_system_libs are filtered into resolved_system_libs,
which has full paths to all of the libraries. This is the list passed
into Compilation.

This makes the required changes noted by @ifreund in the code review for
this branch.
2023-08-03 09:52:14 -07:00
Andrew Kelley
8e687cb0d9 CLI: remove --ambiguous-static-library
Reverts 6232e63ca4460a953ca8453a6f7583eb910e87c8, but keeps the usage
text cleanup.

Let's resist adding this as long as possible.
2023-08-03 09:52:14 -07:00
Andrew Kelley
89c605d140 CLI: add --ambiguous-static-library
I hate this, gonna revert it in the next commit
2023-08-03 09:52:14 -07:00
Andrew Kelley
a1e21ceec8 frontend: fix linking to Windows DLLs as system libs 2023-08-03 09:52:14 -07:00
Andrew Kelley
a08cc7d2ae compiler: resolve library paths in the frontend
search_strategy is no longer passed to Compilation at all; instead it is
used in the CLI code only.

When using Zig CLI mode, `-l` no longer has the ability to link
statically; use positional arguments for this.

The CLI has a small abstraction around library resolution handling which
is used to remove some code duplication regarding static libraries, as
well as handle the difference between zig cc CLI mode and zig CLI mode.

Thanks to this, system libraries are now included in the cache hash, and
thus changes to them will correctly cause cache misses.

In the future, lib_dirs should no longer be passed to Compilation at
all, because it is a frontend-only concept.

Previously, -search_paths_first and -search_dylibs_first were
Darwin-only arguments; they now work the same for all targets. Same
thing with --sysroot.

Improved the error reporting for failure to find a system library. An
example error now looks like this:

```
$ zig build-exe test.zig -lfoo -L. -L/a -target x86_64-macos --sysroot /home/andy/local
error: unable to find Dynamic system library 'foo' using strategy 'no_fallback'. search paths:
  ./libfoo.tbd
  ./libfoo.dylib
  ./libfoo.so
  /home/andy/local/a/libfoo.tbd
  /home/andy/local/a/libfoo.dylib
  /home/andy/local/a/libfoo.so
  /a/libfoo.tbd
  /a/libfoo.dylib
  /a/libfoo.so
```

closes #14963
2023-08-03 09:52:14 -07:00
Andrew Kelley
4d7dd1689f CLI: stop special-casing LLVM, LLD, and Clang
Before:

-fLLVM, -fLLD, -fClang, -flibLLVM
-fno-LLVM, -fno-LLD, -fno-Clang, -fno-libLLVM

After:

-fllvm, -flld, -fclang, -flibllvm
-fno-llvm, -fno-lld, -fno-clang, -fno-libllvm
2023-08-01 20:32:54 -07:00
mlugg
417b92f085 package manager: don't show progress indicator on dumb terminals
This mirrors the behavior of the progress indicator for the actual
compilation. Not doing this was causing sporadic CI failures due to the
(non-existent) fetches taking long enough to appear in stderr.
2023-07-28 21:45:00 -07:00
kcbanner
a8a2f2b58b Add --verbose-generic-instances to provide visibility on the number of generic function instantiations 2023-07-26 02:20:29 -07:00
mlugg
7a57f82976
Package: add progress indicator for package fetching 2023-07-25 19:17:53 +01:00
Ian Johnson
9892ec31a0 zig fmt: make --exclude work on files
Closes #16178
2023-07-24 19:41:59 -07:00
Andrew Kelley
575a7cccc0 CLI: delete dead option -femit-analysis
This used to do something with the old autodocs system. Now it does
nothing.
2023-07-24 02:37:25 -07:00
Andrew Kelley
6e4fff6ba6 move installation logic to the build script where it belongs
* build.zig: introduce `-Dflat` option which makes the installation
  match what we want to ship for our download tarballs. This allows
  deleting a bunch of shell script logic from the CI.
  - for example it puts the executable directly in prefix/zig rather
    than prefix/bin/zig and it additionally includes prefix/LICENSE.
* build.zig: by default also install std lib documentation to doc/std/
  - this can be disabled by `-Dno-autodocs` similar to how there is
    already `-Dno-langref`.
* build.zig: add `std-docs` and `langref` steps which build and install
  the std lib autodocs and langref to prefix/doc/std and
  prefix/doc/langref.html, respectively.

* std.Build: implement proper handling of `-femit-docs` using the
  LazyPath system. This is a breaking change.
  - this is a partial implementation of #16351
* frontend: fixed the handling of Autodocs with regards to caching and
  putting the artifacts in the proper location to integrate with the
  build system.
  - closes #15864

* CI: delete the logic for autodocs since it is now handled by build.zig
  and is enabled by default.
  - in the future we should strive to have nearly all the CI shell
    script logic deleted in favor of `zig build` commands.
* CI: pass `-DZIG_NO_LIB=ON`/`-Dno-lib` except for the one command where
  we want to actually generate the langref and autodocs. Generating the
  langref takes 14 minutes right now (why?!) so we don't want to do that
  more times than necessary.

* Autodoc: fixed use of a global variable. It works fine as a local
  variable instead.
  - note that in the future we will want to make Autodoc run
    simultaneously using the job system, but for now the principle of
    YAGNI dictates that we don't have an init()/deinit() API and instead
    simply call the function that does the things.
* Autodoc: only do it when there are no compile errors
2023-07-22 00:16:27 -07:00
Jacob Young
9c4d5e64b4 llvm: minor fixes 2023-07-19 23:38:40 -04:00
Jacob Young
d195173ba2 llvm: start tracking more things without relying on the llvm api 2023-07-19 23:38:40 -04:00
Motiejus Jakštys
910ad92e0e ld: support -version-script
gettext uses this version and, surely enough, it is supported by lld
2023-06-28 09:32:10 +02:00
Luuk de Gram
87b8a0567b
default to single-threaded for WebAssembly
When targeting WebAssembly, we default to building a single-threaded build
as threads are still experimental. The user however can enable a multi-
threaded build by specifying '-fno-single-threaded'. It's a compile-error
to enable this flag, but not also enable shared-memory.
2023-06-26 20:00:58 +02:00
Luuk de Gram
3819371163
wasm-ld: implement --export-memory flag
This flag allows the user to force export the memory to the host
environment. This is useful when the memory is imported from the
host but must also be exported. This is (currently) required
to pass the memory validation for runtimes when using threads.
In this future this may become an error instead.
2023-06-26 20:00:57 +02:00
Ryan Liptak
b111702940 Recognize the .res extension and link it as if it were an object file
.res files are compiled Windows resource files that get linked into executables/libraries. The linker knows what to do with them, but previously you had to trick Zig into thinking it was an object file (by renaming it to have the .obj extension, for example).

After this commit, the following works:

    zig build-exe main.zig resource.res

or, in build.zig:

    exe.addObjectFile("resource.res");

Closes #6488
2023-06-25 01:42:12 -07:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
Matteo Briani
8ced903d61
Add support for the "--version" linker argument (#16154)
closes #15549

Co-authored-by: Matteo Briani <matteo.briani@icvox.com>
2023-06-24 16:24:50 -04:00
Eric Joldasov
50339f595a all: zig fmt and rename "@XToY" to "@YFromX"
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:42 -07:00
r00ster91
6e84f46990 std: replace builtin.Version with SemanticVersion 2023-06-17 13:17:34 -07:00
Veikka Tuominen
0f5aff3441 zig build: add option to only print failed steps
The motivating case for this is that currently when a test fails
the CI log will include ~5k lines of listing steps that succeeded.
2023-06-16 15:17:59 -07:00
r00ster91
2593156068 migration: std.math.{min, min3, max, max3} -> @min & @max 2023-06-16 13:44:09 -07:00
Andrew Kelley
a596ea683c CLI: introduce --verbose-intern-pool
and stop dumping to stderr without the user's consent.
2023-06-10 20:47:56 -07:00
Andrew Kelley
629f0d23b5
Merge pull request #15579 from squeek502/mem-delimiters
Split `std.mem.split` and `tokenize` into `sequence`, `any`, and `scalar` versions
2023-06-03 13:51:02 -07:00
Evin Yulo
6c2f374556 Use the word 'base' consistently instead of 'radix' 2023-06-01 00:02:16 +03:00
Motiejus Jakštys
ac9f72d87e zig ld: handle --library :path/to/lib.so
`-l :path/to/lib.so` behavior on gcc/clang is:

- the path is recorded as-is: no paths, exact filename (`libX.so.Y`).
- no rpaths.

The previous version removed the `:` and pretended it's a positional
argument to the linker. That works in almost all cases, except in how
rules_go[1] does things (the Bazel wrapper for Go).

Test case in #15743, output:

    gcc rpath:
     0x0000000000000001 (NEEDED)     Shared library: [libversioned.so.2]
     0x000000000000001d (RUNPATH)    Library runpath: [$ORIGIN/x]
    gcc plain:
     0x0000000000000001 (NEEDED)     Shared library: [libversioned.so.2]
    zig cc rpath:
     0x0000000000000001 (NEEDED)     Shared library: [libversioned.so.2]
     0x000000000000001d (RUNPATH)    Library runpath: [$ORIGIN/x]
    zig cc plain:
     0x0000000000000001 (NEEDED)     Shared library: [libversioned.so.2]

Fixes #15743

[1]: https://github.com/bazelbuild/rules_go
2023-05-30 08:18:10 +02:00
Linus Groh
4159add4ab std.fs.file: Rename File.Kind enum values to snake case 2023-05-25 20:17:07 +01:00
Linus Groh
0f6fa3f20b std: Move std.debug.{TTY.Config,detectTTYConfig} to std.io.tty
Also get rid of the TTY wrapper struct, which was exlusively used as a
namespace - this is done by the tty.zig root struct now.

detectTTYConfig has been renamed to just detectConfig, which is enough
given the new namespace. Additionally, a doc comment had been added.
2023-05-24 10:15:02 +01:00
Andrew Kelley
f52189834c rename omit_pkg_fetching_code to only_core_functionality
No functional changes. This renames an internal build option to better
reflect how it is used.
2023-05-17 16:00:24 -07:00
Andrew Kelley
fea6157102 zig2.c: omit non-essential subcommands
When producing zig2.c, don't waste time emitting C code for subcommands
that won't be used, such as objcopy.

This takes zig2.c down from 111M to 109M, and sidesteps some unfortunate
warnings that are currently emitted by GCC.
2023-05-17 15:43:15 -07:00