366 Commits

Author SHA1 Message Date
Ali Chraghi
0e6285c8fc math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
Motiejus Jakštys
1d532f12b5 [Elf] add -z nocopyreloc
Warnings about non-implemented `-z nocopyreloc` are common when
compiling go code (including Go's tests themselves). Let's just
make it stop complaining.
2022-05-19 20:21:07 -04:00
Jakub Konka
5f97652da8 x64: remove verbose_mir functionality
Originally I thought interleaving AIR with MIR will be useful, however
as it stands, I have used it very sporadically, and recently, not at
all, and I do not think anyone else is actually using it. If there is
a simple error such as a wrong instruction emitted,
`objdump` is perfectly capable of narrowing it down, while if there's
something more subtle happening, regardless of having `--verbose-mir`
functionality or not, you still gotta go via the debugger which
offers a better view at interleaved source program with the emitted
machine code. Finally, I believe `-femit-asm` when we add it will offer a
more generic substitute.
2022-05-15 18:21:50 +02:00
Kirk Scheibelhut
24633b5613 zig fmt: make --exclude ignore missing dirs 2022-05-13 16:45:00 -04:00
Andrew Kelley
ec95e00e28 flatten lib/std/special and improve "pkg inside another" logic
stage2: change logic for detecting whether the main package is inside
the std package. Previously it relied on realpath() which is not portable.
This uses resolve() which is how imports already work.

 * stage2: fix cleanup bug when creating Module
 * flatten lib/std/special/* to lib/*
   - this was motivated by making main_pkg_is_inside_std false for
     compiler_rt & friends.
 * rename "mini libc" to "universal libc"
2022-05-06 22:41:00 -07:00
Andrew Kelley
ba127058d1 CLI: detect MinGW-flavored static libraries
Ideally on Windows, static libraries look like "foo.lib". However, CMake
and other build systems will unfortunately produce static libraries that
instead look like "libfoo.a". This patch makes Zig's CLI resolve "-lfoo"
arguments into static libraries that match this other pattern.

This patch fixes an issue with zig-bootstrap where it won't find the
LLVM, Clang, and LLD libraries.
2022-05-04 19:15:31 -07:00
Andrew Kelley
1387d2f5ac zig build: use CacheMode.whole for build_runner.zig
Maybe after we have incremental compilation metadata serialization
and non-LLVM backends, it will make sense to switch this back. For now,
however, this makes successive `zig build` commands much faster.
2022-05-01 15:43:52 -07:00
Jimmi Holst Christensen
a0a2ce92ca std: Do not allocate the result for ChildProcess.init
Instead, just return ChildProcess directly. This structure does not
require a stable address, so we can put it on the stack just fine. If
someone wants it on the heap they should do.

  const proc = try allocator.create(ChildProcess);
  proc.* = ChildProcess.init(args, allocator);
2022-04-29 22:50:34 -04:00
Andrew Kelley
f7596ae942 stage2: use indexes for Decl objects
Rather than allocating Decl objects with an Allocator, we instead allocate
them with a SegmentedList. This provides four advantages:
 * Stable memory so that one thread can access a Decl object while another
   thread allocates additional Decl objects from this list.
 * It allows us to use u32 indexes to reference Decl objects rather than
   pointers, saving memory in Type, Value, and dependency sets.
 * Using integers to reference Decl objects rather than pointers makes
   serialization trivial.
 * It provides a unique integer to be used for anonymous symbol names,
   avoiding multi-threaded contention on an atomic counter.
2022-04-20 17:37:35 -07:00
Andrew Kelley
0c5ad335d2 build system: add -fstage1/-fno-stage1 to zig build
So that people can start experimenting with compiling their projects
with the self-hosted compiler.

I expect this commit to be reverted after #89 is closed.
2022-04-19 14:40:27 -07:00
Cody Tapscott
bb9cd6db1c stage2: Move WASI/Zig-specific selfExePath to introspect.zig 2022-04-18 23:06:49 -07:00
Andrew Kelley
b75d86027d stage2: avoid binary bloat from GeneralPurposeAllocator
In the case of not using it.
2022-04-18 16:41:54 -07:00
Jakub Konka
b03345f32a
Merge pull request #11024 from topolarity/wasi-stage2
stage2: Add limited WASI support for selfExePath and globalCacheDir
2022-04-18 23:53:41 +02:00
Cody Tapscott
692ccd01b4 stage2: Initialize WASI preopens on startup 2022-04-18 10:20:20 -07:00
Wojtek Mach
b2344cc18e Support --subsystem=x instead of --subsystem,x 2022-04-18 11:43:17 +02:00
Wojtek Mach
5eee8f70d1 zig cc: support --subsystem linker flag
Example:

    $ zig cc -o main.exe main.cpp -target x86_64-windows -Wl,--subsystem,windows
2022-04-06 22:48:07 +02:00
Cody Tapscott
1de63ad793 zig fmt: Add --exclude argument to skip dir/file
This change adds a "--exclude" parameter to zig format, which can be
used to make sure that it does not process certain files or folders
when recursively walking a directory.

To do this, we simply piggy-back on the existing "seen" logic in zig
fmt and mark these files/folders as seen before processing begins.
2022-03-25 12:27:46 -07:00
Jakub Konka
b74f292410 Revert "ignore target lib dirs when invoked with -feach-lib-rpath"
This reverts commit 3701697a0a586e630a2452dea29951f0051a47fd.

The commit introduced a regression when building stage2 on nixOS where
the linker would fail to find relevant LLVM dynamic libraries as some
search dirs were missing.
2022-03-22 20:51:34 +01:00
Jan200101
3701697a0a ignore target lib dirs when invoked with -feach-lib-rpath 2022-03-22 09:03:22 +01:00
Jakub Konka
0376fd09bc macho: extend CodeSignature to accept entitlements
With this change, we can now bake in entitlements into the binary.
Additionally, I see this as the first step towards full code signature
support which includes baking in Apple issued certificates for
redistribution, etc.
2022-03-22 07:06:39 +01:00
Steven Fackler
9dc9219b2f Don't strip by default in cc or c++ 2022-03-17 18:16:24 -07:00
Stephen Gutekanst
c3a2b51a2c fix regression in zig run runtime arguments
This brings back #10950, which was reverted in 5ab5e2e6731a9f1198df6c53134545ccc6a6bbd3
because it [introduced a regression in `zig run`](https://github.com/ziglang/zig/pull/10950#issuecomment-1049481212)
where the runtime arguments passed were incorrect.

I've fixed the issue, and notably this was the only location where we
directly relied on accessing arguments by index in this code still (all
other locations use the iterator proper) and so we should be all good to
go now.

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-05 16:27:29 -07:00
Stephen Gutekanst
cfb4f48941 Revert "Revert "Merge pull request #10950 from hexops/sg/responsefiles""
This reverts commit 5ab5e2e6731a9f1198df6c53134545ccc6a6bbd3.
2022-03-05 16:04:21 -07:00
Andrew Kelley
d3648cc030 zig cc: integrate with -fstack-check, -fno-stack-check 2022-03-04 18:10:37 -07:00
Andrew Kelley
e1375942e5 zig cc: special handling of /dev/null
Now we handle -o /dev/null equivalent to -fno-emit-bin because
otherwise our atomic rename into place will fail. This also
makes Zig do less work, avoiding pointless file system operations.
2022-02-28 12:36:45 -07:00
Andrew Kelley
5ab5e2e673 Revert "Merge pull request #10950 from hexops/sg/responsefiles"
This reverts commit 136a43934bc08dc3aee85f1182904b97456601d3, reversing
changes made to 9dd839b7ed15d1191f3303d069cffe0473e03e83.

This broke the behavior of `zig run`.
2022-02-24 12:11:11 -07:00
Jakub Konka
136a43934b
Merge pull request #10950 from hexops/sg/responsefiles
Do not fail to build if 'zig build-lib' etc. arguments exceed OS limits
2022-02-23 22:54:25 +01:00
Andrew Kelley
88d1258e08 stage2: make -lgcc_s additionally link libunwind
Previously, Zig ignored -lgcc_s with a warning that this dependency is
redundant because it is satisfied by compiler-rt. However, sfackler
pointed out that it also provides exception handling functions. So if
Zig sees -lgcc_s on the linker line, it needs to fulfill this dependency
with libunwind.

I also made link_libc inferred to be on if libunwind is linked since
libunwind depends on libc.
2022-02-23 13:25:10 -07:00
xReveres
4a0b037464 wasm: correct shared memory error text 2022-02-23 08:57:20 +01:00
xReveres
fb7cde3071 wasm: shared memory checks 2022-02-23 08:57:20 +01:00
xReveres
b2805666a7 stage1-wasm: implement shared memory 2022-02-23 08:57:20 +01:00
Stephen Gutekanst
c577926a7d zig build: style: remove unnecessary constant bindings
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-02-22 15:49:03 -07:00
Stephen Gutekanst
b341967da0 zig build: use a custom iterator for merging args and response file
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-02-21 14:20:38 -07:00
Stephen Gutekanst
fb61db1ee4 zig build: use orelse to fetch next argument
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-02-21 12:52:10 -07:00
Stephen Gutekanst
e41d4df93c enable passing build-[lib|exe|obj] params via @args.rsp file
This change enables `zig build-lib` and friends to take a response file
of command line arguments, for example:

```sh
zig build-lib @args.rsp
```

Which effectively does the same thing as this in Bash:

```sh
zig build-lib $(cat args.rsp)
```

Being able to use a file for arguments is important as one can quickly
exceed the 32 KiB limit that Windows imposes on arguments to a process.

Helps #10693

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-02-20 13:50:09 -07:00
Stephen Gutekanst
0778f644b5 use process.argsWithAllocator iterator for command line handling
This change refactors the `zig` argument handling (for `build-lib`, etc.
commands) to use a `process.argsWithAllocator` iterator instead of
directly accessing arguments via array indices. This supports the next
commit which will enable us to use a response file argument iterator
here seamlessly.

Helps #10693

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-02-20 13:47:41 -07:00
Steven Fackler
2c8541bdde Support -Wl,--soname 2022-02-20 13:56:12 -05:00
Veikka Tuominen
53241f288e
Merge pull request #10913 from Vexu/err
further parser error improvements
2022-02-18 13:53:47 +02:00
Andrew Kelley
dd12a7b1e5 ci: linux: re-use cmake config for finding LLVM 2022-02-17 23:42:48 -07:00
Andrew Kelley
6f42876e74 CLI: resolve system libs into static libraries
using the provided -L directories before checking if we need to integrate
with system library paths. This prevents false positive of invoking
system cc to find native paths when in fact all dependencies are
satisfied by -L (or --search-prefix to zig build).
2022-02-17 23:42:48 -07:00
Andrew Kelley
5aa35f62c3 Revert "reduce build error noise"
This reverts commit baead472d7641bdd96130354bafadc1fb1ed223b.

Let's go through the proposal process on this one. I want to push back
on this. My position is that, at the very least, a full trace of command
lines of sub-processes should be printed on failure, with the exception
of opt-in flags such as `--prominent-compile-errors`.
2022-02-17 14:30:12 -07:00
Veikka Tuominen
6b65590715 parser: add notes to decl_between_fields error 2022-02-17 22:16:26 +02:00
Jonathan Marler
baead472d7 reduce build error noise
Address https://github.com/ziglang/zig/issues/3477
This provides a mechanism for builds to fully report an error to the user and prevent zig from piling on extra noise.
2022-02-17 14:48:22 +02:00
Veikka Tuominen
9c36cf92f0 parser: make some errors point to end of previous token
For some errors if the found token is not on the same line as
the previous token, point to the end of the previous token.
This usually results in more helpful errors.
2022-02-17 14:23:35 +02:00
Andrew Kelley
22f464a8c3 zig cc: handle -l :FILE syntax
This "feature" of gcc/clang means to treat this as a positional
link object, but using the library search directories as a prefix.

We solve this problem in the CLI layer, using a separate map for
the data since it is an uncommon case.

Closes #10851
2022-02-15 17:36:12 -07:00
Veikka Tuominen
ddd6de86f7 parser: make missing semicolon error point to the end of the previous token 2022-02-13 13:45:35 +02:00
Andrew Kelley
2836cd5fbd CLI: ignore -lgcc_s when it is redundant with compiler-rt
For some projects, they can't help themselves, -lgcc_s ends up on the
compiler command line even though it does not belong there. In Zig we
know what -lgcc_s does. It's an alternative to compiler-rt. With this
commit we emit a warning telling that it is unnecessary to put such
thing on the command line, and happily ignore it, since we will fulfill
the dependency with compiler-rt.
2022-02-09 11:38:33 -07:00
Andrew Kelley
33fa296019 stage2: pass proper can_exit_early value to LLD
and adjust the warning message for invoking LLD twice in the same
process.
2022-02-06 22:29:40 -07:00
Cody Tapscott
c1cf158729 Replace argvCmd with std.mem.join 2022-02-06 22:21:46 -07:00
Cody Tapscott
5065830aa0 Avoid depending on child process execution when not supported by host OS
In accordance with the requesting issue (#10750):
- `zig test` skips any tests that it cannot spawn, returning success
- `zig run` and `zig build` exit with failure, reporting the command the cannot be run
- `zig clang`, `zig ar`, etc. already punt directly to the appropriate clang/lld main(), even before this change
- Native `libc` Detection is not supported

Additionally, `exec()` and related Builder functions error at run-time, reporting the command that cannot be run
2022-02-06 22:21:46 -07:00